feat: --target-reduction-ratio is a real target (audit H4, deferred half) - #16
Merged
Conversation
Closes audit H4's deferred half. `--target-reduction-ratio` was an on/off switch: the planner read it as `> 0` to pick knapsack mode and nothing else read it, so `0.01` and `0.99` produced byte-identical output. Full reasoning in DECISIONS §48. Two things were broken, not one. It never REACHED the machinery — `pruning:topology-pruner` gated on `maxInputTokens` and bypassed itself entirely when only a ratio was set, which is why every ratio-only run's trace says "maxInputTokens not specified in budget; topology pruning bypassed". And it never STOPPED — compression ran to exhaustion, producing 44.62% and later 69.09% for every target on the same file. Overshooting is not a bonus: each extra elision spends fidelity, raises drift, and is irreversible on the CLI. `resolveTokenCeiling` (src/core/budget/) reads the ratio as a statement about the input — "remove 30%" is "keep at most 70%" — and resolves it against the incoming bundle. Once absolute it is an ordinary token ceiling, which the pruner and the knapsack already solve against, so no new selection machinery was needed. Both ceilings are caps, so the tighter wins. Granularity is where this got interesting, and both steps were found by measuring rather than reasoning. The stop rule was first written between items and did nothing on the commonest CLI shape: `optimize one-file.ts` is a single-item bundle, so the check runs once before anything is elided and the item then loses all its regions at once — 0.1, 0.3, 0.5 and 0.7 all produced 69.09%. A ceiling has to bind at the granularity the compression happens at. Then region ORDER mattered: positional order still overshot (0.1 through 0.5 all produced 55.2%) because regions are extremely uneven — measured at 58%, 61% and 83% of the file across three of this repo's sources, with the dominant one first. Selection is now smallest-first when a ceiling is set, re-sorted into positional order before splicing because `elideRegions` walks a forward cursor. What it achieves, as a distribution rather than a claim. Frozen corpus, target 30%, 66 reducing files: 21 land in 25-35%, 13 in 35-50%, 23 still exceed 50%, 9 under 25%. So the flag binds — it is no longer a switch — but adherence is partial and the limit is structural: elision's smallest unit is one region. Sub-region elision is what closes that and is not attempted here. The test pins this as a documented limit and deliberately does not assert `achieved <= target`. The corpus aggregate FELL and that is the feature. The harness measures at ratio 0.3, so runs that used to overshoot now stop near 30%: python file 23.14% -> 20.26%, typescript file 23.03% -> 17.57% — while fallbacks fell (python 14 -> 13) and reduced counts rose, because less aggressive elision survives validation more often. Third time in this project a headline aggregate moved for a non-regression reason (§45 line endings, §46 corpus growth, this). Also in this commit, because a new session will read these first: - ROADMAP renumbered. Its "v1.2.0 — Context Selection Quality" collided with the shipped remediation release; feature releases are now v1.3.0/v1.4.0/v1.5.0. - ROADMAP records that BOTH of v1.3.0's headline deliverables fail their preconditions, measured today: BM25 has no query source anywhere in `src/`, and MMR found 0 of 1,486 real pairs above its 0.90 eject threshold (max 0.296 and 0.500). The similarity instrument was validated first. Built as specified both would be ~1,000 LOC with no observable effect — the H5 condition again. - CLAUDE.md gains a "Where the project actually is" section with that disposition and the alternatives whose preconditions do hold. Suite: 614 passing, typecheck and lint clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Closes audit H4's deferred half. Full reasoning in DECISIONS §48.
--target-reduction-ratiowas an on/off switch: the planner read it as> 0to pick knapsack mode, nothing else read it, so0.01and0.99produced byte-identical output.Two things were broken, not one
pruning:topology-prunergated onmaxInputTokensand bypassed itself entirely when only a ratio was set — visible in every ratio-only trace as "maxInputTokens not specified in budget; topology pruning bypassed".resolveTokenCeilingreads the ratio as a statement about the input ("remove 30%" = "keep at most 70%") and resolves it against the bundle. Once absolute it's an ordinary token ceiling, which the pruner and knapsack already solve against. Both ceilings are caps, so the tighter wins.Granularity — both steps found by measuring
The stop rule was first written between items and did nothing on the commonest CLI shape:
optimize one-file.tsis a single-item bundle, so it checks once before anything is elided and the item then loses every region at once — 0.1, 0.3, 0.5, 0.7 all gave 69.09%. A ceiling must bind where the compression happens.Then region order mattered. Positional order still overshot (0.1–0.5 all gave 55.2%) because regions are extremely uneven:
core/planner/index.tscore/engine/index.tscore/validation/index.tsEvery file has one dominant region and it comes first positionally. Selection is now smallest-first when a ceiling is set, re-sorted into positional order before splicing (
elideRegionswalks a forward cursor).What it achieves — a distribution, not a claim
Frozen corpus, target 30%, 66 reducing files:
The flag binds — it is no longer a switch — but adherence is partial and the limit is structural: elision's smallest unit is one region. Sub-region elision closes it; not attempted here. The test pins this as a documented limit and deliberately does not assert
achieved <= target.⚠ The corpus aggregate fell, and that is the feature
The harness measures at ratio 0.3, so runs that used to overshoot now stop near 30%:
Each contributing file contributes less, and more files survive validation because less aggressive elision means less drift. Third time in this project a headline aggregate moved for a non-regression reason (§45 line endings, §46 corpus growth, this).
Roadmap and CLAUDE.md — written for a fresh session
src/, and MMR found 0 of 1,486 real pairs above its 0.90 threshold (maxima 0.296 and 0.500; the similarity instrument was validated first — identical 1.000, one-line edit 0.998, disjoint prose 0.000). Built as specified, both would be ~1,000 LOC with no observable effect — the H5 condition again.Verification
614 tests passing, typecheck and lint clean. The two behavioural tests fail against the pre-change engine (byte-identical output for different ratios) and pass now.
🤖 Generated with Claude Code