fix(compressor): fix context compression Pass 3, make it JSON-safe for tool_call arguments and add test#11821
Closed
otherview wants to merge 1 commit into
Closed
fix(compressor): fix context compression Pass 3, make it JSON-safe for tool_call arguments and add test#11821otherview wants to merge 1 commit into
otherview wants to merge 1 commit into
Conversation
…d regression tests
This was referenced Apr 18, 2026
Contributor
|
Closing as duplicate of PR #12259 (merged). You independently diagnosed the same bug on Apr 17 within hours of #11788 and #11617, and your test coverage was excellent. We went with #11788's implementation because it was similar in approach but with slightly simpler logic and came with its own test suite. Credited in the salvage PR body — thanks! |
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.
What does this PR do?
This PR fixes a context compression bug where Pass 3 could corrupt
tool_calls.function.argumentsby raw string truncation (args[:200] + "...[truncated]"), producing invalid JSON and causing downstreamjson.loads(arguments)failures (for exampleUnterminated string).The fix keeps Pass 3, but makes it JSON-safe:
argumentsas JSON before modifying.json.dumps(...)so output stays valid JSON.This approach preserves the intent of Pass 3 (reduce oversized args) without violating the tool-call JSON contract.
Related Issue
Fixes #
Type of Change
Changes Made
agent/context_compressor.py:_shrink_json_for_tool_args(...)recursive helper.argumentsverbatim (skip mutation on parse failure).tests/agent/test_context_compressor.py:How to Test
pytest -q tests/agent/test_context_compressor.pytool_calls.function.argumentsare reduced in size.json.loads(arguments)succeeds for shrunk payloads.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs