fix(sap-ai-core): normalize finish_reason and strip assistant prefill - #45320
fix(sap-ai-core): normalize finish_reason and strip assistant prefill#45320Saichandra2520 wants to merge 1 commit into
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
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. |
|
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. SummaryNo 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 |
|
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. |
Description
This PR addresses two bugs when using the SAP AI Core provider (
sap-ai-core):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.).ProviderTransform.message, trailing assistant messages are stripped before sending the request tosap-ai-core.GPT Models Infinite Agent Loop:
SAP AI Core Orchestration API returns
finish_reason: nullinstead of"stop"in the SSE stream, causing OpenCode's agent loop to not detect completion and loop indefinitely.fetchinprovider.tsandSapAICorePluginto normalize SSE stream payloads ("finish_reason": null->"finish_reason": "stop").Related Issues
Testing
packages/opencode/test/provider/transform.test.tsfor trailing assistant message stripping.packages/opencode/test/provider/sap-ai-core.test.tsandpackages/core/test/plugin/provider-sap-ai-core.test.tsfor SSE streamfinish_reasonnormalization.