Skip to content

fix: handle Copilot GPT-5 reasoning streams#577

Merged
will-lamerton merged 3 commits into
Nano-Collective:mainfrom
EntropyParadigm:fix/copilot-gpt5-reasoning-stream
Jun 16, 2026
Merged

fix: handle Copilot GPT-5 reasoning streams#577
will-lamerton merged 3 commits into
Nano-Collective:mainfrom
EntropyParadigm:fix/copilot-gpt5-reasoning-stream

Conversation

@EntropyParadigm

@EntropyParadigm EntropyParadigm commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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:

  • patch @ai-sdk/openai@3.0.71 so Responses reasoning completion / summary events can arrive without a pre-existing activeReasoning entry
  • accumulate streamed text in Nanocoder's chat handler and use it as the final assistant content fallback
  • restore compact tool error punctuation expected by existing tests
  • make file watcher path-filter coverage deterministic via the existing _watchFn test hook
  • clear shutdown timeout handles and reset directly constructed shutdown managers in tests
  • add regression tests for both the streamed-text fallback and Copilot-style Responses reasoning events

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Commands run in a clean WSL-native verification clone:

  • corepack pnpm run build
  • corepack pnpm run test:all

pnpm test:all completed successfully with the repo script's Semgrep branch skipped because semgrep is not installed in the local environment:

✅ AVA tests passed
✅ Knip check passed
✅ Audit passed
⚠️  Semgrep not installed - skipping security scan
✅ Everything passes!

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.ts

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Manual/local repro validation:

  • configured GitHub Copilot provider with gpt-5.5
  • verified nanocoder --provider "GitHub Copilot" --model gpt-5.5 run "reply with exactly ok" returns ok with the local equivalent patch

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

Copilot AI review requested due to automatic review settings June 16, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.text is 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.71 to 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;
Comment on lines +150 to +157
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,
});
Comment on lines +158 to +162
+ 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;
@EntropyParadigm

Copy link
Copy Markdown
Contributor Author

Follow-up pushed in ddd24966 to make the repo's full local gate pass strictly:

  • restored compact tool error punctuation expected by existing tests
  • made file watcher path-filter coverage deterministic with _watchFn
  • cleared shutdown timeout handles and reset directly constructed shutdown managers in tests

Verified in a clean WSL-native clone:

corepack pnpm run build
corepack pnpm run test:all

Result: ✅ Everything passes! (semgrep skipped by scripts/test.sh because it is not installed locally).

@will-lamerton

Copy link
Copy Markdown
Member
  • restored compact tool error punctuation expected by existing tests
  • made file watcher path-filter coverage deterministic with _watchFn
  • cleared shutdown timeout handles and reset directly constructed shutdown managers in tests

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 :)

@EntropyParadigm

Copy link
Copy Markdown
Contributor Author
  • restored compact tool error punctuation expected by existing tests
  • made file watcher path-filter coverage deterministic with _watchFn
  • cleared shutdown timeout handles and reset directly constructed shutdown managers in tests

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 :)

@will-lamerton will-lamerton merged commit 19d238b into Nano-Collective:main Jun 16, 2026
@will-lamerton

Copy link
Copy Markdown
Member

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
https://github.com/Nano-Collective/organisation

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.

GitHub Copilot GPT-5 streams can crash on missing reasoning summary state

3 participants