diff --git a/internal/sessions/call_cache.go b/internal/sessions/call_cache.go index 9f4727281..2a9abcf47 100644 --- a/internal/sessions/call_cache.go +++ b/internal/sessions/call_cache.go @@ -216,7 +216,6 @@ func pruneCalls(files []file) { } func keepCalls(path string, st *callFile) { - defer trimCallRevisions(time.Now()) if callRoot == "" { // what is kept is of this root: a Sessions parse that read a // rollout's calls along (callsRide) keeps them before any Requests @@ -250,6 +249,13 @@ func keepCalls(path string, st *callFile) { } callCache[path] = st callOrder = append(callOrder, path) + // A file kept with no revision window adds nothing to trim, and a + // usage build keeps one for each of the ~11k files a long history + // holds: trimming after each, a sort and a map under callsMu, had its + // readers waiting on each other for seconds of a build. + if st.revisionWeight() > 0 { + trimCallRevisions(time.Now()) + } } // wholeCallReaders read an agent's calls from one session file at a time, diff --git a/internal/sessions/call_continuation.go b/internal/sessions/call_continuation.go index c2f5f83d3..23033fb0b 100644 --- a/internal/sessions/call_continuation.go +++ b/internal/sessions/call_continuation.go @@ -17,7 +17,6 @@ type callContinuation struct { // keepCallContinuation is called with callsMu held. Published continuations // are immutable; prepareCalls clones them before applying another append. func keepCallContinuation(st *callFile) { - defer trimCallRevisions(time.Now()) if st.Agent != "codex" && st.Agent != "claude" && st.Agent != "claude-desktop" { return } @@ -54,6 +53,7 @@ func keepCallContinuation(st *callFile) { state.dirty = nil callContinuations[st.Path] = callContinuation{state, len(st.Calls)} callContinuationOrder = append(callContinuationOrder, st.Path) + trimCallRevisions(time.Now()) } func restoreCallContinuation(st *callFile) *callFile {