Skip to content

refactor(context_compressor): extract summary kernel and preserve compatibility - #81181

Open
andrexibiza wants to merge 11 commits into
NousResearch:mainfrom
andrexibiza:gfg/cc-lb8-summary-repair
Open

refactor(context_compressor): extract summary kernel and preserve compatibility#81181
andrexibiza wants to merge 11 commits into
NousResearch:mainfrom
andrexibiza:gfg/cc-lb8-summary-repair

Conversation

@andrexibiza

@andrexibiza andrexibiza commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Extract the graph-authorized ten-method summary/provenance kernel from agent/context_compressor.py into ContextCompressorSummaryKernelMixin, with compatibility synchronization for reloads and legacy monkeypatch surfaces.

Commits

  • Extraction candidate: 57570954260b370c5d9b4ac4ba0223f71e4fd880
  • Repair commit: e40f2db1402cb629dedcff57e656dee439bb51c3
  • Extraction base: 4effdf33967f49f19069c00c5b5348fd8c10539b
  • Branch: gfg/cc-lb8-summary-repair

Exact scope

  • Ten methods from agent/context_compressor.py:2771–2932
  • Source-window SHA-256: 32b86ff4151753a2a1bf1793090a145af18f485f308f0e0fb7f8e180a619b1bc
  • Repair preserves all ten method AST and dedented source-byte identities.
  • Residual agent/context_compressor.py: 5,350 lines; this shard is one step toward the hard 2K invariant and does not claim final god- compliance.

Parent receipts

  • Compatibility RED→GREEN repro: passed
  • Focused LB8 seam/summary/compressor suite: 138 passed
  • Ten-method AST/source-byte proof: 10/10 passed
  • Ruff, syntax, LF, diff-check, DCO: passed
  • Five post-repair 5×2×3 validators: 5/5 APPROVE

Interlock targets

Gate

This PR supersedes the pre-repair candidate thread and is filed from the fork branch after unanimous 5×2×3 validation. The prior candidate evidence remains preserved as historical provenance; it does not represent the shipped head. No final god- is claimed: the residual file remains above 2,000 lines.

…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>
Window 1307-1422 (class attrs + 5 static/instance methods) into
ContextCompressorThresholdMixin (MRO seam, SessionTitleMixin precedent).
Mixin composed into ContextCompressor bases; members resolve is-identical
through the class. One class-name reference retargeted to the mixin.
Deps one-way on budget module + model_metadata. 52/52 targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

Signed-off-by: Andrex Ibiza <andrexibiza@users.noreply.github.com>
Window 762-1203 (pin 1589-2030) into ContextCompressorDurableGuardsMixin.
Mixin composed BEFORE ContextEngine in bases so its on_session_end/start
shadow the base (as the godfile's own defs did) — MRO pitfall documented
in seam test. 15 members resolve is-identical through the class.
Deps: typing + time (stdlib). 70/70 targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

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

Blind review lanes caught: sqlite3/json used in exception handlers but
not imported; PROACTIVE_PRUNE_REARM_MODEL_CONFIG_KEY co-moved at class
scope but imported at module level; logger used without binding. Fix:
module-level json/sqlite3 imports, constant at module scope, lazy
round-trip logger imports per method (summarizers pattern). 70/70 green.

Part of NousResearch#78645
Part of NousResearch#78647

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

Round-1 blind 5/5 REQUEST_CHANGES confirmed the import gaps; Pass E
additionally caught UnboundLocalError: lazy logger import sat inside the
first except clause while sibling except clauses also used logger.
Move the round-trip import to the first statement of each method body
so logger is bound before any branch. 94/94 targeted tests green.

Part of NousResearch#78645
Part of NousResearch#78647

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

Copy link
Copy Markdown
Contributor Author

LB8 bidirectional interlock — summary-kernel shard.

Primary nodes:

Repair/final validation:

  • repair commit: e40f2db1402cb629dedcff57e656dee439bb51c3
  • extraction base: 4effdf33967f49f19069c00c5b5348fd8c10539b
  • 5×2×3 post-repair validation: 5/5 APPROVE
  • parent compatibility, exact-method, runtime, hygiene, and collision gates: passed

Scope:

  • agent/context_compressor.py:2771–2932
  • agent/context_compressor_summary_kernel.py
  • tests/agent/test_context_compressor_summary_kernel_seam.py
  • ten approved pure methods; exact AST/source-byte preservation verified

This shard is one step toward the 2,000-line law. agent/context_compressor.py remains above 2,000 lines; this PR does not claim the final god-kill.

Related compressor shard PRs: #80626 #80628 #80634 #80636 #80644 #80645 #81074
Related collider/base-drift nodes: #6648 #12588 #25716 #29859 #72637 #74632
Referenced issue nodes: #12586 #72636 #56715 #56716 #56719

Reverse-link requirement: #81105, #78645, and #78647 must each reference PR #81181 and keep the campaign table current.

@andrexibiza

Copy link
Copy Markdown
Contributor Author

LB8 partial-run conjoin / supersession receipt.

The earlier selected-candidate thread (57570954260b) is preserved as historical evidence only. Its 6 APPROVE / 4 REQUEST_CHANGES result exposed a real reload and legacy-monkeypatch compatibility defect; it is not the accepted head.

Surviving implementation: PR #81181, fork head andrexibiza:gfg/cc-lb8-summary-repair, repair commit e40f2db1402cb629dedcff57e656dee439bb51c3.

The replacement passed parent verification and the post-repair 5×2×3 cross-check: 5/5 APPROVE. This comment conjoins the partial candidate posts to the repaired PR without deleting or rewriting the historical record.

The shard remains one step toward the 2,000-line law; no final god-kill is claimed.

@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 sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 7, 2026
@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 summary kernel and preserve compatibility

  1. The import-order-agnostic compatibility block is clever but fragileagent/context_compressor_summary_kernel.py (~L3237-3250): _SUMMARY_KERNEL_COMPATIBILITY_NAMES + globals().get("ContextCompressorSummaryKernelMixin") exist so either module can be imported first. The globals().get(...) guard means the module's effective identity depends on import history: if context_compressor bound the mixin earlier and summary_kernel is then imported, the guard can leave a stale/partially-bound state. A comment documenting the intended import order (leaf-first) plus a cycle-free import test (both orders, as the message-helpers seam does) would pin this.
  2. _strip_summary_prefix truncation at _SUMMARY_END_MARKER is subtle and now lives in a leaf (~L3285-3288): for forced user-leading merged summaries the marker is not the final content (live tail follows), and truncating there is intentional — the stale tail must not leak into the next summarizer prompt. This is exactly the kind of nuance that drifts during mechanical extraction; ensure the seam tests cover the merged-summary-with-live-tail case explicitly (not just standalone summaries).
  3. Mechanical extraction with no byte-level verification — the docstring says the ten methods were moved "mechanically". Unlike sibling refactor(context_compressor): extract message marker helpers #81243, no identity/equality check pins that the moved code is unchanged; the seam tests assert function-object identity across re-exports, which is good — add a behavioral-equivalence spot check (e.g. classify_summary_content on standalone/merged/none inputs) if not already present.
  4. The re-export surface (11 compatibility names including SUMMARY_PREFIX, HISTORICAL_TASK_HEADING, TODO_INJECTION_HEADER) is preserved on context_compressor — external importers keep working.

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 sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants