Add JSON sanitizer for Kimi models (fix malformed tool call arguments)#6691
Closed
nosleepcassette wants to merge 3 commits into
Closed
Add JSON sanitizer for Kimi models (fix malformed tool call arguments)#6691nosleepcassette wants to merge 3 commits into
nosleepcassette wants to merge 3 commits into
Conversation
- Use git checkout --force to handle untracked files that conflict with target branch - Add error handling with helpful message if checkout fails - Fixes issue where hermes update would fail on detached HEAD with untracked files This commonly affects developers with session logs, generated skills, or other untracked files in the working directory.
These models produce malformed JSON in tool call arguments: - Unterminated strings at char 1 - Missing closing braces - Truncated key-value pairs This patch: - Adds tools/kimi_json_sanitizer.py with repair logic - Hooks into run_agent.py JSON validation (line 8820-8834) - Only activates for known problematic models - Falls back gracefully if sanitizer unavailable Fixes cascading retry failures on models with JSON serialization issues.
6 tasks
Contributor
|
Thanks for this contribution! The malformed tool call argument problem you diagnosed is real and was already fixed on This is an automated hermes-sweeper review.
Closing as implemented. If you believe there are Kimi-specific edge cases the general pipeline misses, please open a targeted issue with a reproduction. |
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.
Problem
The
moonshotai/kimi-k2-instructmodel (and similar Kimi variants) produce malformed JSON in tool call arguments, causing cascading failures:The current retry logic (3 retries) amplifies the problem since the same malformed JSON gets re-serialized unchanged.
Solution
This PR adds a model-specific JSON sanitizer that:
is_kimi_model()checkrun_agent.py:8820-8834Files Changed
tools/kimi_json_sanitizer.py- New sanitizer modulerun_agent.py- Hook into JSON validation for repair attempt before declaring invalidTesting
Tested against the following malformed JSON patterns:
Notes
*kimi*patternThis enables use of capable-but-janky models without polluting the core agent loop with model-specific hacks.