Repository navigation
fix(sleep): reopen a slept agent whose tab is gone in a fresh tab instead of stranding it - #33598
Conversation
…tead of stranding it Main resumes a workspace sleep's agents only when their own pane opens, so a record whose tab had disappeared was never resumed: activation opened a plain default tab and the record sat in main's session forever. The window's activation sweep now resumes such a stranded record in a fresh tab with --resume and asks main to drop its copy; main drops it only while no tab lists the pane, so placed records keep their in-pane resume. Fixes #22657
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🔇 Additional comments: 1
src/main/runtime/workspaces/managed-workspace-operations.ts-273-273: 1
273-273:Major · Data Integrity & Integration · Quick win
⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.Verify the record belongs to
worktreeIdbefore deleting it.If two worktrees share a session host, an IPC request can select one worktree and supply a stranded pane key belonging to the other.
dropStrandedSleepRecordchecks the pane key and tab list, but notrecord.worktreeId. Main can therefore delete the other worktree’s resume handle. PassworktreeIdinto the helper and requirerecord.worktreeId === worktreeIdbefore removal. Based on learnings, renderer arguments that affect privileged main-process behavior require validation at the IPC boundary.Source: Learnings

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
53284d47-76e8-4b70-a4b6-cab10ae871a0
Files selected for processing: 16-
src/main/ipc/worktrees-create-metadata-persistence.test.tssrc/main/ipc/worktrees.tssrc/main/ipc/worktrees/sleep/register-worktree-sleep-handlers.tssrc/main/runtime/terminal/stop/worktree-sleep-resume-records.test.tssrc/main/runtime/terminal/stop/worktree-sleep-resume-records.tssrc/main/runtime/workspaces/managed-workspace-operations.tssrc/preload/api/worktree-api.tssrc/preload/api/worktrees-bridge.tssrc/renderer/src/lib/resume-sleeping-agent-session-stranded-sleep.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.tssrc/renderer/src/lib/sleeping-agent-pane-ownership.tssrc/renderer/src/lib/swept-sleep-record-settlement.tssrc/renderer/src/lib/wake-sleeping-agents-in-background.test.tssrc/renderer/src/lib/wake-sleeping-agents-in-background.tssrc/renderer/src/web/preload-api/web-worktrees-api.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
-
| } | ||
| if (isInvalidWorktreeActivationRecord(record)) { | ||
| state.clearSleepingAgentSession(record.paneKey) | ||
| settleSweptRecord(record) |
There was a problem hiding this comment.
Preserve a stranded sleep record when its status is stale.
If an unfinished agent last updated more than 30 minutes before sleep capture, isInvalidWorktreeActivationRecord returns true. The new selection includes its stranded workspace-sleep record, and this branch now clears the renderer record and requests deletion from main without attempting recovery. A stale status does not establish that the provider session cannot resume. Keep the resume handle or report a recovery failure instead of retiring it on this age check.
| void Promise.resolve() | ||
| .then(() => window.api.worktrees.retireStrandedSleepRecord({ worktreeId, paneKey })) | ||
| .catch((error: unknown) => | ||
| console.warn('[sleep-resume] could not retire a stranded sleep record', error) |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash # Inspect the session write and restore paths for both processes. rg -n -C 4 'commitWorkspaceSessionEdit|clearSleepingAgentSession\s*\(|sleepingAgentSessionsByPaneKey|retireStrandedSleepRecord' src/main/runtime src/renderer/src/store src/renderer/src/lib
Repository: stablyai/orca
Length of output: 45667
Script executed:
#!/bin/bash set -eu printf '%s\n' '--- changed helper ---' nl -ba src/renderer/src/lib/swept-sleep-record-settlement.ts | sed -n '1,120p' printf '%s\n' '--- IPC symbol references ---' rg -n -F --glob '*.{ts,tsx}' 'retireStrandedSleepRecord' src | head -80 printf '%s\n' '--- main session persistence symbols ---' rg -n -F --glob '*.ts' -e 'clearSleepingAgentSession' -e 'sleepingAgentSessionsByPaneKey' -e 'commitWorkspaceSessionEdit' src/main src/renderer/src/store src/renderer/src/lib | head -180
Repository: stablyai/orca
Length of output: 26928
Script executed:
#!/bin/bash set -eu printf '%s\n' '--- main retirement method ---' nl -ba src/main/runtime/workspaces/managed-workspace-operations.ts | sed -n '225,290p' printf '%s\n' '--- commitWorkspaceSessionEdit declarations and callers ---' rg -n -F --glob '*.ts' 'commitWorkspaceSessionEdit' src/main | head -80 printf '%s\n' '--- session save handling for sleep records ---' nl -ba src/main/persistence/window-save-sleep-records.ts 2>/dev/null | sed -n '1,180p' || true nl -ba src/main/persistence/window-save-divergence.ts 2>/dev/null | sed -n '1,180p' || true printf '%s\n' '--- handler binding ---' nl -ba src/main/ipc/worktrees/sleep/register-worktree-sleep-handlers.ts | sed -n '25,55p'
Repository: stablyai/orca
Length of output: 15188
Script executed:
#!/bin/bash set -eu printf '%s\n' '--- commit implementation ---' nl -ba src/main/runtime/terminal/stop/worktree-terminal-stop.ts | sed -n '95,155p' printf '%s\n' '--- drop helper definition and uses ---' rg -n -F --glob '*.ts' 'dropStrandedSleepRecord' printf '%s\n' '--- drop helper source context ---' file=$(rg -l -F --glob '*.ts' 'function dropStrandedSleepRecord' src | head -1) test -n "$file" rg -n -C 12 -F -- 'function dropStrandedSleepRecord' "$file"
Repository: stablyai/orca
Length of output: 5315
Script executed:
#!/bin/bash set -eu nl -ba src/main/runtime/terminal/stop/worktree-terminal-stop.ts | sed -n '110,145p' rg -n -C 10 -F --glob '*.ts' 'function dropStrandedSleepRecord' src
Repository: stablyai/orca
Length of output: 4065
Keep retirement recoverable when the IPC request fails.
If retireStrandedSleepRecord rejects before dropStrandedSleepRecord durably removes the main record, settleSweptRecord has already cleared the renderer record. The catch only logs the error. The main-owned record can remain available to a later wake sweep, which may resume the same provider session again. Preserve a retryable retirement intent or reconcile the main record before settlement completes.
Summary (ELI5)
When you put a workspace to sleep, Orca saves a note for each agent ("resume Claude session X in tab T"). On wake, Orca resumes the agent when tab T opens. If tab T has disappeared by then, nothing ever opens it. The note just sits there, the workspace opens a plain new tab, and your conversation is never resumed. With this change Orca reopens that agent in a fresh tab with
--resume, then throws the note away.Root cause
Since #31564, main captures workspace-sleep records (
origin: 'worktree-sleep',state: 'done',restoreOnTabOpenOnly: true). Main resumes them only when their own pane opens (main-resumed-sleep-pane.ts→worktrees:resumeSleptPane). The window's activation sweep skips every such record (!isWorkspaceSleepRecord(record)inresumeSleepingAgentSessionsForWorktree).window-save-sleep-records.tskeeps main's copy through every window save. So a record whose tab is gone is never resumed by anyone, and it is never cleared. Before #31564 the window sweep deleted it instead (the original report). On current main it is stranded rather than deleted, and the user-visible result is the same: a new tab with no resume.What changed
isStrandedWorkspaceSleepRecord(insleeping-agent-pane-ownership.ts) matches a workspace-sleep record when no tab in any workspace still lists its tab id.launchSleepingAgentSession, which opens a fresh tab, uses the captured launch config, and shows the "session restored" banner.worktrees:retireStrandedSleepRecord. Main removes its copy only if the record is still a workspace-sleep record and its partition still lists no tab for the pane (dropStrandedSleepRecord). This stops a duplicate--resumeon the next restart. A placed record can never be dropped this way.Upstream reference: Claude Code resumes from the transcript by id (
claude --resume <session_id>). The fake model server below received the earlier turns in the resumed request.How verified
Isolated dev Electron (
ORCA_DEV_USER_DATA_PATH=/tmp/...), real Claude Code 2.1.310 with an isolatedCLAUDE_CONFIG_DIR, and a local fake Anthropic server.Repro on main (a944e37):
claudein a tab, sent "remember the word PINEAPPLE", and waited for it to finish (done).origin: worktree-sleep, state: done, restoreOnTabOpenOnly: true, matching the report.workspaceSession(the report's step 3), and restarted.claude, and no request to the model server. Main's record was still in the session, stranded, with nothing able to resume it.With this branch, same state:
Claude Codetab with the "session restored" banner and the PINEAPPLE turn in it. Main's stranded record was gone, replaced by the new pane's live record.msgs=5, so the resumed conversation carried its history.Tests:
pnpm tc, the sleep/resume/wake suites (52 files, 502 tests), andcheck:code-quality:changed. The new regression test fails on main.Risk
getWorkspaceSessionHostIdForWorktree. Web client: no-op stub.Fixes #22657