Skip to content

fix(runtime): automatic tab activation no longer wakes a worktree the host put to sleep - #27081

Merged
OrcaWin merged 3 commits into
mainfrom
np/p395-b1-sleep-automatic
Oct 10, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
np/p395-b1-sleep-automatic

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76

ELI5

When you put a workspace on a paired Orca server to sleep, its terminal stopped and then started again about a second later. The server now remembers that it put the workspace to sleep and refuses to restart it on its own. Opening the tab yourself still wakes it.

What Changed

Before: Sleeping a remote workspace with a plain shell tab (no agent) stopped the terminal, then the desktop's background reconnect asked the server to "activate" the tab, and the server started a fresh shell under the same session id. The workspace never stayed asleep until the desktop was reloaded.

After: The background reconnect gets the tab back without a terminal, the workspace stays asleep, and a click on the tab (an explicit user activation) still wakes it as before.

Mechanism:

  • The server already keeps an in-memory sleep record per worktree (terminalSleepStateByWorktreeId). Automatic tab activation only checked for an agent's sleep record, which a plain shell never has. It now also refuses when the host's own sleep record exists.
  • A sleep can commit while an automatic spawn waits for the per-worktree spawn lock. The spawn now carries refuseSleptWorktree, and acquireWorktreeTerminalSpawn re-checks under the lock: it releases the lock and refuses instead of clearing the sleep record and publishing woken. The activation turns that refusal into the same "navigate without spawning" result the agent-record path already returns, so the client's recovery stops instead of looping.
  • User activations, IPC spawns and every other caller are unchanged.

Why

The host is the only side that knows it put the worktree to sleep, so the fix belongs on the host and also protects older clients. Alternatives considered: making the client stop sending automatic activations after a sleep only covers new clients and still races with the stream recovery; writing a durable sleep record would also survive a host restart, but that is part of a parked decision about pausing automatic restore after a crash, so this PR deliberately does not add one. Known limitation: the sleep record is in memory, so a host restart forgets it.

Takes over the approach from #24410 (@mmarabel) and #24416 (@innocarpe), with credit.

Linked Issue

Fixes #24399

Visual Proof

N/A: host-side runtime behavior; covered by the runtime tests below.

Testing

  • src/main/runtime/automatic-activation-host-sleep.test.ts (new; fails on origin/main): a slept worktree with no agent record refuses an automatic activation (no spawn, no woken), a user activation still spawns, an automatic spawn carries refuseSleptWorktree, and a sleep that commits while an automatic spawn waits for the lock makes that spawn refuse without waking the worktree.

  • orca-runtime.test.ts, folder-workspace-pty-identity.test.ts, terminal-list-pending-pty-registration.test.ts pass.

  • pnpm tc:node, oxlint, pnpm run check:code-quality:changed.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

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

SSH and orca serve run the same runtime code. Folder workspaces use the same worktree identity key. No wire change: the refusal is the existing navigation result, so old clients benefit too. No platform-specific code.

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)

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 3 minutes.

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: c3e32d15-496c-428e-abfb-9ee9542ff530

📥 Commits

Reviewing files that changed from the base of the PR and between 2a363ee and 1dfec7c.


📒 Files selected for processing (7)
  • src/main/ipc/pty/pane/adopt-stable.ts
  • src/main/ipc/pty/pane/join-pane-spawn.test.ts
  • src/main/ipc/pty/pane/spawn-reservation.ts
  • src/main/ipc/pty/runtime/spawn-options.ts
  • src/main/runtime/orca-runtime-create-terminal-dependencies.ts
  • src/main/runtime/orca-runtime-create-terminal.ts
  • src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts


No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 92f019a6-94e2-4502-b3ec-3951a6885951

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0b828 and 2a363ee.


📒 Files selected for processing (10)
  • src/main/ipc/pty/runtime/spawn-execute.ts
  • src/main/ipc/pty/runtime/spawn-state.ts
  • src/main/runtime/automatic-activation-host-sleep.test.ts
  • src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts
  • src/main/runtime/orca-runtime-create-terminal.ts
  • src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts
  • src/main/runtime/orca-runtime-stop-terminals-for-worktree.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/worktree-terminals-sleeping-error.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

Terminal spawning now accepts a refuseSleptWorktree option. When enabled, spawn acquisition checks the worktree sleep state under the shared lock and rejects a spawn if the worktree is sleep-held. Automatic mobile-session activation uses this option and handles the sleeping-worktree error without materializing a terminal. User activation can still wake the worktree. New tests cover automatic activation, user activation, and a spawn queued during sleep.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2a363

Automatic activation leaves a sleeping worktree stopped, while explicit activation can still wake it. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main runtime fix: automatic tab activation no longer wakes a worktree that the host put to sleep.
Description check Passed The description is complete and focused. It includes the user-facing behavior, mechanism, rationale, linked issue, visual-proof justification, automated testing, compatibility notes, and checklist sta…
Linked Issues check Passed The changes satisfy the coding requirements in #24399. activateMobileSessionTab refuses automatic materialization when the host sleep state exists, including for tabs without an agent sleep record. …
Out of Scope Changes check Passed The changes stay within #24399. The production edits add one host-side refusal option, propagate it through terminal creation, preserve the existing explicit-wake path, and handle the existing navigat…


✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR


  • 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.

@OrcaWin
OrcaWin merged commit dc12495 into main Oct 10, 2026
76 of 77 checks passed
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.

[Bug]: Sleeping a remote workspace immediately restarts its terminal until the desktop is refreshed

1 participant