hermes - 💡(How to fix) Fix [RFC] Attempt JSON repair on truncated tool call args before aborting

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
RAW_BUFFERClick to expand / collapse

Problem

When the model emits truncated tool call arguments (finish_reason mismatched by router or provider, leaving a trailing {"key": or [{"name": "foo" without closing braces/brackets), conversation_loop.py currently returns an abort immediately. This costs a full API round-trip — the model has to re-generate its entire response.

Proposed solution

Before aborting, pass truncated arguments through _repair_tool_call_arguments — the same repair function already used for API sanitization (trailing commas, unclosed braces/brackets, control characters, etc.).

If repair succeeds on ALL truncated calls (valid JSON after fix), clear the invalid-args list and continue normally. Only abort if repair genuinely fails.

In practice, most truncations are simply an unclosed trailing object/array — repair handles them trivially. I've observed this saving 20-30 retry cycles per day in heavy usage.

The change is ~40 lines in the truncation detection block of conversation_loop.py — no new dependencies, no new abstractions. I'll open a PR if this looks good.

Prior art

Adapted from a similar approach in Reasonix's trunkation handling — attempting JSON repair before falling back to abort has proven effective there.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [RFC] Attempt JSON repair on truncated tool call args before aborting