fix(session): recover orphan reasoning stream parts - #41630
Conversation
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.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
The following comment was made by an LLM, it may be inaccurate: Related PRs Found#39287 -
#26167 -
These are related PRs in the same stream recovery space, but #39287 is the direct predecessor that this PR builds upon. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #36241
Type of change
What does this PR do?
AI SDK reports a missing reasoning/text start as an in-band
part ... not founderror, 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 passbun typecheckfrompackages/opencodeScreenshots / recordings
Not applicable.
Checklist