Skip to content

fix(session): recover orphan reasoning stream parts - #41630

Open
bvolpato wants to merge 3 commits into
anomalyco:devfrom
bvolpato:reasoning-recovery
Open

fix(session): recover orphan reasoning stream parts#41630
bvolpato wants to merge 3 commits into
anomalyco:devfrom
bvolpato:reasoning-recovery

Conversation

@bvolpato

@bvolpatobvolpato commented Aug 11, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#36241

Type of change

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

What does this PR do?

AI SDK reports a missing reasoning/text start as an in-band part ... not found error, then keeps streaming. OpenCode promoted that bookkeeping error to a fatal turn failure.

Emit a missing start before orphan deltas or end events, preserve provider metadata, and ignore only matching AI SDK bookkeeping errors. Real provider errors still fail.

Based on #39287 by DragonBaiMo, rebased onto current dev, with coverage moved into current adapter suite. Existing PR no longer passes that suite after recent adapter changes.

How did you verify your code works?

  • bun test test/session/llm.test.ts: 29 pass
  • bun typecheck from packages/opencode
  • pre-push repository typecheck: 30 tasks pass

Screenshots / recordings

Not applicable.

Checklist

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

DragonBaiMoand others added 3 commits August 10, 2026 20:55
The AI SDK enqueues a non-fatal "reasoning part <id> not found" / "text
part <id> not found" error part when a reasoning/text delta arrives with no
preceding *-start block (common with OpenAI-compatible and Anthropic
proxies). The adapter promoted every error part to a fatal Effect.fail,
aborting the turn and spamming logs. Recognize these SDK-internal orphan
stream-state errors and drop them instead of failing; genuine errors still
fail.
Proxies that stream deltas without a preceding *-start caused the
processor to drop the delta and any providerMetadata riding on it,
including Anthropic thinking signatures. Repair the stream in the
adapter by emitting the missing start before the delta.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actionsgithub-actionsBot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PRs Found

#39287 - fix(session): repair orphan reasoning/text stream parts instead of failing the turn

#26167 - fix(session): retry empty stream truncations and discard partial parts

These are related PRs in the same stream recovery space, but #39287 is the direct predecessor that this PR builds upon.

Sign up for freeto 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.

[macOS v1.17.18] gpt-5.6-sol-fast/high repeatedly fails with reasoning part rs_*:0 not found

2 participants

@bvolpato@DragonBaiMo