agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

[Feature]: Compact idle orchestrators before their prompt cache expires

Open neversettle17-101 opened this issue 2 weeks ago • 0 comments

Problem

Compact idle sessions before their prompt cache expires. When a session with a large history goes quiet, its cache expires after about an hour. The next wake-up (a worker report, a PR nudge, ao send, an auto-resume) then re-writes the whole history to cache at the expensive rate. Orchestrators are hit hardest: they go idle between reports, carry hundreds of thousands of tokens, and always get woken again.


Agent-collected evidence

Collected 2026-11-18. Source checked against main at cb352b7. Cache lifetime read from local Claude Code transcripts.

What exists today:

  • Manual compaction in Chat mode: chat.Service.Compact → Controller.Compact. The Claude ACP driver advertises ChatCapabilityCompaction.
  • A size-based window: CLAUDE_CODE_AUTO_COMPACT_WINDOW (200k / 1m). Claude Code compacts once the context reaches that size.
  • Idle hibernation (chat/hibernate.go, IdleBeforeHibernate = 10m). Idle hibernation deliberately excludes orchestrators (ListChatHibernationCandidates filters kind <> 'orchestrator').

Nothing compacts a session because it has gone idle.

Cache lifetime: in 12,170 recent Claude Code responses on this machine, every cache write went to ephemeral_1h_input_tokens. None went to the 5-minute cache. An idle session's cache therefore expires about 60 minutes after its last request.

Rough cost for a 470k-token orchestrator that goes idle and is woken later (input-token equivalents: cache write ≈ 2×, cache read ≈ 0.1×, output ≈ 5×):

Cost
Cold wake today: re-write 470k to cache ~940k
Compact at ~50 min idle while warm: read 470k + ~10–20k summary output ~100–150k
Cold wake after compaction: re-write ~40k ~80k

This only pays off when the session is woken again after its cache expires. That is almost always true for orchestrators. For workers, many never wake again, and compacting mid-task loses code context.

Field evidence: the token audit linked from #8385 recorded orchestrator requests at 322k–343k tokens of context, and a worker resuming a 463k-token conversation with no compaction (#8398).

Related: #8385 (staggering), #8398 (history carried across task boundaries), #8397 (report retry limit).

neversettle17-101 avatar Nov 18 '26 18:11 neversettle17-101