Skip to content

refactor(context_compressor): extract content/media strip helpers (LB4) - #80636

Open
andrexibiza wants to merge 4 commits into
NousResearch:mainfrom
andrexibiza:gfg/cc-lb4-media
Open

andrexibiza wants to merge 4 commits into
NousResearch:mainfrom
andrexibiza:gfg/cc-lb4-media

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 LB4 — extract the content/media strip helpers into agent/context_compressor_media.py with an is-identical re-export seam.

Slice

  • God-file: agent/context_compressor.py (6,883 lines @ pin 6e9cae6ac4b)
  • Window: 870–1111 @ pin (446–668 banner-inclusive at LB3)
  • Golden sha256: 9e0acd77719ca3f8533dba593d85e768eb8ac0aef1ae8c49021de82a50f80433 — byte-exact, verified by 5/5 blind reviewers
  • Module: agent/context_compressor_media.py (9 members: _IMAGE_PART_TYPES + 8 functions)
  • Deps: stdlib + agent.turn_context only — no cycle
  • Seam: godfile re-exports all 9 members; cc.<m> is cm.<m> verified at runtime

Verification

  • 43/43 targeted tests (seam + all prior slices + ghost-skill + redaction + zero-user-guard)
  • 5/5 blind re-review APPROVED (0 CRITICAL / 0 IMPORTANT; 1 cosmetic MINOR on blank-line bookkeeping)
  • 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>
@andrexibiza

Copy link
Copy Markdown
Contributor Author

Interlock: Part of #78645 + #78647. 5/5 blind APPROVED receipts in worktree tmp/PASS_*_VERDICT.md.

@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/compression Context compression and continuation sessions 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 content/media strip helpers (LB4)

  1. The mid-file # noqa: E402 import blocks are load-bearingagent/context_compressor.py (~L9-70): imports of the new leaf modules are placed after module-level code to dodge circular imports. That ordering becomes fragile the moment a leaf module imports back from context_compressor (the sibling LB6 extraction refactor(context_compressor): extract durable session guards mixin (LB6) #81074 introduces exactly such a round-trip seam). Consider documenting the dependency direction (leaves must never import from the parent at module scope) in a comment above the block.
  2. No whole-compress() E2E assertion — the seam tests verify each leaf function in isolation, but nothing proves the extracted helpers are still invoked with identical semantics end-to-end. A single compress() smoke test (real ContextCompressor, call_llm stubbed) would lock the integration; the sibling refactor(context_compressor): extract message marker helpers #81243 pattern (byte-hash) is one approach, behavior assertions are a better one.
  3. HISTORICAL_TASK_HEADING moved to context_compressor_budget and re-exported through the top import — external code doing from agent.context_compressor import HISTORICAL_TASK_HEADING keeps working, but anything importing it from the module directly (tests/plugins) should be migrated to the new home to avoid a hidden two-source constant.
  4. New modules have no __all__ — each leaf exports a large surface of _private names; an explicit __all__ would make the seam surface self-documenting and catch accidental new exports. (Minor.)

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