fix(opencode): ensure tool_use/tool_result integrity and Anthropic user-first ordering - #31547
fix(opencode): ensure tool_use/tool_result integrity and Anthropic user-first ordering#31547TeddyEngel wants to merge 1 commit into
Conversation
|
believe this has previously been fixed elsewhere actually, unless u can send me a session where u hit it |
|
@rekram1-node it's unfortunately still an issue. Here is a redacted session that crashes on latest dev, resumes ok with my fix: crash_minimal.json |
|
I'm using the newest version of OpenCode, and I got this error, too, using Anthropic models. |
@AlphaComposite Feel free to cherrypick my commit into your local forked repo and run it locally as I don't know if they want to merge this or not - you won't get the issue and it should resume the compacted sessions properly. Been running it myself for 5 days and not getting any issue anymore. I believe they are working on a fix for the root cause |
|
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 #27594
Type of change
What does this PR do?
(The PR implements fix 4 from the linked issue: "A defensive pass that pairs every
tool_usewith the matchingtool_resultbefore dispatch.")Sessions that had undergone nested compaction would fail to resume. The specific error encountered was from Anthropic:
Two issues were identified:
Orphan Tool-Calls (All Providers)
After nested compaction, tool-calls could become orphaned (no corresponding tool-result). Most LLM APIs reject this.
User-First Ordering (Anthropic Only)
After nested compaction, the message array could start with system messages followed directly by an assistant message. Anthropic requires the first non-system message to be
user:How did you verify your code works?
Checklist
If you do not follow this template your PR will be automatically rejected.