Skip to content

fix: prevent opencode run crash on malformed tool inputs#13050

Closed
0xK3vin wants to merge 4 commits into
anomalyco:devfrom
0xK3vin:fix/run-crash-malformed-tool-input
Closed

fix: prevent opencode run crash on malformed tool inputs#13050
0xK3vin wants to merge 4 commits into
anomalyco:devfrom
0xK3vin:fix/run-crash-malformed-tool-input

Conversation

@0xK3vin

@0xK3vin 0xK3vin commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #12978

The tool() display function in run.ts reads raw LLM input before Zod validates it — so if the model omits a required field (like subagent_type on task), 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 — but tool() 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.

adamdotdevin and others added 4 commits February 10, 2026 15:53
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
@github-actions

Copy link
Copy Markdown
Contributor

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

No duplicate PRs found

@0xK3vin 0xK3vin closed this Feb 11, 2026
@0xK3vin
0xK3vin deleted the fix/run-crash-malformed-tool-input branch February 11, 2026 02:04
Sign up for free to 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.

opencode run crashes when task tool input lacks subagent_type

3 participants