fix(chat): graceful degradation for malformed tool call arguments (v2)#22115
Closed
huckstack wants to merge 1 commit intoggml-org:masterfrom
Closed
fix(chat): graceful degradation for malformed tool call arguments (v2)#22115huckstack wants to merge 1 commit intoggml-org:masterfrom
huckstack wants to merge 1 commit intoggml-org:masterfrom
Conversation
DISCLOSURE: This patch was developed by a human (David @ huckstack) with assistance from an AI coding agent (Hermes). The human reviewed and approved all changes. Problem: When models generate malformed JSON in tool call arguments (e.g., unescaped single quotes like log_dir = '/home/user/.hermes/logs/cron'), func_args_not_string() throws an HTTP 500 error. This causes cascading failures where every subsequent request crashes with 'Failed to parse tool call arguments as JSON: unexpected end of input'. The function was introduced in commit b283f6d with throw, which converts a recoverable parsing error into a hard server error. Fix: Replace throw with LOG_WRN in func_args_not_string(). This converts the hard 500 error into graceful degradation — the server logs a warning and keeps the arguments as a string, allowing the conversation to continue. Note: This is a pragmatic workaround, not a root fix. The core issue is that the PEG parser in the TAG_WITH_TAGGED tool format (introduced by PR ggml-org#21216) fails on malformed JSON in parameter values. See issue ggml-org#21771 for the full analysis of the parser regression. Related: ggml-org#21771 Signed-off-by: David @ huckstack <huckstack@gmail.com>
Member
|
Duplicate of #22089 |
|
Hi @huckstack, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
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.
DISCLOSURE
This contribution was developed by a human (David @ huckstack) with assistance from an AI coding agent (Hermes). The human reviewed and approved all changes.
Problem
When models generate malformed JSON in tool call arguments (e.g., unescaped single quotes like
log_dir = '/home/user/.hermes/logs/cron'),func_args_not_string()throws an HTTP 500 error. This causes cascading failures where every subsequent request crashes withFailed to parse tool call arguments as JSON: unexpected end of input.The function was introduced in commit b283f6d with
throw, which converts a recoverable parsing error into a hard server error.Fix
Replace
throwwithLOG_WRNinfunc_args_not_string(). This converts the hard 500 error into graceful degradation — the server logs a warning and keeps the arguments as a string, allowing the conversation to continue.Context
This is a pragmatic workaround, not a root fix. The core issue is that the PEG parser in the TAG_WITH_TAGGED tool format (introduced by PR #21216) fails on malformed JSON in parameter values. See issue #21771 for the full analysis of the parser regression.
Related: #21771, #22072, #12068 (hermes-agent)
Testing
This fix has been validated on:
The fix prevents the HTTP 500 cascade while allowing the conversation to continue. The warning is logged for debugging purposes.