fix(context-assembly): kill 123 pre-existing mutation survivors in condensers.py (#228) - #299
Merged
Merged
Conversation
…ndensers.py (#228) A scoped mutmut run over core/context_assembly/condensers.py left 123 survivors outside the #196-changed condense_assembled_context: every non-wiring condenser (condense_code_block, condense_assistant_message, condense_memory_content, condense_timeline_event, condense_user_message, condense_entity_triples) plus the fence-splitting helpers. The file was also 391 lines (over the 300-line file cap) with two functions over the 40-line method cap, so the behaviour-preserving split came first: one file per condenser family (condense_text.py, condense_code.py, condense_structured.py, condense_dispatch.py, condense_stage.py) behind an unchanged condensers.py re-export facade. Verified against the pre-existing 36-test suite (plus the #196 pg_recall wiring tests) passing unmodified before any new test was added. Four new test files add exact-equality contract tests (boundary pairs, accounting ladders, literal rosters, exact routing) mirroring the split. Re-scoped mutation run: 383 mutants, 377 killed, 6 documented-equivalent survivors (three <=/< boundary ties resolving to an identical no-op truncation, two loop-index </<= ties provably unreachable, and the #196 priority 3->4 tie re-confirmed after the split) -- see docs/audits/condensers-mutation-run-2026-07-30.md. One genuine dead-code branch surfaced by the run (condense_assistant_message's trailing code-only fallback, every mutant of which survived) is deleted per SS9/12.1 rather than kept as speculative future-proofing; the unreachability proof moves to the use site and is pinned by two tests. A stale "late import" docstring claim about assemble_prompt (the import was already module-scope) is corrected in the same pass. Closes #228 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Yu6EnWspTfqHoGkExyS6u
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Issue #228 asked for the 125 pre-existing mutation survivors in
core/context_assembly/condensers.py— every function outside #196'scondense_assembled_context— to be killed by contract tests ordocumented as equivalent (§12.1: no third disposition).
The file was also 391 lines (over the 300-line §4.1 cap), with two
functions over the 40-line §4.2 cap (
condense_assistant_message63,condense_assembled_context66) — so the behaviour-preserving splitcame first, per the issue's own framing: "if the file also breaches §4
sizes, the behaviour-preserving split comes first (existing suite
passing unchanged is the proof), then the tests."
Split (behaviour-preserving)
condensers.py(391 lines) → one file per condenser family, plus a thinre-export facade so every existing import path (including the
mock.patch("...condensers.condense_assembled_context")target intests_py/core/test_pg_recall_assemble_context_condensation.py) keepsresolving unchanged:
condense_text.pycondense_user_message,condense_timeline_event+ sentence helperscondense_code.pycondense_code_block,condense_assistant_message+ fence helperscondense_structured.pycondense_entity_triplescondense_dispatch.pycondense_memory_content(shape/tag dispatch)condense_stage.pycondense_assembled_context(#196 wiring)condensers.pyProof of zero behaviour change: the pre-existing 36-test
test_condensers.py+ the 3-testpg_recallwiring suite (39 tests, 216across the whole
context_assemblytest directory) pass unmodifiedagainst the split, verified before a single new test was written.
One dead-code branch surfaced by the mutation run is deleted, not kept
(§9/§12.1 — "every mutant of an unreachable branch survives... remove
it, don't test it"):
condense_assistant_message's trailingif prose_parts and prose_budget > 0: ...; return join(code_parts) # pragma: no coverfallback, every mutant of which survived. Thereachability proof moves to the use site in
condense_code.pyand ispinned by two tests (see ledger). A stale docstring claim about a "late
import" of
assemble_prompt(the import was already module-scope, notlate) is corrected in the same pass — a seen defect in touched material
(§14).
Mutation run
Full methodology, per-mutant verification (
mutmut show, not assertedfrom memory), and a reproducible 2nd run confirming the same 6 survivor
IDs:
docs/audits/condensers-mutation-run-2026-07-30.md.condense_assembled_context(#196's own function, already triaged to 0non-equivalent survivors) re-confirms at 0 after the split — no
regression.
Completion Ledger
Diff is
git diff origin/main...HEAD. No new production branches areintroduced (this is a behaviour-preserving split + one dead-code
deletion); every pre-existing branch that had a test in
test_condensers.pynow additionally has an exact-equality mutation-hardening test in the file
mirroring its new module.
condense_user_messageboundary (<=fast path, mid-question keep, tighter-budget rebuild)test_condense_text.py::test_user_message_at_exact_budget_is_returned_verbatim,::test_user_message_keeps_every_middle_question_in_order,::test_user_message_result_at_exact_budget_is_not_truncated,::test_user_message_truncates_the_rejoined_result_when_over_budgetcondense_user_message2-sentence fallback (len(sentences) <= 2)test_condense_text.py::test_two_sentence_message_truncates_the_original_not_the_rejoincondense_timeline_event3 date-format arms + no-date + boundary + over-budgettest_condense_text.py::test_timeline_event_reads_the_bracketed_date_marker,::test_timeline_event_reads_an_iso_date,::test_timeline_event_reads_a_month_day_year_date,::test_timeline_event_at_exact_budget_is_returned_verbatim,::test_timeline_event_compressed_at_exact_budget_is_not_truncated,::test_timeline_event_truncates_the_compressed_form_not_the_raw_text_split_sentences/_first_sentencehelperstest_condense_text.py::test_first_sentence_returns_the_first_sentence_not_the_whole_text,::test_split_sentences_strips_and_drops_empty_partscondense_assistant_messagecode-only branch (code_tokens >= token_budget), boundary, oversized-block degradetest_condense_code.py::test_assistant_code_only_path_stops_at_the_budget_boundary,::test_assistant_code_equal_to_budget_takes_the_code_only_path,::test_assistant_message_at_exact_budget_is_returned_verbatimcondense_assistant_messageprose-interleave branch + floor + blank-fallbacktest_condense_code.py::test_assistant_interleaves_prose_and_code_in_original_order,::test_assistant_prose_share_scales_with_the_leftover_budget,::test_assistant_blank_only_content_falls_back_to_truncationtest_condense_code.py::test_assistant_unclosed_fence_is_a_single_code_segment,::test_split_by_code_blocks_segments_preserve_original_newlinescondense_code_blocksignature scan, boundary, prefix rostertest_condense_code.py::test_code_block_at_exact_budget_is_returned_verbatim,::test_code_block_keeps_every_declared_signature_prefix,::test_code_block_signature_accounting_stops_at_the_budget_boundary_has_code_blocks/_split_by_code_blockshelperstest_condense_code.py::test_has_code_blocks_indent_run_threshold_is_three,::test_has_code_blocks_detects_a_fencecondense_entity_triplesboundary + accountingtest_condense_structured.py::test_entity_triples_at_exact_budget_is_returned_verbatim,::test_entity_triples_stop_at_the_budget_boundarycondense_memory_contenttag-dispatch (code/file/timeline/event arms)test_condense_dispatch.py::test_code_tag_routes_to_the_code_block_condenser,::test_file_tag_routes_to_the_code_block_condenser,::test_timeline_tag_routes_to_the_timeline_condenser,::test_event_tag_routes_to_the_timeline_condensercondense_memory_contentshape-dispatch (arrows, speaker prefix, indent)test_condense_dispatch.py::test_two_unicode_arrows_reach_the_triple_threshold,::test_two_ascii_arrows_reach_the_triple_threshold,::test_assistant_prefixed_transcript_routes_to_the_assistant_condenser,::test_user_prefixed_transcript_naming_the_assistant_routes_to_assistant,::test_indent_runs_alone_route_to_the_assistant_condensercondense_memory_contentfast-path boundarytest_condense_dispatch.py::test_memory_content_at_exact_budget_is_returned_verbatimcondense_assembled_contextunder/over-budget split (unchanged)test_condensers.py(36 tests, unmodified)test_condensers.py+test_pg_recall_assemble_context_condensation.py(3 tests) import through the old pathmutmutscoped runPre-push gate output (quoted)
§4 sizes (AST, verbatim script from the task):
(0 findings across all 6 source files + 4 new test files.)
ruff:
doc claims + badges:
Targeted tests:
Full suite (post-rebase onto origin/main@2590922):
Conflict markers / JSON: none;
.bestpractices.jsonparses.Mutation (scoped,
pyproject.toml[tool.mutmut] patched thenrestored — no diff on
pyproject.tomlin this PR):Full per-file breakdown, per-mutant
mutmut showdiffs, and theindependent second-run reproduction:
docs/audits/condensers-mutation-run-2026-07-30.md.Boy-scout items fixed in this PR
condense_assistant_message's unreachablecode-only fallback), not kept as future-proofing.
assemble_promptcorrected(the import was already module-scope).
docs/module-inventory.md'score/context_assembly/file count,already stale by one file before this PR (said "9", measured "10"),
corrected to the current measured 15.
No unfixed, un-issued seen defects remain in touched material.
Closes #228
Co-Authored-By: Claude Opus 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_012Yu6EnWspTfqHoGkExyS6u