Skip to content

fix(context_compressor): harden tool-call previews in summaries - #12588

Open
sauerdaniel wants to merge 1 commit into
NousResearch:mainfrom
sauerdaniel:fix/context-compressor-summary-tool-arg-preview
Open

fix(context_compressor): harden tool-call previews in summaries#12588
sauerdaniel wants to merge 1 commit into
NousResearch:mainfrom
sauerdaniel:fix/context-compressor-summary-tool-arg-preview

Conversation

@sauerdaniel

@sauerdaniel sauerdaniel commented Apr 19, 2026

Copy link
Copy Markdown

What does this PR do?

Hardens context-compaction summary rendering for assistant tool calls.

Compaction summaries currently render tool arguments as truncated function-call-shaped pseudo examples such as execute_code({ ... }). Those summaries are injected into later model context. This change renders bounded, JSON-safe descriptive previews as name args={preview}, reducing ambiguity while preserving useful argument context.

Related Issue

Fixes #12586

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/context_compressor.py
    • Add _preview_tool_args_for_summary() for bounded, JSON-safe argument previews.
    • Bound string values, collection sizes, nesting depth, dictionary-key lengths, and total serialized size.
    • Preserve distinct values when shortening dictionary keys would otherwise collide.
    • Fall back to a compact valid-JSON envelope when a branching object exceeds the total preview budget.
    • Change summary serialization from name(args) pseudo calls to name args={preview}.
    • Preserve current sensitive-text redaction before preview construction.
  • tests/agent/test_context_compressor.py
    • Cover short JSON, long/multiline values, long and colliding keys, total-size bounds, and non-call-shaped serializer output.

How to Test

  1. Run scripts/run_tests.sh tests/agent/test_context_compressor.py -q.
  2. Confirm long-key previews retain both values while bounding key length.
  3. Confirm deeply branching arguments produce valid JSON within the configured budget.
  4. Confirm summaries contain execute_code args= and not execute_code({.

Final focused verification after resolving the current-main redaction-helper rebase:

200 passed

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run the focused context-compressor suite on the final rebased head: 200 passed
  • I've added tests for my changes
  • I've tested on my platform: Fedora Linux x86_64

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — behavior is documented in helper docstrings and tests
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — pure serializer logic; no platform API
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

Screenshots / Logs

/tmp/hermes-pr-venv/bin/python -m pytest tests/agent/test_context_compressor.py -q
200 passed in 8.39s

@sauerdaniel
sauerdaniel force-pushed the fix/context-compressor-summary-tool-arg-preview branch from 1a73ba3 to dc9b309 Compare April 19, 2026 15:55
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 23, 2026
@sauerdaniel
sauerdaniel force-pushed the fix/context-compressor-summary-tool-arg-preview branch from dc9b309 to e6435e3 Compare May 19, 2026 13:55

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for targeting a behavior that is still present on current main: agent/context_compressor.py:1506-1510 truncates raw arguments and emits name(args), and _generate_summary() consumes that serialization at agent/context_compressor.py:1778.

Problems

  • The proposed helper's dictionary branch copies keys unchanged at agent/context_compressor.py:494 in the PR. max_items, max_depth, and _shorten_string() do not bound a very long key, so a valid arguments object can still make the supposedly bounded preview arbitrarily large.

Suggested changes

  • Cap/replace overlong dictionary keys and add a regression test for that case, alongside the existing long-string-value coverage.

Automated hermes-sweeper review.

Comment thread agent/context_compressor.py
@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 12, 2026
@sauerdaniel
sauerdaniel force-pushed the fix/context-compressor-summary-tool-arg-preview branch 3 times, most recently from 7737021 to 7747dba Compare July 16, 2026 11:14
@sauerdaniel

Copy link
Copy Markdown
Author

Rebased onto current main in 7747dbade. The reviewer-requested key bounds, collision preservation, collection/depth limits, and total serialized-preview cap remain covered. Verification: focused context-compressor suite 182 passed; full canonical suite at -j 32 passed 2,026 files / 41,622 tests; Ruff and git diff --check passed.

@sauerdaniel
sauerdaniel force-pushed the fix/context-compressor-summary-tool-arg-preview branch from 7747dba to 1fd7d3d Compare July 22, 2026 08:24
@sauerdaniel

Copy link
Copy Markdown
Author

Rebased onto current main. The bounded JSON-safe preview, key-collision handling, depth/item limits, total serialized cap, and non-call-shaped name args= rendering remain intact. Focused context-compressor suite: 187/187; Ruff passed.

@sauerdaniel
sauerdaniel force-pushed the fix/context-compressor-summary-tool-arg-preview branch from 1fd7d3d to 30bbe35 Compare July 22, 2026 08:58
@sauerdaniel

Copy link
Copy Markdown
Author

Final refresh onto the latest main: the focused context-compressor suite now passes 187/187; Ruff passes. The branch is one commit and zero commits behind upstream.

@andrexibiza

Copy link
Copy Markdown
Contributor

Interlock completion for the context-compressor shard campaign:

The full related set is explicitly recorded in #81074, including the prior compressor shards, same-surface colliders/fixers, and their referenced issue nodes. The residual agent/context_compressor.py remains alive until the 2k Law is satisfied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] context compaction summaries still emit function-call-shaped pseudo tool calls with truncated arguments

4 participants