We Ran 37 Agent Sessions to Find the Real Compaction Sweet Spot

Phase 1 modelled the compaction sweet spot at 40k–65k. Then we measured it: 37 agent runs across 8 autocompaction ceilings on Gemini 3.8 Flash. Compacting at 50k costs more than never compacting at all.

Tiny pink-haired Milim sits calmly on a massive brass pipe flange in a vast cathedral-like steam manifold hall with morning light filtering through soaring arched windows.

Six days ago we published The Context Compaction Curve and modelled the compaction sweet spot at 40k–65k tokens. That number came from pricing arithmetic, not from a running agent. We said so at the time, and then we went and measured it.

We were wrong, and not by a little. We were wrong in the opposite direction.

Across 37 benchmark runs on Gemini 3.8 Flash, spanning eight autocompaction ceilings and 450+ controlled turns, the cheapest configuration in the whole sweep was the one with autocompaction switched off. On a 25-turn feature build, compacting at a 50,000-token ceiling billed $2.48. Never compacting billed $1.60. Being disciplined about context cost 55% more than being lazy about it.

The one-line version. Compaction is not a cleanup routine. It is a cache-invalidation event. It throws away a 90% prefix discount you were already getting for free, then charges you full price to re-read the files it just forgot. Never compact while your cache is warm.


What to change tomorrow morning

Before the receipts, here is the whole finding in the form you can act on:

The rest of this post is why each of those lines is true, and where the data is thinner than we would like. The full methodology, every arm's raw telemetry, and the power-law derivation live in the Phase 2 Methodology & Receipts Report.


The intuition trap

Gut feel says compact early. Every token in the window is processed on every turn, so an agent carrying 200,000 tokens should cost roughly four times as much as one carrying 50,000. When a session starts feeling heavy, the instinct is to trim it.

Modern KV prompt caching breaks that arithmetic completely.

Frontier providers bill input on two tiers: full-price fresh input, and heavily discounted reads of an already-cached prefix. On Gemini 3.8 Flash, fresh input is $0.75 per million tokens. A cached prefix read is $0.075 per million, a 90% discount.

In an active loop, nearly your entire conversation history is served from that cache. Here is Turn 20, with context grown to 180,000 tokens:

StateWhat gets billedTurn cost
Uncompacted, warm178k cached + 2k fresh$0.0149
Compacted at 50kSummary + 50k fresh write + re-reads$0.0465

The uncompacted turn costs less than a penny and a half. The compacted turn pays a triple tax:

  1. Summary burn. The harness calls the model to summarize history, generating output tokens at $3.75/M, the most expensive token you can buy.
  2. Prefix invalidation. The summary replaces the history, so the provider's cached KV prefix no longer matches. The next turn writes the whole prompt as fresh input at $0.75/M.
  3. Working-memory eviction. The summary drops exact line numbers, AST fragments, and test traces. The agent has to go back to disk.

Tax 3 is the one nobody prices in, and it is the one that compounds.


Never compact when warm

Scenario 2 ran all eight ceilings through an identical 30-turn workload (workloads/feature.md) with zero idle time between turns. Every turn fired back-to-back, cache warm throughout. This is the shape of a real afternoon of pair-programming with an agent.

ArmCeilingCompactionsTotal cost (30 turns)
A-50k50,000101$4.49
A-100k100,00011$2.70
A-150k150,0003$3.39
A-200k200,0001$2.27
A-272k272,0000$3.13
A-500k500,0000$2.59
A-1M1,048,5760$3.71
A-disabledoff0$2.54

A-50k compacted 101 times in 30 turns, an average of 3.37 compactions per turn. It was not managing context. It was stuck in a loop: edit code, exceed 50k, compact, lose the variable references it just wrote, re-read the file, exceed 50k, compact again.

The bill: $4.49 for A-50k against $2.27 for A-200k. Compacting aggressively "to save money" carried a 97.7% surcharge.

Total session cost by autocompaction ceilingGemini 3.8 Flash · one run per arm · 30-turn warm sweep, 25-turn cold-gap sweepTotal session cost by autocompaction ceilingGemini 3.8 Flash · one run per arm · 30-turn warm sweep, 25-turn cold-gap sweep$0$2$4$650k100k150k200k272k500k1MoffAutocompaction ceiling · total billed session cost (USD)Scenario 2 · warmScenario 4 · cold gaps
Figure 1: Total billed cost per arm, both sweeps. The 50k ceiling is worst or near-worst in both and is the only arm that thrashes (101 and 37 compactions). Above 150k the arms scatter within single-run noise. The penalty sits at the low end, not the high end. Exact figures are in the table above.

Scenario 4 repeated the sweep over a 25-turn build with deliberate cold spells: seven-minute idle gaps at turns 8 and 16, standing in for the meetings and coffee breaks that let a cache expire. A-50k took 37 compactions and billed $2.48. A-disabled billed $1.60. Same 55% penalty, different route to it.

