Repository navigation
fix: gate worktree status on live PTYs so sleep reports inactive - #1603
Merged
Merged
Conversation
Sleep preserves tab.ptyId as a wake-hint sessionId, so the previous liveness check (`tab.ptyId != null`) kept the workspace dot green and agent rows as "working" until the 30-min stale TTL decayed them. Switch liveness to ptyIdsByTabId (cleared by every pty.kill / sleep) via a new tabHasLivePty helper, and drop live agentStatusByPaneKey entries on sleep so the inline rows disappear with the dot. Retained "done" rows survive — that signal is dismissed by the user, not the system. Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
Contributor
Author
|
Electron validation update: I validated the main sleep-status renderer path in the Electron dev app via CDP. What passed:
Also ran:
Scope note: the Electron run covered the live renderer sleep transition. The pure row-derivation/orphan-retained cases are covered by unit tests; mobile/RPC and SSH-specific paths were not fully end-to-end exercised in that Electron run. |
Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
…atuses # Conflicts: # src/renderer/src/App.tsx
Co-authored-by: Orca <[email protected]>
5 tasks done
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…blyai#1603) * fix: gate worktree status on live PTYs so sleep reports inactive Sleep preserves tab.ptyId as a wake-hint sessionId, so the previous liveness check (`tab.ptyId != null`) kept the workspace dot green and agent rows as "working" until the 30-min stale TTL decayed them. Switch liveness to ptyIdsByTabId (cleared by every pty.kill / sleep) via a new tabHasLivePty helper, and drop live agentStatusByPaneKey entries on sleep so the inline rows disappear with the dot. Retained "done" rows survive — that signal is dismissed by the user, not the system. Co-authored-by: Orca <[email protected]> * fix: drop retained agent rows on worktree sleep Co-authored-by: Orca <[email protected]> * WIP: Changes before auto-review fixes Co-authored-by: Orca <[email protected]> * fix: preserve slept worktree status liveness Co-authored-by: Orca <[email protected]> * fix: treat slept pty hints as inactive Co-authored-by: Orca <[email protected]> * chore: remove sleep status planning docs Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After sleeping a worktree, the sidebar lied on three axes: the dot stayed green, in-flight
workingagent rows persisted until the 30-min stale TTL, and retaineddonerows kept rendering under a grey card after Phase 1 fixed the first two. Sleep preservestab.ptyIdas a wake-hint sessionId — not a liveness signal — so the previoustab.ptyId != nullchecks were wrong, and retained-done was preserved across sleep against the "agent lives in the pane" mental model.Phase 1 — status precondition + live-row drop (commit
b5fd86e6):ptyIdsByTabId[tab.id].length > 0) via a newtabHasLivePtyhelper, threaded throughgetWorktreeStatus,WorktreeCard,WorktreeJumpPalette, and both branches ofagent-status.ts(primary pane-titles + tab-title fallback).shutdownWorktreeTerminalsdrops liveagentStatusByPaneKeyentries unconditionally on sleep, soworking/blocked/waitingrows disappear with the dot.tab.ptyIdwas populated as a hint but no PTY was alive.Phase 2 — retained-done drop on sleep (commit
5b61ae64):donerows along with everything else — the prior grey-card-with-green-row mixed signal is gone. Reload, tab close, and worktree remove paths are unchanged.dropAgentStatusByWorktreeruns unconditionally from the sleep path, sweeping live + retained + ack for the worktree's tabs and any orphan retained rows whoseworktreeIdmatches.preserveRetainedoption fromdropAgentStatusByTabPrefix— sleep was its only caller.Design doc with full root-cause + UX matrix (Phase 1 + Phase 2 unified) lives at
docs/PLAN_SLEEP_STATUSES.md(untracked locally).Screenshots
No visual change to the happy path. Behavior change: the worktree dot transitions to grey within one render of sleeping a worktree, inline
workingrows disappear at the same time, and retaineddonerows are also dropped (Phase 2). The "Claude finished while you were away" UX continues to work for reload / unrelated worktree cases — only sleep folds it.Testing
pnpm lintpnpm typecheckpnpm testpnpm buildNew/extended tests:
tab-has-live-pty.test.ts(new) — direct unit tests for the helper.worktree-status.test.ts— slept-tab (tab.ptyIdset, no live PTY) →inactive; slept-with-retained-done → grey via the extractedresolveWorktreeStatuspure function.agent-status.test.ts—getWorkingAgentsPerWorktreeandcountWorkingAgentsForTabboth return 0 for a slept tab on (a) the primary pane-titles branch and (b) the tab-title fallback. Phase 2: regression test fordropAgentStatusByTabPrefixno longer accepting apreserveRetainedoption (live, retained, ack, suppressors all fold uniformly).store-cascades.test.ts— aftershutdownWorktreeTerminals(wt, { keepIdentifiers: true }):agentStatusByPaneKeyis cleared, retained-done is also cleared (Phase 2 inversion), ack entries are cleared, suppressors are planted for live keys. Hook-level assertions foruseWorktreeAgentRowscovering slept and slept-with-retained-done.sleep-worktree-flow.test.ts— end-to-end: retained-done rows for the slept worktree are gone afterrunSleepWorktreereturns.Manual end-to-end verification (real Electron dev build)
Spawned a fresh dev build via
run-electron-vite-dev.mjs --remote-debugging-port=9336, attached playwright-cli over CDP via a named session (to avoid cross-instance leaks across other dev builds on the same user-data-dir), and drove the live store. Created a throwaway test worktree, spawned its PTY, and exercised the scenarios below. Real hook events were posted toagentHookServerover its loopback port + token to seedlastStatusByPaneKey.Sleep clears the working agent row + greys the dot (Phase 1). Pre-sleep:
livePtys=[ptyId],agentEntry={state:'working'}. CalledshutdownWorktreeBrowsers+shutdownWorktreeTerminals(wt, { keepIdentifiers: true }). Post-sleep:livePtys=[],agentEntry=null,getWorktreeStatusinputs yield'inactive'(dot grey), working row gone.Done → sleep drops retained-done (Phase 2). Set
working→done(uninterrupted), waited foruseRetainedAgentsSyncto capture the live entry inprevAgentsRef, then removed the live entry to land a retaineddone. Pre-sleep: live PTY present,retainedEntry={state:'done', interrupted:false}. Post-sleep:livePtys=[],liveAgent=null,retainedAgent=null(Phase 2 drop), no suppressor leak.Acknowledged done → sleep drops retained + ack (Phase 2). Same setup as test 2 but called
acknowledgeAgents([paneKey])before the live drop. Pre-sleep:retainedEntrypresent,ackTimestampset. Post-sleep: retained dropped,ackTimestamp=null(acknowledgedAgentsByPaneKey ack entry cleaned up), no suppressor leak.WorktreeJumpPalettematches the sidebar (Phase 1). Opened the palette over the slept worktree. The option rendered asInactive sleep-status-e2e-..., agreeing with the sidebar's grey dot. Confirms the jump-palettegetWorktreeStatusplumbing — without it the palette would desync from the sidebar (showing the slept worktree as still active offtab.ptyId).Sleep + wake reactivates fresh; past
donedoes not resurrect. After test 3's sleep, calledsetActiveWorktree(wtId)to wake. Post-wake: freshptyIdon the tab,tab.generation=1,liveAgent=null,retainedAgent=null. The worktree reactivates empty as designed.Tests 7 and 8 from the design doc (renderer reload paths) require a full BrowserWindow recreation for the
agentHookServer.setListenerreplay loop to fire —location.reload()keeps the same BrowserWindow alive, so the replay (which only triggers onsetListener(fn)re-call) doesn't run. What was verified upstream: hook POSTs land in renderer state via the IPC bridge (solastStatusByPaneKey.setruns on every hook), andclearPaneState(paneKey)is invoked frompty.killteardown atsrc/main/ipc/pty.ts:349(so sleep's PTY teardown wipes the replay cache as the design doc claims). Full Cmd+Q+relaunch verification is not in this run.Remaining manual checks with real agent processes (mid-turn working sleep, Cmd+Q+relaunch reload paths, permission-state sleep, two-worktree isolation) are tracked in
docs/PR_1603_MANUAL_TEST_PLAN.mdfor follow-up before merge.Cleanup: throwaway worktree removed via
removeWorktree(id, true), dev build closed.AI Review Report
Reviewed with Claude. Risks checked:
ptyIdsByTabIdfrom the wake-hint sessionId at hydrate time (terminals.tsearly-population path), so reload behavior matches today — verified by test, by reading the hydrate path, and by the wake-cycle observed in manual test 5.lastStatusByPaneKeyreplay survives renderer-only reloads (wheresetListeneris not re-called) and is cleared on PTY teardown — both pre-existing behaviors. The PR only changes what sleep does to the renderer-side maps.tabs.ts:1289: kept the|| tab.ptyId != nullclause and added a comment — this is a one-shot migration include, not a liveness check, and reconcile fires again post-reattach.suppressedPtyExitIds(renderer ignore-list for PTY exit events) andretentionSuppressedPaneKeys(retention-side ignore-list) are distinct and unaffected by the unconditional drop. Phase 2's same-frame race (hook ping promotesworking→donein the same frame as sleep) is guarded by suppressor-planting, which the unconditional path correctly re-enables.getWorktreeStatuscallers audited:WorktreeCardandWorktreeJumpPaletteboth threaded; jump palette would otherwise desync from the sidebar (verified live in manual test 4).Security Audit
No new input handling, command execution, path handling, auth, secrets, dependency, or IPC surfaces. The change is renderer-only state derivation plus an unconditional drop in an existing shutdown path. No follow-up needed.
Notes
asleepstate in theWorktreeStatusenum (slept and never-started both render grey for now), and the parallel mobile/MCPworktree.psfix in the main-process runtime — that path uses a different data shape (RuntimeLeafRecord) and is tracked as future work.worktree.sleepRPC for scripted-sleep misuse. Tracked separately; the design doc adds a code comment above the RPC method as a stopgap.tab.ptyId→tab.lastSpawnSessionIdto eliminate the wake-hint vs liveness footgun at the type level.Made with Orca 🐋