fix: repair malformed JSON in model-written tool arguments - #62
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesTool argument repair
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
commit: |
5d80ea7 to
525b3db
Compare
e498ea7 to
4bde753
Compare
525b3db to
de67ad5
Compare
4bde753 to
1a632b2
Compare
de67ad5 to
eade981
Compare
1a632b2 to
ea8b00e
Compare
4b47377 to
98a175d
Compare
ea8b00e to
41902da
Compare
bf66a7c to
ebfb674
Compare
41902da to
1807f63
Compare
The helper throws when its input parses cleanly, so the two error assertions cannot silently compare against an empty string.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/agent-core/test/loop/tool-call.e2e.test.ts`:
- Around line 179-183: Update the test case for parseToolCallArguments to use
input containing both an invalid in-string escape and a separate structural
error, such as {"a":"bad \\*","b":[}, so repairInvalidStringEscapes is attempted
but reparsing still fails. Keep the assertion focused on returning the original
parseErrorMessage for the unmodified input.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2871e31a-253c-4d0b-abd1-d831ae342719
📒 Files selected for processing (3)
.changeset/tool-args-escape-repair.mdpackages/agent-core/src/loop/tool-call.tspackages/agent-core/test/loop/tool-call.e2e.test.ts
The previous input never triggered a repair, so the fallback that reports the original error after a failed reparse was untested.
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @pythoughts/pythinker-code@0.16.0 ### Minor Changes - [#59](#59) [`6999b68`](6999b68) - Add an opt-in advisor: a second model reviews the conversation after a completed user turn unless another review is already running, and its notes appear as an `<advisory>` block in the agent's next turn; enable with `[advisor] enabled = true` plus an advisor model (the `advisor` model role or `[advisor] model`), and it runs only when the advisor shares the session model's provider. - [#56](#56) [`b71f094`](b71f094) - Add model roles: lock a model alias to the small, implementer, or advisor slot with `/model <role>`, list assignments with `/model roles`, and reference roles as `@small`, `@implementer`, or `@advisor` wherever a subagent model can be set; an assigned implementer role becomes the default model for subagents. - [#57](#57) [`99c427c`](99c427c) - Show what the agent is doing in the working indicator: eligible tool calls whose input schema accepts the injected field now carry a short model-written intent, streamed live into the spinner label (for example "check failing test…") instead of a rotating placeholder; disable with `PYTHINKER_CODE_EXPERIMENTAL_TOOL_INTENT=0`. - [#58](#58) [`065bf2e`](065bf2e) - Redesign core TUI surfaces: tool cards get state-tinted backgrounds with three new theme tokens, a status bar with a per-session accent color appears between the input box and footer, and the prompt box uses a neutral border while permission mode appears in the status bar. The working-label shimmer uses a calmer constant-velocity sweep with alternating mission-control highlights. ### Patch Changes - [#62](#62) [`7fc36fd`](7fc36fd) - Repair invalid escape sequences and unescaped quotes in model-written tool arguments instead of failing the tool call. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary
Model-written tool arguments sometimes fail strict
JSON.parseand kill the tool call at preflight. Two failure classes were observed in real Dynamic Workflow launches:\*inside JSON string values (Bad escaped character at position 3458)."inside a string value that terminates it early (Expected ',' or ']' after array element in JSON at position 2832).Both now repair instead of failing the call. The repair runs only as a fallback after
JSON.parserejects the input, and the original parse error is still reported when the repaired text also fails to parse.Approach
A single scanner pass rewrites invalid escapes to a literal backslash plus character, and rewrites an in-string
"to\"unless the next non-whitespace character is structural (,:}]) or end of input. A content quote immediately followed by a structural character stays ambiguous and still closes the string; that limit is documented in the function comment.Test plan
packages/agent-core/test/loop/tool-call.e2e.test.ts— 45 tests, including a reproduction of the observed items-array failure, mixed-class repair, whitespace before the terminator, and preservation of the original error on still-broken input.Summary by CodeRabbit
Bug Fixes
Tests