Read the two tables together and the honest shape appears: the penalty lives at the low end, not the high end. Above roughly 150k the arms scatter within run-to-run noise, and 200k wins Scenario 2 only to lose Scenario 4. Below 100k every arm loses, in every scenario, by a lot. That asymmetry is the finding. Setting the ceiling high is a safe bet. Setting it low is a reliably expensive one.


The reacquisition multiplier

Why does compaction cost so much more than the summary itself? Because a summarized agent becomes a paranoid one.

Scenario 5 counted read, grep, and find calls in the three turns immediately after each compaction, against that arm's own baseline.

MetricA-50kA-200kA-disabled
Baseline reads per turn0.652.352.08
Post-compaction reads per turn3.221.67none
Reacquisition multiplier (Scenario 4)4.95× (peak 6.08×)0.71×1.00×
Reacquisition multiplier (Scenario 2)2.65× (peak 3.03×)0.33×1.00×
Planted-directive violations000
Final test suite100% pass100% pass100% pass

When compaction fired mid-derivation in Scenario 4, file inspection surged 4.95× over the next three turns, peaking at 6.08×.

Look at what survives a summary and what does not. Planted architectural directives, strict TypeScript and no any, were retained perfectly: zero violations across every arm in Scenarios 2, 4, and 6. Summaries are good at keeping rules. What they lose is fine-grained working memory: exact function signatures, export interfaces, mock payloads. The agent still knows the constraints and has forgotten the code.

So it re-reads. And because the summary already invalidated the prefix, every re-read byte arrives as fresh, full-price input. That is the tax: you pay to forget, then you pay again to remember, at ten times the rate you were paying to simply not forget.


The other direction: thinking gets more expensive

If uncompacted context preserves cache hits and avoids reacquisition storms, why not carry a million tokens forever?

There is a tax at the top end too. It is not an input-token tax. It is reasoning inflation.

Scenario 3 held the task fixed (workloads/refactor.md) and varied only the history the agent carried into it: four tiers (20k, 80k, 180k, 272k), three runs each, twelve runs total.

History tierMeasured context (L)Total output tokensTurn cost
20k (clean)60k – 112k467 – 776$0.063 – $0.109
80k (moderate)56k – 82k292 – 1,123$0.084 – $0.111
180k (heavy)152k – 171k1,337 – 1,549$0.334 – $0.444
272k (bloated)146k – 255k1,739 – 2,335$0.427 – $0.661

Identical task. Same model. Ten times the cost per turn at the bloated end.

Reasoning tokens vs context lengthScenario 3 · 12 runs, identical refactor task · log-log axes · fit exponent β = 1.49Reasoning tokens vs context lengthScenario 3 · 12 runs, identical refactor task · log-log axes · fit exponent β = 1.49101001,00050k100k200k300kMeasured context length (L)Reasoning tokens (T)Double the context, roughly 2.8× the thinking
Figure 2: Every dot is one of the 12 measured Scenario 3 runs; the line is the fitted power law. Run-to-run spread is wide at any fixed context length, so the exponent describes the trend rather than any single turn. Full per-run receipts are in the Phase 2 Methodology & Receipts Report.

Fitting reasoning tokens against context length gives a power law with an exponent of β ≈ 1.49, which is super-linear. In plain terms: double your context and the model thinks roughly 2.8× as hard to get through it, whether or not the extra context is relevant.

The mechanism is mundane. Reasoning models read their own prefix while they search, so stale terminal logs, superseded compiler errors, and abandoned diffs all widen that search. At the 272k tier, total output averaged 2,075 tokens per turn, quadruple a clean 20k context, pushing single turns to $0.66.

The full fit, the per-run receipts, and the derivation live in the Phase 2 Methodology & Receipts Report. They are not repeated here.


Fifty turns without compacting once

Does the reasoning tax eventually break long-context execution outright? Scenario 6 pushed one arm, A-disabled, through a 50-turn feature lifecycle (workloads/endurance.md): a priority queue with backpressure, a concurrency-limited worker pool with graceful drain, a dead-letter queue with exponential backoff, REST routing with payload validation, a DAG scheduler, a Prometheus metrics collector, then a full refactor with strict JSDoc and vitest suites.

Session 01a097fd ran from Turn 1 to Turn 50 with the compactor off:

Zero hallucinations, zero instruction drift, zero degradation across the run. Per-turn cost rose smoothly from $0.013 on Turn 1 to $1.255 on Turn 50. The reasoning tax is real and visible, and it never became a correctness problem.

Now compare the two ends of the sweep. A-50k spent $4.49 on 30 turns while thrashing through 101 compactions. A-disabled spent $4.77 on 50 turns and shipped a working queue engine with a green test suite. Nearly the same money; 67% more work done.


What this costs on the model you actually use

