anomalyco / anomalyco/opencode

sap-ai-core: GPT models cause infinite agent loop — model never stops responding

Open
#45,314 0 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Aug 26, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Bug Report

OpenCode Version: 1.18.23
Provider: sap-ai-core
Model: sap-ai-core/gpt-4.1, sap-ai-core/gpt-5.5 (affects all sap-ai-core/gpt-* models)

Description

When using any GPT/OpenAI model through the SAP AI Core provider, the agent never stops after giving a response. Even for a simple "Hi", the model replies repeatedly in an infinite loop.

Steps to Reproduce
  1. Configure OpenCode with sap-ai-core provider and any gpt-* model
  2. Send "Hi"
  3. Receive a response
  4. Observe the agent immediately sends the same conversation again
  5. Model responds to "Hi" again
  6. This repeats indefinitely — only Ctrl+C stops it
Root Cause

The SAP AI Core Orchestration API (used via @jerome-benoit/sap-ai-provider-v2) does not return a finish_reason: "stop" in the SSE stream in the format OpenCode/AI SDK expects.

OpenCode's agent loop checks finish_reason to decide whether to stop or continue. When finish_reason is missing, empty, or in an unexpected format, OpenCode treats it as "model wants to continue" and re-invokes the loop — sending the full conversation back to the model immediately.

Comparison: OpenCode already handles a similar case for Snowflake Cortex in packages/opencode/src/provider/provider.ts.

Expected Behavior

After the model returns a complete response, the agent loop should stop. The model should respond to "Hi" exactly once.

Suggested Fix

In packages/opencode/src/provider/provider.ts, the sap-ai-core custom loader should add a fetch wrapper that normalizes the SSE stream response — ensuring finish_reason: "stop" is present when the model has finished.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.