GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||
GeezerVison is showing github.com — fix(session): fix root causes and reconstruction of tool_use/tool_result mismatch (#16749) by altendky · Pull Request #16751 · anomalyco/opencode Conversation
|
| Layer | Where it acts | What it prevents |
|---|---|---|
| Layer 1 (tool-error race) | Stream event handling | Silent error drops that leave tools in wrong state |
| Layer 2 (recovery step-finish) | Retry loop, before continue |
DB corruption at write time — ensures step boundaries are preserved |
| Layer 3 (synthetic step-start) | Message reconstruction | Handles already-corrupted DB data + any future edge cases the above layers miss |
Session ses_32fb35486ffeeJAHmplKU1gB2t, message msg_cd05ba534001gICo48Lsy1NHWp:
part_id | type | tool | status | error
-------------------------------+-------------+-------+--------+------------------------
prt_cd05bb9ac001... | step-start | | |
prt_cd05bb9ad001... | text | | |
prt_cd05bb9f0001... | tool | write | error | Tool execution aborted
← 96 SECOND GAP
prt_cd05d3273001... | text | | |
prt_cd05d35a8001... | tool | write | completed |
prt_cd05f3c5d001... | step-finish | | |
input: {} — tool-error was dropped because status was "pending" (Layer 1 root cause)step-finish/step-start boundary between the two groups (Layer 2 root cause)[step-start, text, tool(error), text, tool(completed)]) and asserts the structural invariant: no text or reasoning part appears after a tool-call part in the same assistant ModelMessageContent types in this message: [text, tool-call, text, tool-call]| File | Change |
|---|---|
packages/opencode/src/session/processor.ts |
Tool-error race fix (accept "pending") + recovery step-finish before retry |
packages/opencode/src/session/message-v2.ts |
Synthetic step-start injection in toModelMessages() |
packages/opencode/test/session/message-v2.test.ts |
Test reproducing corrupted DB interleaving pattern |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…smatch (anomalyco#16749) Add failing test demonstrating that when step-finish/step-start parts are missing (due to retryable stream errors), toModelMessages produces a single assistant block with interleaved tool-call and text parts. Currently fails with: Content types in this message: [text, tool-call, text, tool-call].
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate: Found related PRs that may address similar issues:
These PRs may already be working on fixes for the issues this test case is reproducing. Check if they've been merged or if there's overlap in the solution approaches. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…terleaved due to missing step boundaries When the finish-step handler throws during a retryable error, step-finish for step 1 and step-start for step 2 are never saved. Both steps' content merges into one DB message without boundaries. On replay, convertToModelMessages() produces a single assistant block with interleaved tool_use/text, which the Anthropic API rejects. Fix: track whether we've seen a tool part in the current step. If text or reasoning appears after a tool part without an intervening step-start, inject a synthetic step-start to force the AI SDK to split content into separate blocks.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Missing step-finish/step-start parts after retryable stream errors cause tool_use/tool_result mismatch
There was an error while loading. Please reload this page.