We benchmarked Gemini 3.8 Flash because it is cheap enough to run 37 sessions without a budget conversation. You are probably not running Gemini 3.8 Flash.

So here is the same result priced onto four frontier models. The method is deliberately narrow. Take the measured token counts from Scenario 4, which are 2.41M fresh input / 4.56M cache reads / 87k output for A-50k and 0.94M / 8.80M / 62k for A-disabled, then re-price those exact counts at each model's public rate card. Nothing about the agent's behaviour is modelled. Only the invoice changes. Rates come from the LiteLLM catalog fetched 2026-09-13, and the method reproduces the Gemini receipts to the cent.

ModelCompacting at 50kNever compactingYou losePenalty
Gemini 3.8 Flash (measured)$2.48$1.60$0.88+55%
GPT-5.6 Sol$13.22$8.52$4.70+55%
Claude Opus 5$16.53$10.65$5.87+55%
Claude Fable 5.1$29.63$14.71$14.92+101%
GPT-6 Astra$33.05$21.31$11.74+55%

That is one 25-turn feature build. Run four a day across 21 working days and the compaction tax reaches $395/month on Sol, $493 on Opus 5, $986 on Astra, and $1,253 on Fable 5.1, per developer. Pick your own volume. The per-build number is the one we measured.

The same build, priced on four frontier models25-turn feature build · compacting at 50k vs never compactingThe same build, priced on four frontier models25-turn feature build · compacting at 50k vs never compacting$0$10$20$30Gemini Flash+$0.88+55%GPT-5.6 Sol+$4.70+55%Opus 5+$5.87+55%Fable 5.1+$14.92+101%GPT-6 Astra+$11.74+55%Compacting at 50kNever compactingRe-priced from measured tokens · not measured on these models
Figure 3: Scenario 4’s measured token counts re-priced at each model’s public rate (LiteLLM catalog, 2026-09-13). Only Gemini 3.8 Flash was actually run; the other four assume identical agent behaviour and are a re-pricing, not a prediction. Cache-write charges are excluded, which understates every penalty shown.

Why four of the five land on exactly +55%

That is not a rounding coincidence, and it is the most portable thing in this post. The penalty percentage is governed by a single number on the rate card: the ratio of cache-read price to fresh-input price.

Gemini, Sol, Opus 5, and Astra all discount cache reads 10:1, so they all pay the same 55% surcharge for compacting at 50k. Fable 5.1 discounts them 40:1, at $0.25 per million read against $10.00 fresh, and its penalty doubles to +101%.

The conclusion runs against instinct and is worth saying slowly: the better your provider's cache deal, the more compaction costs you. A deep cache discount is not insurance against a bloated context. It is precisely what makes throwing that context away expensive, because it widens the gap between the token you were paying for and the token you replaced it with.

If your provider ever announces a deeper cache discount, your autocompaction threshold should go up, not down.

Two honest caveats

We did not run these models. Token counts are behavioural, and a different model will read a different number of files after a compaction, think for a different number of tokens, and possibly compact a different number of times. Treat the table as "what the invoice would have said if this model behaved exactly like the one we measured". It is a re-pricing, not a prediction. The mechanism should hold anywhere there is a discounted prefix cache. The exact dollars will not.

These figures understate the penalty. Gemini's rate card has no separate cache-write price, so our measured receipts carry no cache-write column and the re-pricing above omits it entirely. Every one of A-50k's 37 compactions forces a fresh prefix write, and on all four frontier cards a cache write costs 1.25× fresh input. Charging A-50k's 2.41M fresh input tokens at cache-write rates instead would push the penalty from +55% to roughly +83% on Sol, Opus 5, and Astra, and from +101% to +142% on Fable 5.1. The omitted cost falls almost entirely on the compacting arm, so every number in the table is a floor.


Where this is thin

Three limits worth stating plainly, because they bound how far you should carry this:


The new rule of thumb

If you build harnesses

  1. Raise the autocompaction floor. A 50k default is an anti-pattern on models with 200k+ native windows. Start at 150k–200k.
  2. Gate compaction on cache warmth, not token count alone. Check the time since the last turn. If the prefix is warm, defer. Compacting into a warm cache is strictly value-destroying.
  3. Pin the working set across compaction. If you must compact, carry open file buffers and recent symbols through verbatim instead of narrating them into prose. That is where the 4.95× comes from.
  4. Prefer explicit handoffs to reactive autocompaction. At a phase boundary, write a /handoff brief and start clean. An autocompactor firing mid-step is the worst of both.

The headline is small enough to keep in your head: compaction is a cache event, not a hygiene routine. Pay it when the cache is already cold. Never pay it when it's warm.


Want to check our arithmetic? The Phase 2 Methodology & Receipts Report carries the full protocol, every one of the 37 run receipts, per-turn telemetry for all eight arms, and the power-law derivation behind β = 1.49. It is written for readers who would rather verify the numbers than take them.


Sources