Skip to the content.

Planned view measured over real session transcripts

Generated: 2026-06-23 · issue #559 · cmd/ctxplanbench · 5 heaviest sessions on this box, 715 replayed turns.

internal/ctxplan/scaling.go takes a mean tokens/turn and a forecast-hit rate and computes the resident-token curve. That is a model — useful for the asymptotic claim, but it is not a measurement. This note records the measurement: the planned view replayed turn-by-turn over the heaviest REAL Claude Code transcripts on this box, reporting the three quantities the issue names.

Companion: this note measures the planner’s output (resident tokens). Its sibling CTXPLAN-PLANNING-COST-FLATTEN measures the planner’s own per-turn work (the Θ(N²)→Θ(c·N) candidate-index flatten, #558), and the honest cost↔fidelity dial that the bounded probe trades on real sessions.

How (the honest construction)

Each transcript is ingested through the shipped cdb.IngestSessionrecall core image, so a result the write-time gate quarantines is sealed here too (8 of 723 pages on these sessions). Each recall.Page is bridged 1:1 into a ctxplan.Span; the session is replayed one benign span per turn through the real planner (ctxplan.Materialize) and the real page-fault handler (ctxplan.DemandPage). Nothing about the win is modeled:

The forecast is a deliberately cheap heuristic a deployment could actually run: the last 6 turn descriptors as intents (a recency window) + the durable spans pinned. It is not an oracle.

The numbers (budget W=8000 tokens, window K=6)

session (heaviest first) turns linear cum planned cum peak refs faults served faithful
0c073826… 217 25.82M 1.65M 8.2K 9558 2410 (25.2%) 2410 217/217
af549457… 359 20.58M 2.73M 8.0K 26286 8915 (33.9%) 8915 359/359
4d528918… 90 16.08M 657.6K 8.0K 1662 633 (38.1%) 633 90/90
a5d0581a… 32 7.21M 195.3K 10.2K† 467 125 (26.8%) 125 32/32
0227e3e1… 17 124.4K 11.8K 953 95 0 (0.0%) 0 17/17
aggregate 715 69.81M 5.24M 38068 12083 (31.7%) 12083 715/715

† peak exceeds W on a pin-overrun turn (durable pins alone exceed the budget — documented planner behavior: pins stay resident, OverBudget is set, reported not hidden).

What the numbers say

Honest fences

Reproduce

go run ./cmd/ctxplanbench -selfcheck                       # pipeline gate (exit 0)
go run ./cmd/ctxplanbench -heaviest 5 -budget 8000 -window 6
go run ./cmd/ctxplanbench -transcripts <path>.jsonl -out report.json

Witnesses: go test ./cmd/ctxplanbench (TestReplayInvariants, TestReplayLooseBudgetHoldsEverything).

Reproduction (2026-06-26, independent re-run)

go run ./cmd/ctxplanbench -heaviest 5 -budget 8000 -window 6 re-run on this box’s current heaviest-5 (the transcript set has grown since 2026-06-23, so these are different, longer sessions):

  turns linear cum planned cum multiplier faithful refs faults served refused compaction lost
aggregate 2055 158.13M 16.00M 9.9× fewer resident 2055/2055 353,646 196,271 (55.5%) 196,271 0 2016/2055

The regime reproduces exactly — 100% exact recall (2055/2055), 100% of misses served (0 refused, 0 lost), compaction destroying facts on 2016/2055 turns — at a different multiplier (9.9× here vs 13.3× on the original set), because these sessions are longer and the heuristic forecast misses more often (55.5% vs 31.7%). Every additional miss is still a served page fault, never a lost fact. The multiplier moves with the transcript set; the recall/served invariants do not. -selfcheck exits 0.