Repository navigation
Conversation
…ter the run completes A follow-up still queued when a run completes is the thread's latest run, so the completed run's idle-compaction check ends without a timer. Removing or steering that queued message afterwards emitted only a cancelled update, which started nothing, so the thread never compacted before its cache expired. A cancelled update for a run that never started now starts the same check, which retargets the completed run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
With idle compaction set to "Before the cache expires (beta)", a Claude thread is never compacted when a follow-up message is still queued at the moment the run completes and is then removed or steered.
IdleCompactionServicestarts its check only onrun.updatedwith statuscompleted. At that moment the queued run has the highest ordinal, soidleCompactionWindowreturns null and the check ends without a timer. The removal that follows emitsrun.updatedwith statuscancelled, which starts nothing. The thread stays uncompacted, and the next message after the cache expires pays a full uncached read.#29904 fixed the order where the queued message is cancelled before the run completes. This is the opposite order.
Steps: on a Claude thread above the 200K floor, queue a follow-up while a turn runs, let the turn complete, then remove the queued message (or steer it) before it starts. Expected:
/compactis sent about 2 minutes before the cache expires. Actual: nothing is sent.Change
IdleCompactionService.startnow also startscompactWhenDueonrun.updatedwith statuscancelledandstartedAt === null. The check already ignores such runs when it picks the latest run, so its existing retarget branch takes over the completed run and waits for that run's window.A queued message that is still queued keeps blocking compaction, as #29904 intends. If the cancel arrives while the previous run is still running, the check finds no completed latest run and ends, and the later
completedevent arms the timer as before.Scope
A bug in idle compaction. Production code is +5 −1 in one file. There is no issue for it: I searched issues and pull requests for this order and found none, and the fix is one condition on an existing event filter.
Verification
macOS 27.0.1, Apple silicon, Node 26.12.1, on main d023407.
startedAtnull. No/compactwas dispatched in the next 104 minutes, and the next user message ran against an expired cache.IdleCompaction.test.ts, "compacts when a queued message is removed or steered after the run completes": the completed event is read while the follow-up is queued, then the queued run is cancelled without starting. On main the test fails withexpected [] to deeply equal ["server:idle-compact:idle-thread:run-1"]. With the change it passes, and the other 14 tests in the file still pass (15 of 15).vp run check:changedpasses (format, lint, knip, graphql, typecheck, tests).idleCompaction: "beforeCacheExpires", one realclaudeAgentturn (Haiku) with a follow-up queued behind it, and the follow-up cancelled throught3_queue0.07 seconds after the turn completed, before it started. The turn is below the 200K-token floor, so neither side sends/compact. The transcript shows whether the service looks at the thread again after the cancel: on main it does not, here it does. The unit test above covers the dispatch.Transcript (before: main d023407, after: this branch de58496)
Driver script (scratch, not committed)
transcript.sh:mcp.py:/compactdispatch on a thread above 200K tokens after an idle wait of about an hour (the unit test covers that path).Written by Claude Fable 5.2 in Claude Code, run in T3 Code.
🤖 Generated with Claude Code