fix: prevent opencode run crash on malformed tool inputs#13050
Closed
0xK3vin wants to merge 4 commits into
Closed
Conversation
Wrap the tool display dispatch in a try/catch so that when the LLM omits required fields, the CLI falls back to the generic display instead of crashing with a TypeError. Fixes anomalyco#12978
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12978
The
tool()display function inrun.tsreads raw LLM input before Zod validates it — so if the model omits a required field (likesubagent_typeontask), it crashes with a TypeError. This also kills the self-healing retry loop since Zod never gets a chance to tell the model what it got wrong.Fix: wrapped the dispatch body in a try/catch that falls back to the existing
fallback(part)handler. Valid inputs behave exactly the same, malformed ones get the generic display instead of a crash.I know the style guide prefers
.catch()over try/catch — buttool()is synchronous, so using.catch()would mean wrapping it in a Promise which changes the execution timing from sync to async and could introduce new bugs. Didn't think it was worth it.Tested by mocking all 12 tool display functions with missing required fields — 9 crashed before, 0 after.
Thanks to @ariane-emory for helping me make my first PR to OpenCode.