Skip to content

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

Closed as not planned

Description

@Saichandra2520

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.

Activity

  1. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions