Skip to content

fix(terminal): a phone wake no longer resumes an agent whose terminal is still running - #29431

Merged
nwparker merged 1 commit into
mainfrom
nwparker/sta-3859-double-resume
Oct 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/sta-3859-double-resume

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​26 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21

ELI5

When a phone opens a workspace on a desktop that runs Orca, the desktop wakes that workspace's sleeping agents. It could also "wake" an agent that was never asleep, starting a second claude --resume on a conversation that was still running in another tab. You ended up with two copies of one conversation writing to the same transcript. Now the desktop asks its terminal service which terminals are still running before it resumes anything.

What Changed

Before: a phone opened a workspace the desktop wasn't showing. If one of its agent tabs hadn't been re-attached since the desktop app restarted (the terminal service kept the agent running across the restart), the wake treated the tab as empty and opened a new tab running claude --resume <same id>. Two live processes, one transcript.

After: the wake resumes a record only when the host's own terminal list shows that pane's terminal has exited. If the terminal is still running, the record is left alone and nothing new is launched. If the list can't be read, the wake declines and keeps the record, so a later activation can still resume it.

Mechanism: wakeSleepingAgentsForWorktreeInBackground called resumeSleepingAgentSessionsForWorktree directly. That sweep decides ownership from renderer-local state only: the live PTY map, plus "this pane will reconnect because its worktree is active". For a background worktree after a restart, both are empty or false, so a live pane reads as unowned. The wake now goes through gateWorktreeAgentActivation, the gate that user worktree activation already uses. The gate reads the execution host's PTY inventory (pty.listSessions), skips records whose persisted PTY is still listed, refuses when an unattributed agent PTY is live, and returns blocked if the inventory is unreadable. The gate gained an optional resumeOptions argument, so the wake keeps its no-navigation, already-woken-claims and background-mount behavior.

Workspaces owned by a paired Remote Orca Server have no host inventory on this renderer, so they keep the existing per-pane mirror park unchanged.

Why

The rule is to never resume unless the current holder is proven exited. The activation gate already enforces that rule against the host's terminal inventory, and the background wake was the one sweep caller that skipped it. Reusing the gate keeps one ownership check instead of adding a second inventory read. The other option was to make recordPaneIsOwnedByPreservedPane treat a persisted PTY binding as ownership. But that binding goes stale across sleep and restart and can't tell live from exited, so it would either block legitimate resumes or still fork.

The two paired-client paths were closed by #29272 and #29389 (open). #29289 (open) covers the paired-desktop renderer's mirrored-record sweep. This PR touches neither.

Linked Issue

STA-3859 (Linear)

Visual Proof

N/A. This changes which resume a background sweep is allowed to launch. It has no UI change, and the runtime test covers it.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New src/renderer/src/lib/wake-sleeping-agents-live-unmounted-pane.test.ts, run against the real store and sweep. The worktree is a background one, and its pane is unmounted but its persisted PTY is live.

  • Live PTY in the host inventory: no resume tab and no automatic claim. Fails on main (a second --resume gets queued).
  • Unreadable inventory: outcome blocked, no resume, record kept. Fails on main.
  • Exited PTY (absent from the inventory): resumes exactly once.

The existing wake, live-done, activation-gate and host-mirror frame-ordering suites pass. pnpm tc:web and pnpm run check:code-quality:changed pass.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • No wire change. The renderer reads a host inventory it already reads during activation.
  • SSH: the inventory is scoped to the SSH connection that owns the workspace, the same as during activation. Lost contact means unverifiable, and the wake declines instead of resuming.
  • Folder workspaces resolve through the same inventory scope.
  • Cross-platform: renderer logic only.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…ng an agent

The background wake a phone triggers on the desktop host resumed slept agent
records with no host PTY inventory check. In a worktree the desktop is not
looking at, a pane whose PTY the daemon still runs (e.g. after a renderer
restart) reads as unowned, so the wake forked a second claude --resume onto
the live transcript. Route it through the activation gate, which resumes only
records whose PTY the host inventory shows exited and declines when the
inventory cannot be read. (STA-3859)
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 49a2d2d2-f4da-4975-915b-4f49df3d29aa
📥 Commits

Reviewing files that changed from the base of the PR and between 802508c and d8305c6.

📒 Files selected for processing: 3
  • src/renderer/src/lib/wake-sleeping-agents-in-background.ts
  • src/renderer/src/lib/wake-sleeping-agents-live-unmounted-pane.test.ts
  • src/renderer/src/lib/worktree-agent-activation-gate.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 1af9bfe into main Oct 16, 2026
30 checks passed
nwparker added a commit that referenced this pull request Oct 25, 2026
The terminal daemon now lists the ORCA_PANE_KEY each PTY was spawned with,
and the activation gate (also used by the phone wake) claims a sleeping
record through that key when this renderer's layout no longer links the
record's pane to the live PTY. Covers a host that re-keyed the live PTY onto
a new tab and an agent a paired client launched for its own pane; both
previously forked a second `claude --resume` onto the live transcript.

Rewritten on current main from #24386 (the phone wake already routes
through the gate since #29431; the SSH relay it also touched is gone).

Co-authored-by: Minidoracat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant