Skip to content

Commit 42ff7fd

Browse files
committed
docs(context-budget): record why the measurement lib is not adopted yet
A review asked this branch to source bin/fm-context-measure-lib.sh and delete its inline measure_context, since the lib's header names this branch and docs/scripts.md calls it the single owner. That was declined by standing decision. This records the refusal with its evidence so a later reader sees a reasoned decision rather than a finding that was quietly skipped. The adoption is not refused in principle; one owner is the agreed end state. A straight swap today would delete working behavior, in four ways, the fourth found by that review: the lib slurps where this streams, it has no compaction-boundary tally that genuine-reset detection depends on, it dedupes multi-block turns by requestId, and it does not drop synthetic zero-usage entries. That fourth difference makes the lib's own caller wrong rather than merely different. On a transcript of one 300,010-token turn followed by the synthetic zero-usage entry written when a turn ends abnormally, the lib returns 0 with exit status 0, so a caller reads it as a real measurement. bin/fm-session-pulse.sh then takes its under-threshold branch and removes the once-per-session handover-due marker, so an interrupted turn makes that session forget a handover was due. Reproduced end to end. That is a defect in the sibling hook, is not repaired here, and is tracked as fm-session-pulse-false-zero. The agreed end state is the reverse move: put this streaming implementation, with rule 3 and the compaction tally, into the lib and have both callers adopt it, under its own tests and review as fm-context-measure-lib-adoption.
1 parent acb99c3 commit 42ff7fd

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎docs/verification/context-budget.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,45 @@ If it ever does occur the failure mode is a notice at every turn end: noisy, har
457457
**Unproven:** whether the shared-key case that needed a writable notice record beside an unwritable block record arises naturally.
458458
It was produced deliberately with a read-only record file; no natural cause was found on this host.
459459

460+
## The inline measurement is kept on purpose, and the lib is behind it
461+
462+
A review of this branch asked it to source `bin/fm-context-measure-lib.sh` and delete the inline `measure_context`, on the grounds that the lib's own header names this branch and `docs/scripts.md` calls it the single owner of the turn-end measurement.
463+
464+
**That was declined by standing decision, twice, and this record exists so the refusal reads as reasoned rather than skipped.**
465+
The adoption is not refused in principle - one owner is the agreed end state - but a straight swap today would delete working behavior.
466+
Four ways the lib is behind this implementation, the fourth found by that same review:
467+
468+
| Behavior | This guard | `fm-context-measure-lib.sh` |
469+
| --- | --- | --- |
470+
| Memory over a huge transcript | One streaming pass, constant memory | Slurps with `jq -s` |
471+
| Compaction-boundary tally | Returned alongside the total, and `record_predates_a_compaction` needs it for genuine-reset detection | Absent, and cannot supply it |
472+
| Multi-block turns | Takes the last usage entry | Dedupes by `requestId` |
473+
| Rule 3, synthetic zero-usage entries | Dropped, so the last *positive* total is reported | **Not dropped** |
474+
475+
The fourth row is the one that matters most, because it makes the lib's own caller wrong rather than merely differing.
476+
One transcript of a 300,010-token turn followed by the synthetic zero-usage entry Claude Code writes when a turn ends abnormally:
477+
478+
```
479+
lib -> 0 (exit status 0, so a caller reads it as a real measurement)
480+
guard -> 300010
481+
```
482+
483+
The consequence is reachable in `bin/fm-session-pulse.sh`, which measures through the lib.
484+
A `0` is below its 250,000 threshold, so it takes the under-threshold branch and removes the once-per-session `state/.handover-due` marker.
485+
Reproduced end to end in a scratch primary home, one session, appending only the synthetic entry between turns:
486+
487+
```
488+
turn 1, 300010 tokens over the threshold -> state/.handover-due created
489+
turn 2, synthetic zero entry appended -> state/.handover-due WIPED
490+
```
491+
492+
So an interrupted or errored turn makes that session forget a handover was due.
493+
That is a defect in the sibling hook rather than in this guard, it is not repaired by this branch, and it is tracked as `fm-session-pulse-false-zero`.
494+
495+
Adopting the lib as it stands would import the same false zero into this guard, which is exactly what rule 3 exists to reject.
496+
The agreed end state is the reverse move: put this streaming implementation, with rule 3 and the compaction tally, into the lib and have both callers adopt it.
497+
That changes behavior for the other caller, so it carries its own tests and its own review, tracked as `fm-context-measure-lib-adoption`.
498+
460499
## Native knobs remain unusable
461500

462501
Neither `CLAUDE_CODE_MAX_CONTEXT_TOKENS` nor `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` can enforce this ceiling; the feasibility scout recorded the decompiled reason for each.

0 commit comments

Comments
 (0)