anomalyco / anomalyco/opencode
sap-ai-core: GPT models cause infinite agent loop — model never stops responding
@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
- Configure OpenCode with
sap-ai-coreprovider and anygpt-*model - Send "Hi"
- Receive a response
- Observe the agent immediately sends the same conversation again
- Model responds to "Hi" again
- This repeats indefinitely — only
Ctrl+Cstops 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.