Repository navigation
fix(agent-status): stop reconnect replay re-arming a stale working row (STA-4144) - #14610
brennanb2025 wants to merge 1 commit into
Conversation
…w (STA-4144) A reconnect replay re-delivers a status this client already holds, but applyNormalizedStatus stamped it receivedAt = now while attachStatusTiming kept the cached stateStartedAt. A pane whose Stop was lost (sleep, app restart, relay drop) therefore came back "working" with a fresh freshness clock and an hours-old displayed age, and every reconnect re-armed it — so the 30-minute stale-decay safety net could never fire. Preserve the cached receivedAt when a replay carries the same state. A replay carrying a NEW state is real news (it can be the completion this client missed) and keeps live timing. Refs STA-3532, STA-3522 (duplicates), STA-3524.
|
Warning Review limit reached
Next review available in: 24 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing this. The mechanism it describes is real — I re-verified that a same-state relay replay still re-arms It cannot execute on the reported pane
The pane in the STA-4144 screenshot is a local worktree — its card carries no host chip, and the transcript references a locally-installed toolchain. So this change is inert on the pane it was written for. What the evidence actually showsThe pane footer reads The Two measured regressionsBoth are probes against a real F1 — an actively working remote agent decays to That trades a false-positive spinner on a finished agent for a false-negative F2 — a new Command Code turn is back-dated. The preserved value is passed as
The better fix is the one this PR already identifiedUnder "Known remaining gap": carry the host's original observation time on the replay envelope, as an additive optional field. That answers the question the staleness gate is actually asking — how old is this evidence — and fixes F1 by construction. Better still, STA-4612's liveness join makes the whole class unrepresentable rather than reconciling timestamps after the fact. Tracking it there. Relationship to #14635Checked by cherry-pick rather than by reading bodies: #14635 rebases cleanly onto STA-4144 stays openClosing this PR does not fix the reported bug. The evidence is being re-homed onto STA-4119, with the durable fix in STA-4612. Leaving the branch in place. |
ELI5
When Orca reconnects to an agent host, the host re-sends ("replays") the last status it had for each pane. Orca was treating that re-send as if it were brand-new news that just happened. So a pane that had finished long ago came back looking busy again, and the "it's been quiet for 30 minutes, stop the spinner" safety net kept getting reset. Every reconnect restarted the clock, so the spinner never stopped.
What Changed
In
applyNormalizedStatus, a replayed event that carries the same state we already have cached now keeps the cachedreceivedAtinstead of being stamped with the current time.A replay carrying a new state still gets live timing — that path is how a client learns about a completion it missed while disconnected, so it must stay fresh.
One-line behavioral diff; 10 lines with the comment.
Why
attachStatusTimingdeliberately preservesstateStartedAtwhen the state is unchanged, but unconditionally setsreceivedAt = now:receivedAtbecomes the renderer'supdatedAt(useIpcEvents.ts→setAgentStatus), which is the only input to the staleness gate:Stale
workingrows are supposed to decay toidleinworktree-agent-rows.ts:236. That decay is the only recovery when a terminating hook is lost — and a lostStopis exactly what a sleep, an app restart, or a relay drop produces.So the failure is: turn ends while disconnected →
Stopnever arrives → row frozen atworking→ reconnect replays the cachedworking→receivedAtjumps to now,stateStartedAtstays put → row is "fresh working" again, showing an hours-old age → decay can never fire, and every subsequent reconnect re-arms it.That reproduces the reported artifact exactly: an amber spinner with tool detail (
Bash: pnpm run typecheck…, which only renders whenstate === 'working') next to an age of6h.isReplayalready rides the envelope throughingestRemoteand was consulted for interrupt-suppression andclaudeRunningNonAgentTask, but never for timing.Which reconnects hit this
The replay must land while the cached entry still exists, so
stateStartedAtsurvives:wsl-hook-relay-manager.ts:295requests a replay on every (re)connect and never clears cached statuses first (noclearStatusEntriesForConnectionin that manager at all).relay.ts→replayCachedPayloadsForPanes()replays while the client session stays up, so the client never tore down.The local
setListenerreplay (server.ts:640) was already safe: it re-emits enriched payloads with their originalreceivedAt.Linked Issue
Linear STA-4144 — "Claude code stuck in loading after work completes" (Urgent, In Progress).
Duplicates: STA-3532, STA-3522 (both Urgent, screenshot-only reports of the same symptom).
Related: STA-3524 (reconnect replays are not idempotent — same root, notification-side symptom).
No GitHub issue exists for this one; it came in via Slack.
Fixes #
Visual Proof
Not captured — stating this plainly rather than approximating it. The stuck state needs a lost
Stopplus a relay reconnect, which I could not stage live inside this worktree without disrupting the running desktop session.The "before" artifact is the reporter's screenshot on STA-4144: sidebar row
Fix issues - Bash: pnpm run typecheck > /tm…showing the amber working spinner at age 6h, while the pane's TUI is plainly idle (❯prompt, recap printed). That combination is only reachable with a freshupdatedAtand an oldstateStartedAt, which is the state this PR makes unreachable for replays.The behavior is pinned by a deterministic test on real state transitions instead (below).
Testing
New:
src/main/agent-hooks/reconnect-replay-status-freshness.test.ts— drives the realAgentHookServerthroughingestRemote(no mocking of the logic under test) and asserts on the real cached row viagetStatusSnapshot(), gated by the sharedisFreshNonDoneAgentStatuspredicate the UI actually uses.Red/green oracle — with the fix reverted, case 1 fails on the real symptom:
i.e. the replay pushed
updatedAtforward 31 minutes. The other two cases pass without the fix (they assert preserved behavior, so they are guards, not filler):workingpast the stale window stays stale → decays to idle (fails without the fix)donestill applies with live timing — the missed-completion pathworkingping still refreshes freshness, and still reportsstateStartedAtas the state's startScoped checks run (per instruction, no full typecheck):
vitest src/main/agent-hooks/→ 40 files, 615 passed, 4 skippedvitest src/relay/agent-hook-server.test.ts src/main/ssh/ssh-relay-session-agent-hooks.integration.test.ts→ 25 passedtsc --noEmit -p config/tsconfig.node.json --composite false→ cleanoxlint+oxfmt --checkon both changed files → cleanPlatforms: logic is platform-independent and sits in the shared ingest path. The two reconnect paths it fixes are WSL (Windows) and SSH/remote relay; exercised through the integration suites above, not on live Windows/SSH hosts.
Investigated and ruled out
Recorded so the next person doesn't re-walk these:
Bashleaving an unbalanced hook pair — disproved on real Claude Code 2.1.227 with a hook recorder:run_in_backgroundyieldsPreToolUse → PostToolUse0.11s apart, thenStop. Perfectly balanced, no late tool event.setListener; it preservesreceivedAt.done— real but separate: teardown atuseIpcEvents.tsclearsliveAgentStatusBurstQueuewithout draining, so adonesitting in the 33ms window is discarded on effect teardown. Narrow, and not the reported mechanism. Not touched here.Known remaining gap (not fixed here)
When a reconnect does clear first — the SSH path calls
clearStatusEntriesForConnectionon teardown — the replay recreates the row with bothreceivedAtandstateStartedAtset to now. The pane then shows a working spinner aged "now" for 30 minutes even if the agent finished long ago. Closing that needs the original observation time carried on the replay envelope (a new optional wire field, safe perdocs/reference/remote-wire-compatibility.md). Deliberately out of scope to keep this focused.Review
isReplay) that already crosses the wire.workingrows.Checklist
Author