Repository navigation
fix(ssh): reopening a workspace-slept agent tab on a managed host resumes it, without widening its permissions - #29672
Conversation
…nt on the managed host A paired client's worktree sleep stops the host's PTYs, but the resume record its renderer writes never reaches the host, and the host is what answers the tab open. Capture the record on the host from its own hook store before the stop, applying the shared holder rule (an agent the hook store proved exited leaves no record).
…ermission-widening defaults Resuming a session started as a hand-typed `claude` filled the missing launch recipe from settings defaults, which carry the permission bypass. Host tab-open resume, window cold restore and worktree wake now share one rule: the recorded recipe, or none.
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bf8fd9e7-46e4-4ff7-9479-ed35a44306e2
📒 Files selected for processing: 16
src/main/runtime/host-sleep-resume-record.test.tssrc/main/runtime/terminal/launch/mobile-terminal-startup.tssrc/main/runtime/terminal/stop/worktree-sleep-resume-recording.tssrc/main/runtime/terminal/stop/worktree-sleep-resume-records.tssrc/main/runtime/terminal/stop/worktree-terminal-sleep.tssrc/main/runtime/terminal/stop/worktree-terminal-stop.tssrc/main/runtime/workspaces/workspace-activation.tssrc/renderer/src/components/terminal-pane/pty-connection-agent-session-resume.spec.tssrc/renderer/src/components/terminal-pane/pty-connection-cold-restore-agent-resume.spec.tssrc/renderer/src/components/terminal-pane/pty-connection-cold-restore-resume-command.spec.tssrc/renderer/src/components/terminal-pane/pty-connection-remote-runtime-attach.spec.tssrc/renderer/src/components/terminal-pane/pty-connection-sleeping-resume-banner.spec.tssrc/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.tssrc/renderer/src/lib/sleeping-agent-session-launch-windows-quoting.test.tssrc/renderer/src/lib/sleeping-agent-session-launch.tssrc/shared/tui-agent-launch-defaults.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| // Why before the stop: a PTY's exit clears its hook rows, and with them the session ids. | ||
| const resumeCapture = await this.sleepResumeRecords.capture(worktree.id, livePtyIds) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Capture errors now abort the sleep before any PTY stops.
sleepResumeRecords.capture runs inside the main try. It has no catch. persist swallows its errors, so a lost record "costs the resume, not the sleep". capture does not follow that rule. captureWorktreeSleepResumeRecords catches errors from checkAgentPresence. It does not catch a throw from readRows, which calls getAgentProviderSessionSnapshotFn. If that call throws, the sleep fails with no PTYs stopped. Wrap the capture so that a failure produces an empty capture.
Proposed fix
- const resumeCapture = await this.sleepResumeRecords.capture(worktree.id, livePtyIds)
+ const resumeCapture = await this.sleepResumeRecords
+ .capture(worktree.id, livePtyIds)
+ .catch((error) => {
+ console.error('[runtime] could not capture slept agent sessions', { worktreeId: worktree.id, error })
+ return new Map() as Awaited<ReturnType<typeof this.sleepResumeRecords.capture>>
+ })📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Why before the stop: a PTY's exit clears its hook rows, and with them the session ids. | |
| const resumeCapture = await this.sleepResumeRecords.capture(worktree.id, livePtyIds) | |
| // Why before the stop: a PTY's exit clears its hook rows, and with them the session ids. | |
| const resumeCapture = await this.sleepResumeRecords | |
| .capture(worktree.id, livePtyIds) | |
| .catch((error) => { | |
| console.error('[runtime] could not capture slept agent sessions', { worktreeId: worktree.id, error }) | |
| return new Map() as Awaited<ReturnType<typeof this.sleepResumeRecords.capture>> | |
| }) |
ELI5
You put a workspace to sleep while an agent was in one of its tabs. On a managed SSH host, opening that tab again gave you a plain shell, and the conversation never came back. Now the host remembers which conversation each slept tab held and resumes it when you open the tab. Resuming also no longer adds permission-skipping flags you never launched the agent with.
What Changed
Before: on a managed SSH host, with one or two paired desktops, opening a workspace-slept agent tab always gave a plain shell. That was true even when no other tab held the conversation (the soak's control runs from desktop 1 and desktop 2 both failed).
After: reopening the tab runs
claude --resume <id>(or that agent's equivalent).Mechanism. When a paired desktop sleeps a workspace, it asks the host (
terminal.sleep) to stop the terminals. The desktop wrote its "resume this conversation" record only into its own state. For host-owned tabs, the desktop defers the tab open to the host (session.tabs.activate), which reads only its own records. So no--resumewas ever issued, from either desktop. The #29588 holder check was never reached.The host's sleep now captures those records itself, before it stops each terminal (
worktree-sleep-resume-records.ts,worktree-sleep-resume-recording.ts):At open, the existing #29588 path applies the holder rule against other panes.
Permission rule (security). A resume used to fill a missing launch recipe from the settings defaults, and those defaults carry the permission bypass (for example
--dangerously-skip-permissions). That silently widened a session the user had started by hand as a bareclaude. Three paths now share one helper,resolveResumeLaunchRecipe: the host tab-open resume (mobile-terminal-startup.ts), the window's cold restore (cold-restore-resume-startup.ts), and worktree wake (sleeping-agent-session-launch.ts). They use the recorded recipe, or no args and no env. Orca-launched sessions keep their recorded flags.The headless "can't wake slept agents" warning on mobile activation now ignores records that resume on tab open.
Why
The host answers the tab open, so it has to hold the record. Alternatives considered:
Capturing on the host from its own hook store needs no wire change. Older clients get the fix as soon as the host updates, and an older host behaves exactly as before.
The record write goes through the existing durable session-edit path, now a shared
commitWorkspaceSessionEdit, so the main-process layout-writer ratchet stays flat.Known follow-ups, not in this PR:
Linked Issue
Follow-up to #29588 (soak finding: the desktop path on managed SSH hosts).
Visual Proof
N/A. Terminal behaviour only; the live soak results are below.
Testing
Live, on real hardware. Soak harness, managed SSH host on omarchy (Linux) under an isolated HOME and a private sshd, with two paired macOS desktops. The fake
claudeposts the real hook process identity and theSessionEndreason. The managed server and both desktops were built from 4e3f509d1b11:claude ... --resume <S>, resumed=yes.claude --resume Splus a prompt plusexitin the main worktree, then reopen: resumed=yes. This is the original soak scenario.That build still added
--dangerously-skip-permissionsfrom the settings defaults, which led to the permission fix. Re-run on 50d4042:claude:claude '--resume' '<S>', no permission flag, resumed=yes.claude '--dangerously-skip-permissions'): the recorded recipe is kept, givingclaude '--dangerously-skip-permissions' '--resume' '<S>', resumed=yes.Tests.
src/main/runtime/host-sleep-resume-record.test.tsis new. Its sleep-and-reopen cases fail on main.Updated renderer resume specs pin the no-defaults rule.
orca-runtime.test.ts(1388 tests) passes. The full local replay of the pr.yml "static analysis and typecheck" job passes, including the focus-read and layout-writer ratchets.Review
Codex review (
gpt-6.1-sol, high) ran across 8 rounds. Fixed:The remaining P2s are the two follow-ups above.
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)