Repository navigation
Conversation
…orkspace Sleeping a workspace kills its PTYs but deliberately keeps `tab.ptyId` as a wake hint. `planMobileTerminalTabMount` only checked that the handle resolved to a real tab, so a phone/web client calling `terminal.subscribe` made the desktop background-mount that pane and bring a PTY back up — reviving the workspace with no user activation and no navigation. Fail closed when the workspace holds no live PTY and nothing is queued to spawn, so a mount could only create a PTY rather than attach one. `terminal.subscribe` already falls back to a scrollback-only stream when no PTY appears, so the client still gets the saved output. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016Si2MAXbpmvDM3qBihjoTy
Greptile SummaryThis PR fixes a bug where a mobile or web client calling
Confidence Score: 5/5Safe to merge — the change is a pure read-only predicate that strictly narrows what remote clients can trigger, and the three escape hatches preserve every legitimate mount path. The guard correctly distinguishes a slept workspace (empty Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/renderer/src/lib/mobile-terminal-tab-mount.ts | Adds worktreeHasNoResumableTerminal guard before any mount planning; correctly uses ptyIdsByTabId (live-PTY source of truth) rather than tab.ptyId (sleep-preserving hint). All three escape hatches (live PTY on any tab, pending startup, pending activation spawn) are sound and tested. |
| src/renderer/src/lib/mobile-terminal-tab-mount.test.ts | Six new test cases added — three blocking paths and three allowed paths — using well-named state / sleptState helpers that accurately mirror the runtime distinction between live and slept workspaces. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[terminal.subscribe from mobile/web client] --> B{request.worktreeId?}
B -- No --> Z1[return null]
B -- Yes --> C{worktreeHasNoResumableTerminal?}
C -- checks every tab --> D{"ptyIdsByTabId empty AND\npendingStartupByTabId empty AND\n!pendingActivationSpawn"}
D -- all tabs satisfy --> E[return true — slept workspace]
D -- any tab fails --> F[return false — awake workspace]
E --> Z2[return null — no revival]
F --> G{tabId provided?}
G -- Yes --> H{tab exists in workspace?}
H -- No --> Z3[return null]
H -- Yes --> I[tabId = request.tabId]
G -- No --> J{ptyId provided?}
J -- Yes --> K[resolveTerminalTabIdForPtyId]
K --> L{unique owner found?}
L -- No --> Z4[return null]
L -- Yes --> I
J -- No --> Z5[return null]
I --> M{isTabMounted?}
M -- Yes --> Z6[return null]
M -- No --> N[return BackgroundMountTerminalWorktreeDetail]
Reviews (2): Last reviewed commit: "refactor: condense mount guard rationale..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/lib/mobile-terminal-tab-mount.ts (1)
15-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense this rationale comment.
The full behavior explanation is useful but overly long for an inline source comment; retain the essential invariant and issue reference.
Suggested simplification
-/** - * True when mounting this tab could only *create* a PTY rather than attach one: - * the workspace holds no live PTY and nothing is queued to spawn. - * - * Why: sleeping a workspace kills its PTYs but keeps `tab.ptyId` as a wake hint, - * so a mobile subscribe could mount the pane and bring the workspace back to life - * on the desktop with no user activation (`#10205`). `terminal.subscribe` already - * degrades to a scrollback-only stream when no PTY appears, so failing closed here - * still serves the saved output — it just stops resurrecting a slept workspace. - */ +/** Prevent mobile subscriptions from reviving slept workspaces (`#10205`). */As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 97a044aa-9d1a-4e3a-b59d-516fcbb207d0
📒 Files selected for processing (2)
src/renderer/src/lib/mobile-terminal-tab-mount.test.tssrc/renderer/src/lib/mobile-terminal-tab-mount.ts
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016Si2MAXbpmvDM3qBihjoTy
|
Closing this — it targets a path that is not the cause, and the path it does touch has since been fixed upstream. Two things came out of a deeper investigation of #10205:
Thanks for the patience on this one — the original premise was wrong and I would rather withdraw it than have it reviewed on that basis. |
Summary
Sleeping a workspace could be undone by a phone or web client, with no action on the desktop.
Sleep kills a workspace's PTYs but deliberately keeps
tab.ptyIdas a wake hint.planMobileTerminalTabMountonly checked that the incoming handle resolved to a real tab, so when a client calledterminal.subscribeon one of that workspace's terminals, the desktop background-mounted the pane and brought a PTY back up — reviving the workspace without any user activation and without navigating anywhere. The user sees a workspace they slept turn green again, and opening it shows a bare shell (a fresh spawn carries no agent resume).This makes the planner fail closed when a mount could only create a PTY rather than attach one: the workspace holds no live PTY, no queued startup, and no pending activation spawn.
terminal.subscribealready degrades to a scrollback-only stream when no PTY appears, so the client still gets the terminal's saved output — it just no longer resurrects the workspace.Still allowed, and covered by tests:
terminal.create→subscriberaces the spawn)Fixes #10205
Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildSix new cases in
mobile-terminal-tab-mount.test.ts(12/12 pass): three that a slept workspace is not revived via real-tab id, synthetic pty handle, or before consulting mount state; three that legitimate mounts still proceed.Note on
pnpm test: the full suite has 43 pre-existing failures in 9 files unrelated to this change (use-markup-draw-hint,pr-comment-presentation,pr-comments-list-selection,use-persisted-ai-vault-view-options,LinearAgentSkillSetupPrompt.reminder-toast,mobile-sidebar-onboarding-badge,SidebarToolbar,transcript-watch-liveness,agent-exec-handler). Verified identical failures on unmodifiedupstream/mainat 4543bb6 — mostlywindow.localStoragebeing undefined in those environments.Field verification
Reproduced and then verified fixed against a running dev build over CDP:
planMobileTerminalTabMountreturned a mount plan for every slept workspace.null; a workspace with live PTYs still plans its mount.AI Review Report
Reviewed with Claude Code across the risk areas below.
ptyIdsByTabId, which is populated for local, SSH, and remote-runtime PTYs alike, so a live remote workspace still mounts. Remote-runtime and SSH pty ids are not special-cased, matching the surrounding code.terminal.create→subscribepath working, which is how mobile launches agents. Verified no other caller exists —planMobileTerminalTabMountis called only fromuseIpcEvents, which passes the full store state.Array.everyover a single workspace's tabs on an event that already does more work; no new renders, subscriptions, or IPC.sleptWorktreeIdsmarker. It is the more complete fix (it would also cover the non-mobile wake paths listed in [Bug]: Sleeping workspaces revive without user activation — hard to diagnose (open question on opt-in lifecycle logging) #10205), but the issue notes that approach was added and reverted historically, so it needs a maintainer decision rather than a drive-by change.Security Audit
No new input handling, command execution, path handling, auth, secrets, or dependency surface. The change is a read-only predicate over existing renderer store state and strictly narrows what a remote client can cause the desktop to do — a client can no longer cause PTY spawns in a workspace the user has slept. IPC shape is unchanged; the message is already validated by the existing planner, and the new check runs before any mount is scheduled. No follow-up needed.
Notes
worktree.activate).activateAndRevealWorktree→resumeSleepingAgentSessionsForWorktree, cold-restore agent resume, startup hydration); I could not reproduce those on currentmain, including the issue's own Trigger A cascade, so they are deliberately out of scope here.hasWorktreeSleepIntentis only set when sleeping the active workspace (sleep-worktree-flow.ts), so sleeping a background workspace lets its PTY exits reachbumpWorktreeActivity— a workspace registers activity at the moment it is slept.store/slices/terminals.tsusessession.activeWorktreeIdsOnShutdown ?? …tabs.some(t => t.ptyId). The primary writer inlib/workspace-session.tsexplicitly avoidstab.ptyIdwith the comment "which sleep preserves as a wake hint and would revive slept worktrees as active", but the fallback uses exactly that — so a session missing that field (older build, or a crash before the write) revives every slept workspace on next launch.