Skip to content

fix(core): normalize AI SDK fragment boundaries - #50685

Merged
rekram1-node merged 1 commit into
v2from
gateway-protocol-fix
Sep 23, 2026
Merged

rekram1-node merged 1 commit into
v2from
gateway-protocol-fix

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Before

AI SDK providers may overlap, repeat, or omit text and reasoning boundaries. The AI SDK adapter forwarded them unchanged, but Session accepts one open text fragment and one open reasoning fragment at a time, so these streams killed the turn with an untyped defect.

In #50662, AI SDK's OpenAI Responses parser behind Vercel AI Gateway starts summary part :1 while :0 is still open, then ends both at item completion:

reasoning-start(rs_1:0)
reasoning-start(rs_1:1)   -> "reasoning start before end"

Native @opencode/ai protocols already normalize these boundaries through their lifecycle helpers (#45789). Providers that run through the AI SDK adapter did not.

After

The adapter applies the same rule to text and reasoning: a start or delta for another fragment closes the open one, repeated starts are ignored, and ends for fragments that are not open are dropped.

reasoning-start(rs_1:0)
reasoning-end(rs_1:0)
reasoning-start(rs_1:1)

Well-formed streams are unchanged. This also covers the same class of failure in other AI SDK producers:

  • repeated reasoning starts from older xAI Responses
  • reasoning deltas after an ended id from xAI Chat (reopened, not dropped)
  • message items that stay open until flush in xAI Responses
  • the same summary-part overlap in the in-repo Copilot Responses fork

Dropping a late end for a force-closed part loses only that end's metadata. OpenAI repeats the same encrypted content on every summary-part end, so the part that remains open still carries it for replay.

Testing

  • bun test test/aisdk.test.ts, test/github-copilot, and test/session from packages/core
  • bun typecheck from packages/core
  • bun run check

Closes #50662

@rekram1-node rekram1-node changed the title fix(core): serialize AI SDK reasoning fragments fix(core): normalize AI SDK fragment boundaries Sep 23, 2026
@rekram1-node
rekram1-node merged commit f0381e5 into v2 Sep 23, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the gateway-protocol-fix branch September 23, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant