fix: handle Copilot GPT-5 reasoning streams#577
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves resilience when the AI SDK fails to provide a final aggregated response, by falling back to streamed text captured from the token stream, and patches @ai-sdk/openai to tolerate certain reasoning/summary SSE sequences.
Changes:
- Accumulate streamed text deltas and use them as a fallback when
result.textis empty/unavailable. - Add AVA tests for streamed fallback behavior and for OpenAI Responses parser tolerance.
- Apply a pnpm patch to
@ai-sdk/openai@3.0.71to avoid crashes on missing reasoning state.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| source/ai-sdk-client/chat/chat-handler.ts | Captures streamed text and uses it as a fallback for the final response content / empty-output handling. |
| source/ai-sdk-client/chat/chat-handler.spec.ts | Adds tests for streamed fallback and parser tolerance scenarios. |
| pnpm-workspace.yaml | Registers a patched dependency for @ai-sdk/openai@3.0.71. |
| patches/@ai-sdk__openai@3.0.71.patch | Patches OpenAI Responses language model parsing to handle missing reasoning state safely. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| : []; | ||
|
|
||
| const content = fullText; | ||
| const content = fullText || accumulatedText; |
| controller.enqueue({type: 'text-start', id: '0'}); | ||
| controller.enqueue({type: 'text-delta', id: '0', delta: 'ok'}); | ||
| controller.enqueue({type: 'text-end', id: '0'}); | ||
| controller.enqueue({ | ||
| type: 'finish', | ||
| finishReason: 'stop', | ||
| usage, | ||
| }); |
| + const activeReasoningPart = activeReasoning[value.item_id] ?? | ||
| + (activeReasoning[value.item_id] = { | ||
| + encryptedContent: null, | ||
| + summaryParts: {}, | ||
| + }); |
| // reasoning-aware nudge depends on this for the GPT-5 case where the | ||
| // SDK throws AI_NoOutputGeneratedError after a reasoning-only stream. | ||
| let accumulatedReasoning = ''; | ||
| let accumulatedText = ''; |
| } | ||
| break; | ||
| case 'text-delta': | ||
| accumulatedText += chunk.text; |
| : []; | ||
|
|
||
| const content = fullText; | ||
| const content = fullText || accumulatedText; |
|
Follow-up pushed in
Verified in a clean WSL-native clone: corepack pnpm run build
corepack pnpm run test:allResult: |
Hey @EntropyParadigm - really appreciate this PR. Looking good and great to merge! On the stabilisation of the test gates, are you okay to revert this commit? These issues have been addressed on main now and are out of scope for this PR. Thanks :) |
Of course, my pleasure and totally good to revert the commit. Thank you :) |
This reverts commit ddd2496.
|
Thanks for this PR @EntropyParadigm - feel free to add yourself as a contributor to our website via a PR which I will approve :) https://nanocollective.org/contributors |
Description
Fixes #576.
This PR makes GitHub Copilot GPT-5 / Responses streams more tolerant of Copilot's reasoning event ordering and preserves streamed text when the AI SDK final text accessor reports no output.
Changes:
@ai-sdk/openai@3.0.71so Responses reasoning completion / summary events can arrive without a pre-existingactiveReasoningentry_watchFntest hookType of Change
Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Commands run in a clean WSL-native verification clone:
corepack pnpm run buildcorepack pnpm run test:allpnpm test:allcompleted successfully with the repo script's Semgrep branch skipped becausesemgrepis not installed in the local environment:Additional focused regression command:
corepack pnpm run test:ava source/events/sources/file-watcher.spec.ts source/utils/shutdown/shutdown-manager.spec.ts source/utils/tool-result-display.spec.tsx source/ai-sdk-client/chat/chat-handler.spec.tsManual Testing
Manual/local repro validation:
gpt-5.5nanocoder --provider "GitHub Copilot" --model gpt-5.5 run "reply with exactly ok"returnsokwith the local equivalent patchChecklist