Skip to content

refactor(context_compressor): extract message marker helpers - #81243

Open
andrexibiza wants to merge 1 commit into
NousResearch:mainfrom
andrexibiza:refactor/context-compressor-message-marker-helpers
Open

refactor(context_compressor): extract message marker helpers#81243
andrexibiza wants to merge 1 commit into
NousResearch:mainfrom
andrexibiza:refactor/context-compressor-message-marker-helpers

Conversation

@andrexibiza

@andrexibiza andrexibiza commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Extract the three message-marker helpers and _DB_PERSISTED_MARKER from agent/context_compressor.py into the leaf module agent/context_compressor_message_helpers.py.

The original module re-exports every moved name, preserving import compatibility and the established monkeypatch surface used by ContextCompressor.compress().

Exact scope

  • Feature Package pin: f15a38ee73631b3cd5f7d30765c37d5f0245d403
  • Original window: agent/context_compressor.py:173-237
  • Moved bytes: 3,204
  • SHA-256: 8c6860876e9a511927f9eecffce5bb878179d590218df284edd48c3cf3adc31d
  • Moved names:
  • _fresh_compaction_message_copy
  • _template_visible_role
  • _strip_persistence_markers
  • _DB_PERSISTED_MARKER

The complete owner file remained byte-identical from the Feature Package pin through rebased base df7e17841959d08254d923869a1060005680d4a2, so the approved seam did not drift.

Compatibility and behavior

  • agent.context_compressor still exposes the three helpers and marker constant.
  • Re-exported helper objects are identical to the leaf-module definitions.
  • Runtime tests prove a monkeypatch applied to agent.context_compressor._fresh_compaction_message_copy controls the real ContextCompressor.compress() path.
  • Fresh outer-message copies, nested-data identity, role-template behavior, and persistence-marker stripping are preserved.
  • AST checks reject duplicate definitions in the original module.
  • The leaf module has no import edge back to agent.context_compressor.

Verification

Post-rebase at commit 95900a9fc4752232358c578869e753cd08b5d785:

  • focused compressor/seam battery: 180 passed
  • Ruff check: passed
  • Ruff format check: passed
  • git diff --check: passed
  • clean-pin application checks: all five independent lane patches applied
  • exact moved-byte and AST ownership receipt: passed

The five-lane implementation wave produced four exact-byte clean extractions. Two independent lanes converged on the accepted leaf-module name; one divergent implementation failed the Golden-SHA gate and was excluded. Stronger compatible assertions from the lane set were consolidated into the committed seam suite.

Feature Package status

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

Part of #78645

Part of #78647

🔒 : #78645 · indexed by the All Gods tracker #78647.

Related interlock closure

Every listed node is preserved for coordination; this PR does not duplicate their extracted windows.

@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 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 message marker helpers

  1. The byte-hash assertions are a change-detector testtests/agent/test_context_compressor_message_helpers_seam.py test_leaf_source_is_cycle_free_exact_move_and_only_definition_owner (~L218-251): len(approved) == EXPECTED_BYTES and sha256(...) == EXPECTED_SHA256 over the raw source bytes of the extracted functions. Any docstring edit, comment tweak, or whitespace change in context_compressor_message_helpers.py breaks CI for zero behavioral reason — exactly the source-reading / change-detector pattern the repo's AGENTS.md bans ("Never read source code in tests", "Don't write change-detector tests"). Recommend dropping the byte-length/SHA assertions and keeping the identity, behavior, and patch-authority checks, which already fully cover the seam.
  2. helper_bytes.index(b"def _fresh_compaction_message_copy") (~L249) is position-based slicing of the file — if a docstring or comment above that def ever contains the same byte sequence, the slice starts early and the hash trivially fails. ast-based function-range extraction (already used elsewhere in the same test for the cycle-free check) would be robust — or simply drop the byte checks per point 1.
  3. The rest of the extraction is exemplary — identity re-export checks in both directions, import-order cycle-freeness in fresh interpreters, patch-authority preservation on agent.context_compressor, a parametrized _template_visible_role contract test, and a compress() integration test with a leaking-copy mock proving the terminal sweep invariant.

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