Skip to content

fix(sap-ai-core): normalize finish_reason and strip assistant prefill - #45320

Closed
Saichandra2520 wants to merge 1 commit into
anomalyco:devfrom
Saichandra2520:fix/sap-ai-core-prefill-and-loop
Closed

fix(sap-ai-core): normalize finish_reason and strip assistant prefill#45320
Saichandra2520 wants to merge 1 commit into
anomalyco:devfrom
Saichandra2520:fix/sap-ai-core-prefill-and-loop

Conversation

@Saichandra2520

Copy link
Copy Markdown

Description

This PR addresses two bugs when using the SAP AI Core provider (sap-ai-core):

  1. Claude Models 400 Error (Assistant Message Prefill):
    SAP AI Core Orchestration API rejects messages ending with an assistant message (400: This model does not support assistant message prefill. The conversation must end with a user message.).

    • Fix: In ProviderTransform.message, trailing assistant messages are stripped before sending the request to sap-ai-core.
  2. GPT Models Infinite Agent Loop:
    SAP AI Core Orchestration API returns finish_reason: null instead of "stop" in the SSE stream, causing OpenCode's agent loop to not detect completion and loop indefinitely.

    • Fix: Wrapped fetch in provider.ts and SapAICorePlugin to normalize SSE stream payloads ("finish_reason": null -> "finish_reason": "stop").

Related Issues

Testing

  • Added unit tests in packages/opencode/test/provider/transform.test.ts for trailing assistant message stripping.
  • Added unit tests in packages/opencode/test/provider/sap-ai-core.test.ts and packages/core/test/plugin/provider-sap-ai-core.test.ts for SSE stream finish_reason normalization.
  • Verified all test suites pass.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

The search for "finish_reason null stop" found PR #43707 which is about chat streams, but that appears to be unrelated to the SAP AI Core provider issue.

Summary

No duplicate PRs found

The search results only return the current PR #45320 itself (which is correctly excluded from consideration) and one unrelated PR about console chat streams. There are no open PRs addressing the same SAP AI Core provider bugs regarding finish_reason normalization or assistant message prefill stripping.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 26, 2026
@github-actions github-actions Bot closed this Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants