Repository navigation
Description
summarize's fill threshold is a fraction of the model's context window (default 0.9). But what makes compacting useful is getting ahead of the expensive cold rewrites below the client's own compaction point — and that point is not a fixed fraction of the window.
The two populations
Measured on production traffic, client-side compaction happens at two very different fills:
| Population | Client compacts at | As a fraction of its window |
|---|---|---|
| 200k models | median 167,425 (n = 8 tenants) | ≈ 0.84 |
| 1M models | ~999,8xx | ≈ 1.00 |
The mechanism behind the difference is not established from our data — it is not a constant fraction and not a constant reserve, and this issue deliberately does not guess at it.
Why it matters: the default is unreachable on 200k models behind Claude Code
0.9 × 200,000 = 180,000, which is above the ~167,425 where Claude Code compacts. The client compacts first, so the transcript never reaches our threshold and this component never fires.
Observed directly: a real Claude Code session on claude-haiku-4-5 had to be run with min_request_frac: 0.5 to exercise the trigger at all (see #234's validation run). At the shipped default it would have been inert.
The arithmetic that says the default is nonetheless right
Applying "fire 10% of the window before the client compacts" to both populations:
| Model | Client compacts at | C − 0.10 × window |
As a fraction |
|---|---|---|---|
| 1M | ~999,800 | 899,800 | 0.90 |
| 200k | 167,425 | 147,425 | 0.74 |
On the 1M population, "10% before the native compact" is 0.9. So the shipped default is already correct for large-window deployments, and a learned threshold would only ever change behaviour on 200k models — where it is currently unreachable.
That yields the property this design should be built around:
A learned threshold may only LOWER the fill fraction from its configured default, never raise it.
So adopting it can never make the component fire later than it does today — only earlier. Earlier is the direction the threshold sweep showed gains in (near-linear from 0.6 to 0.95; roughly $320-500 recovered per 5-point step down, at $0.22-0.32 per extra turn spent on a compacted context). A bug in the learning can cost some over-compaction; it cannot cost the cold rewrites already being caught.
Where the value has to live: across sessions, not within one
Learning within a single session has a bootstrapping problem — the teacher is the event we wanted to prevent. You learn "this client compacts at 167k" by watching it compact at 167k, by which point that cycle's opportunity is gone. Within-session learning therefore helps from the second cycle onward, which is not worthless (long sessions cycle repeatedly: median 7 cold rewrites, max 46) but always misses a new session's first cycle.
The compaction point is a property of the client build and the model, not of the conversation — Claude Code does not choose a different threshold per session. So the value should be keyed on (agent, model) and persisted, which is the only way a new session gets its first cycle right.
Suggested shape:
- The measurement lives where the data already is: a client compaction is a drop in
tokens_beforebetween consecutive turns of a conversation, whichdash/overview.go'sCompactionResetsalready detects. The quantity wanted is the billed fill on the turn just before each drop. - The decision reads a cached per-
(agent, model)number on the request path, never a history query per turn. - Absent a learned value, the configured fraction applies unchanged. Absent both, the existing
window_not_exactdecline stands.
Ctx.PrevBilledInput (added in #234) is what makes the fill expressible in the provider's units on the request path, so this builds directly on that.
Guards
A tokens_before drop is not always a client compaction, and learning from an impostor is how this feature would go wrong:
/clear, a session-id collision, or a resumed conversation all look like a drop. Requiring the drop to land in a plausible band (roughly 30-95% of the prior fill) filters the obvious cases.- Require several observations before adopting — one drop is an anecdote.
- A recency window. A Claude Code upgrade changes the threshold, so a value learned months ago is a guess wearing a measurement's clothes. The same discipline the window provenance keeps: prefer declining to acting on something stale.
- A floor, so a pathological learned value cannot drive continuous compaction.
- Never raise the threshold, per the property above.
Not in #234
#234 ships the trigger, the async execution model and the episode measurement, and is already large. This wants #234's PrevBilledInput merged first, so it belongs on its own branch off main afterwards.
Raised by the repo owner while reviewing #234's validation run: "I think that the default should be 0.9 and if during a session u learned otherwise, u can adopt it as the session grows." This issue records why the cross-session half is the part that carries the value.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew/ToDo
Activity
fix(dash): derive the episode span from the fill threshold, as the at…
fix(dash): the span's far end is the CLIENT's compaction ceiling, not…
docs(dash): define the compaction point C, in the one ruler the gate …
test(scenarios): add arm D, an early-compacting client — the case the…
amiddavid commentedon Sep 15, 2026
Partially addressed by #234 — the three known models now carry a real ceiling; the learning mechanism this issue asks for does not exist. Recording the split so the issue is not read as untouched.
What landed
internal/compactionpointdefines C, the provider-billed input at which the conversation's own compaction mechanism acts, andTrigger.Firesnow resolvesmin_request_fracagainst C rather than the raw context window (Ctx.FillDenominator(), falling back toCtxWindowwhen C is unknown). So the default is no longer 0.9 of a number the client never reaches.The table, longest-match on the normalized model id:
Source(Measured / Assumed / WindowFallback) travels with the value, so a consumer can tell a fact from a default — the same measured/modelled disciplinedeclcredit.goenforces.What this issue still wants, and one correction to its premise
The mechanism is still a table. Nothing learns C from traffic, and #234 deliberately did not guess at the rule behind the two populations.
The measured haiku figure is 0.996, not the ≈0.84 this issue reports. Both are real numbers about different rulers, and conflating them is how the table would be set wrong:
tokens_before(schema.MessagesTokens)The
median 167,425in the table above is the client's own count, which excludes the system prompt, tool declarations and the JSON envelope. C must be stated in provider-billed tokens, because that is the rulerPrevBilledInputand the context window are both stated in — otherwise the fraction needs a conversion that runs a median 3.38x and cannot be applied per request.So the 200k population's C is ≈0.996, not ≈0.84, and the default of 0.9 is reachable there. The "unreachable on 200k models" section of this issue is wrong for that reason, not because the fill gate is fine — it was independently unreachable until #234, since
Firescompared the fraction againstMessagesTokens.Two dead ends, so they are not re-attempted
max_tokensdoes not yield C. A request'smax_tokensis the output budget. It looked like it might complete a window-minus-reserve identity on one data point; there is counter-evidence in the same capture (199,184 input + 32,000 max_tokens > 200,000 succeeded), and on the two models checkedmax_tokenswas 32,000 for both, so it cannot vary with C. Retracted.CONTEXT_GURU_CAPTURE) shows the body carrying onlymax_tokens, messages, metadata, model, output_config, system, temperature, thinking, tools, stream. Nocontext_management, and no field naming context/compact/limit/window/threshold. If the auto-compact threshold is user-settable, that setting does not reach the wire — so C cannot currently be observed from a request, only from therequests.bypassedtransition after the client has already compacted.Which leaves the four cases a learning implementation has to keep apart: the client compacts (C observable, once, after the fact), we ask the provider (#241, C chosen), nothing compacts (C = W, a fact), and unknown (C = W, a guess). Keeping the last two apart is the whole reason
Sourceexists.[-]summarize: learn the client's own compaction point instead of assuming a fixed fraction of the window[/-][+]summarize: learn the client compaction point per (agent, model) from traffic (the table exists, #234)[/+]amiddavid commentedon Nov 27, 2026
Narrowed and retitled.
compactionpointtable.Trigger.Firesnow usesCtx.FillDenominator(), with the source set to Measured, Assumed or WindowFallback.