fix: Azure GPT-5 responses replay ordering#21932
Open
avdr-cpp wants to merge 3 commits intoanomalyco:devfrom
Open
fix: Azure GPT-5 responses replay ordering#21932avdr-cpp wants to merge 3 commits intoanomalyco:devfrom
avdr-cpp wants to merge 3 commits intoanomalyco:devfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #20698 and
Closes #21925
Type of change
What does this PR do?
Azure GPT-5 Responses replay was failing when OpenCode resumed a session that already contained assistant reasoning and tool calls. There were two problems in the replay path.
First, the request body wrapper only stripped replay item ids for
@ai-sdk/openai. Azure uses@ai-sdk/azure, sostore: falsestill sentmsg_*,fc_*, andrs_*ids back to Azure, which caused validation failures on resumed sessions.Second, assistant replay items could be serialized in the order they were encountered, which allowed a message or function call to be emitted before its paired reasoning item. Azure expects the reasoning item first.
This change fixes both issues by applying the id stripping logic to the Azure SDK path as well, and by buffering assistant replay output so reasoning is emitted before the paired assistant message or function call. I also added focused regression tests for the reversed replay ordering cases.
How did you verify your code works?
docker exec opencode sh -lc 'opencode run --session ses_288901721ffeCYvaDhbO9eyNUt -m azure/gpt-5.4 --agent build --dangerously-skip-permissions "Give a one sentence status update."'docker exec opencode sh -lc 'opencode run --session ses_288901721ffeCYvaDhbO9eyNUt -m azure/gpt-5.4 --agent build --dangerously-skip-permissions "Use the task tool once to inspect the repo quickly, then give exactly one sentence of status."'docker run --rm -v /home/a/opencode/opencode-app/upstream:/workspace -w /workspace/packages/opencode oven/bun:1.3.11-alpine sh -lc 'set -e; bun install --frozen-lockfile >/tmp/bun-install.log 2>&1 || { cat /tmp/bun-install.log; exit 1; }; bun test test/provider/openai-responses-input.test.ts test/provider/transform.test.ts'Screenshots / recordings
Not a UI change.
Checklist