You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sap-ai-core: GPT models cause infinite agent loop — model never stops responding #45314
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-core provider and any gpt-* 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+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.
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.
Activity
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