Skip to content

refactor(context_compressor): extract tool-result summarizers (LB5a) - #80645

Open
andrexibiza wants to merge 6 commits into
NousResearch:mainfrom
andrexibiza:gfg/cc-lb5-summarizers
Open

refactor(context_compressor): extract tool-result summarizers (LB5a)#80645
andrexibiza wants to merge 6 commits into
NousResearch:mainfrom
andrexibiza:gfg/cc-lb5-summarizers

Conversation

@andrexibiza

@andrexibiza andrexibiza commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

God-file Feature Package (tracker #78647): agent/context_compressor.py slice LB5a — extract the tool-result one-line summarizers into agent/context_compressor_summarizers.py with an is-identical re-export seam.

Slice

  • God-file: agent/context_compressor.py (6,883 lines @ pin 6e9cae6ac4b)
  • Window: 1114–1289 @ pin (459–634 at LB4)
  • Golden sha256: efd0867b107f3f25cc0d4d2e4b3cb228be4bd8eef29c26026a593d19749939ec — byte-exact, verified by 5/5 blind reviewers (round 2)
  • Module: agent/context_compressor_summarizers.py (3 members)
  • Deps: one-way on skill-prune module; logger via lazy in-function round-trip import (auth s2 seam pattern) — no import-time cycle
  • Seam: godfile re-exports all 3 members; cc.<m> is cs.<m> verified at runtime

Round-2 fix (blind Pass E caught it)

test_summarize_tool_result_type_safety.py patched agent.context_compressor._summarize_tool_result_unguarded, but the call resolves via the summarizers module global after extraction — the mock never fired. Per extraction doctrine, test patch targets move with the code: retargeted to agent.context_compressor_summarizers._summarize_tool_result_unguarded. Dead typing imports trimmed.

Verification

  • 13/13 type-safety + 60/60 full family
  • 5/5 blind re-review APPROVED (round 2; round-1 CRITICAL confirmed fixed)
  • ruff clean · git diff --check clean · LF-only · DCO signed

Part of #78645
Part of #78647

…ll-prune

Wave-2 dual REQUEST_CHANGES agreed LB2 skill-prune cannot extract first:
it calls _redact_compaction_text and _content_text_for_contains (cycle).
Move those two pure leaves into context_compressor_text_utils.py with
is-identical re-export through the godfile. Golden bodies byte-exact.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
… (LB2)

Wave-2 redraw: banner-inclusive window 404-618 (golden
ec5defbef6a402ad302b28369c81f5f9182162f1c8353b231d2d863fe59305c0) into
context_compressor_skill_prune.py. Deps on the two text-util leaves now
import one-way from context_compressor_text_utils — no cycle. 12 members
re-exported is-identical through the godfile. 35/35 targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
Window 420-649 (current numbering; pin 616-868 minus the text-util leaf)
into context_compressor_budget.py. HISTORICAL_TASK_HEADING moves with the
cluster (sole external dep, re-exported is-identical). 29 members
re-exported through the godfile. 39/39 targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
Window 446-668 (banner-inclusive; pin 870-1111 minus leaves) into
context_compressor_media.py. 9 members re-exported is-identical through
the godfile; deps on typing/json/turn_context only (one-way). 43/43
targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
Window 459-634 (def-aligned; pin 1114-1289 per W2 redraw) into
context_compressor_summarizers.py. 3 members re-exported is-identical;
logger dep via lazy round-trip import (auth s2 seam pattern, zero
behavior change); skill-prune deps one-way from skill_prune module.
47/47 targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
…rs module

Pass E (blind) caught a regression: test_summarize_tool_result_type_safety
patched agent.context_compressor._summarize_tool_result_unguarded, but the
call resolves via the summarizers module global after extraction, so the
mock never fired. Per extraction doctrine, test patch targets move with
the code: retarget to context_compressor_summarizers. Also trim dead
typing imports in the new module.

13/13 type-safety + 60/60 family green.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
@andrexibiza

Copy link
Copy Markdown
Contributor Author

Interlock: Part of #78645 + #78647. 5/5 blind APPROVED (round 2) receipts in worktree tmp/PASS_*_R2_VERDICT.md.

@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/compression Context compression and continuation sessions P3 Low — cosmetic, nice to have labels Aug 6, 2026
@andrexibiza

Copy link
Copy Markdown
Contributor Author

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.

@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference, author can ignore or act on any point.

refactor(context_compressor): extract tool-result summarizers (LB5a)

  1. Heavy overlap with sibling extraction PRs — this PR and refactor(context_compressor): extract threshold coercion mixin (LB7) #80644 both move budget / media / skill_prune / summarizers / text_utils out of context_compressor.py (this one omits the threshold module that refactor(context_compressor): extract threshold coercion mixin (LB7) #80644 adds). If both land independently they will conflict on the same hunks. Since the series (refactor(context_compressor): extract content/media strip helpers (LB4) #80636 LB4, refactor(context_compressor): extract tool-result summarizers (LB5a) #80645 LB5a, refactor(context_compressor): extract durable session guards mixin (LB6) #81074 LB6, refactor(context_compressor): extract threshold coercion mixin (LB7) #80644 LB7) is clearly staged, coordinating so each stage builds on the merged previous one would avoid merge churn and duplicated seam tests.
  2. Patch-target migration is handled correctlytests/agent/test_summarize_tool_result_type_safety.py moves the mock target to agent.context_compressor_summarizers._summarize_tool_result_unguarded; the name is still re-exported on agent.context_compressor, so both old and new patch paths resolve to the same object. Worth keeping the re-export stable since runtime code may also reference it.
  3. The long _summarize_tool_result tool-name if/elif chain moved mechanically — the seam tests cover the moved functions in isolation; recommend one compress()-level test that exercises a summarized tool result end-to-end (e.g. a terminal call with a large output) to prove the extraction didn't alter which branch fires.
  4. Minor: the new module's top-level imports from sibling leaves while context_compressor imports it mid-file with # noqa: E402 — the import graph is exercised by cycle-free tests in the other seams, but a comment documenting the allowed dependency direction would help future edits.

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

Labels

area/compression Context compression and continuation sessions comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants