fix: Critical thread crash from tool validation errors#1363
Open
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
Open
fix: Critical thread crash from tool validation errors#1363gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
gdeyoung wants to merge 1 commit intoagent0ai:mainfrom
Conversation
- Move validate_tool_request() inside None check in process_tools() - Wrap validation in try/except to convert ValueError to warning - Add defensive tool_args parsing for models returning JSON strings Fixes critical bug where malformed LLM output causes unhandled ValueError that locks up the entire agent thread.
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.
Critical Bug: Thread lockup from unhandled ValueError
Impact
Agent threads lock up completely when the LLM output cannot be parsed as valid JSON. This happens at a significant rate — any time a model produces non-JSON output (reasoning text, markdown with no JSON block, malformed JSON, etc.), the entire conversation thread dies with:
The thread becomes unrecoverable — no retry, no graceful degradation, just a dead thread.
Root Cause
In
agent.pyprocess_tools(),validate_tool_request()is called before theNonecheck ontool_request:The existing
elsebranch (line ~939) already handlesNonegracefully with a misformat warning — but it is unreachable because the validation crashes first.Fix
validate_tool_request()inside theNonecheck — so unparseable output falls through to the existing graceful handlertry/except ValueError— converts crashes into logged warnings that allow the message loop to continuetool_argsparsing — handles models that returntool_argsas a JSON string instead of a dict (confirmed issue with MiniMax M2.5 and others)Testing
Nonefromjson_parse_dirty()gracefullyValueErrorfrom validation is caught and logged as warningtool_argsstring parsing works with JSON string inputsWhy This Is Safe
elsebranchelsebranch already existed: This was always the intended behavior — the bug was just an ordering error