Skip to content

fix: sanitize multiline tool-call JSON - #370

Merged
xDarkicex merged 1 commit into
mainfrom
agent/fix-multiline-tool-call-sanitization
Aug 1, 2026
Merged

fix: sanitize multiline tool-call JSON#370
xDarkicex merged 1 commit into
mainfrom
agent/fix-multiline-tool-call-sanitization

Conversation

@compoodment

@compoodment compoodment commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace the single-line raw tool-call JSON regex with brace- and string-aware object scanning.
  • Parse each complete candidate as JSON and remove it only when it contains a direct or nested tool-call record.
  • Preserve adjacent ordinary JSON instead of allowing a multiline match to span unrelated objects.

Root cause

TOOL_CALL_JSON_RE used [^\r\n]*, so it could never match a formatted JSON object across line breaks. Simply changing it to a cross-line wildcard would risk consuming from an earlier ordinary object through a later tool call, especially with nested arguments.

Impact

Historical multiline tool-call JSON is now removed from recalled context before it can prime a model to repeat tool syntax, without deleting neighboring ordinary structured memory.

Verification

  • pnpm exec tsc --noEmit
  • Full .ts-build/test/unit/context-engine.test.js — 74/74 passed
  • Focused historical-tool, ordinary-JSON, and multiline-tool-JSON tests — 3/3 passed
  • git diff --check

Fixes #353.

– Vale

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@compoodment, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf4b9ff4-9453-49e0-9f97-7e528be58f8b

📥 Commits

Reviewing files that changed from the base of the PR and between 96467dd and a3aab9c.

📒 Files selected for processing (2)
  • src/context-engine.ts
  • test/unit/context-engine.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@compoodment
compoodment marked this pull request as ready for review July 13, 2026 11:24
@compoodment

Copy link
Copy Markdown
Collaborator Author

Vale Review — PR #370

Quality: Q4/5 — sharp
Head: a3aab9c

Findings:

  • src/context-engine.ts:1273 — None: the new scanner is string/brace-aware, and src/context-engine.ts:1326-1340 removes only parsed objects that contain a tool-call record while preserving neighboring ordinary JSON. info

Proof gaps: No local gate run in this worker; PR reports TypeScript and the focused context-engine unit coverage.

Verdict: comment-only — self-authored PR, focused fix, no current-head blocker found.

– Vale
use @vale review

@xDarkicex xDarkicex added the release:patch Bump patch version on merge label Aug 1, 2026
@xDarkicex
xDarkicex merged commit f94464e into main Aug 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:patch Bump patch version on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: TOOL_CALL_JSON_RE cannot match multiline JSON tool-call objects

2 participants