Files
magpie/docs
yetone c9fb7c9a1f gateway: a Claude run its timer ended mid-reply is no longer kept idle, holding one of 6 places (#1667)
A resumed turn's 30-minute timer calls abort. Fired during a reply,
finish closed the run and removeRun took it out of b.idle, where it
wasn't yet. The reply's last event, already in the segment, still
reached the client whole, so ended was told ok and kept the closed run
with keepIdle, then re-armed its timer. That timer found it closed and
never took it out, so it held one of idleMost places until pushed out,
and the push-out shelved a session removeRun may already have deleted.
letGo's keepIdle had the same window.

keepIdle now reads r.closed under b.mu and refuses an ended run,
returning false; ended and letGo then return without re-arming the
timer or rewinding. finish sets closed before removeRun takes b.mu, so a
run is either refused here or kept and then taken out by removeRun.

Tests: TestClaudeRunEndedMidReplyIsNotKeptIdle fires the run's timer
(abort through removeRun) and then calls ended with a whole reply. On
the old code it fails: "a run its timer ended mid-reply is kept idle (1
runs), holding a slot of 6"; it passes with the fix. TestClaudeIdle*
kept closed runs only so abort did nothing; they now keep live runs, and
TestClaudeIdleReplacementKeepsItsKey sets the other run at old's key
directly, since keeping it there through keepIdle would end old.

Run: go test -race -run 'Claude|Subscription|Idle|LetGo|Rewind'
./internal/gateway (ok); the full suite is in the next commit's body.
Not tried with a real Claude Code: the window needs a 30-minute reply.
2026-10-12 03:28:16 +08:00
..