Skip to content

fix: Azure GPT-5 responses replay ordering#21932

Open
avdr-cpp wants to merge 3 commits intoanomalyco:devfrom
avdr-cpp:fix/azure-gpt5-responses-replay
Open

fix: Azure GPT-5 responses replay ordering#21932
avdr-cpp wants to merge 3 commits intoanomalyco:devfrom
avdr-cpp:fix/azure-gpt5-responses-replay

Conversation

@avdr-cpp
Copy link
Copy Markdown

Issue for this PR

Closes #20698 and
Closes #21925

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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, so store: false still sent msg_*, fc_*, and rs_* 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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