diff --git a/server/src/session/claude.rs b/server/src/session/claude.rs index 79d89f5..ba4279c 100644 --- a/server/src/session/claude.rs +++ b/server/src/session/claude.rs @@ -192,14 +192,19 @@ const STDERR_LOG: &str = "stderr.log"; /// they left behind, one ordinary request ("can you make it so you can /// rename a session?") cost 4.2 million tokens across its 130 calls. /// -/// 100k is the smallest window the CLI accepts and roughly the cheapest: -/// per-call cost falls with the cap, while the compaction it forces costs -/// about the same in total either way -- a smaller window compacts more -/// often but each pass is proportionally smaller. What it trades is how -/// much detail survives a compaction, which is a real cost to the work -/// and the reason this is one named constant rather than a computed -/// value. Raise it if sessions start losing the thread. -const AUTOCOMPACT_WINDOW: &str = "100k"; +/// 200k rather than the 100k floor, because the cheapest window on tokens +/// is not the best one to sit in front of. Measured on the same session: +/// context comes back to 70-85k within ten calls of a compaction, so a +/// 100k window compacts about every thirteen calls, and a compaction +/// takes roughly two minutes (`durationMs` 104,346 to 147,671 across the +/// six recorded). A 130-call request would spend some twenty minutes +/// compacting. 200k keeps most of the saving against the 1M ceiling and +/// halves the stalls. +/// +/// Worth knowing before tuning this: the window decides how often the +/// context is thrown away, not how fast it fills. What fills it is ~7k +/// per call of tool output, and no value here touches that. +const AUTOCOMPACT_WINDOW: &str = "200k"; /// How often a reader with nothing to read looks again. ///