Skip to content

fix(runtime): one teardown policy per kind; removal closes host browser pages everywhere, headless sleep stops terminals - #30715

Merged
nwparker merged 3 commits into
mainfrom
nwparker/r4-owned-session-teardown
Oct 19, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/r4-owned-session-teardown

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​150 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​150
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​164 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​134

ELI5

When you remove or sleep a workspace, Orca must stop whatever that workspace runs on its machine: terminals, native agent chats, browser pages, and leftover launch records. Different removal paths had each grown their own list, and some forgot items. Now one table says, for each action and each kind of item, whether it is stopped or kept. Every path reads that table.

What Changed

User-visible fixes:

  • Removing a project (repo.rm, the CLI, or a paired client) now closes that project's browser pages hosted on the machine and forgets its failed agent launches. Before, they stayed open or recorded for the life of the server.
  • Removing a workspace or folder from the desktop app now closes the browser pages the desktop hosts for paired clients, the same as removal through the runtime already did.
  • Sleeping a workspace from the CLI, a phone, or a paired client on a server with no window (headless serve, or a desktop whose window has closed) now sleeps that workspace's terminals. Before, it only told a window that wasn't there and returned success. A stop that can't be proven is now reported as an error, never as "asleep".

Mechanism:

  • src/main/runtime/owned-session-teardown-policy.ts declares the kinds (pty, structured-chat, host-browser, launch) and the entry points (worktree, folder and project removal, sleep, disconnect). A satisfies Record<…, Record<…>> table makes a new kind or entry point a compile error until someone decides it. The decided policy:
    • Removal stops everything.
    • Sleep stops terminals and keeps tabs, pages and launch records. Stopping native chats on sleep is declared stop-pending-28445; that stop itself is Sleep stops a workspace's native chat agents #28445's.
    • Disconnect stops nothing, because losing contact is never evidence that something exited.
  • The existing closeStructuredSessions flags now read from the table.
  • One runtime method, releaseRemovedWorktreeHostSessions, closes headless pages and client-hosted page records and forgets failed launches.
    • It is called from runtime removal, from all eight desktop IPC removal paths (inside their existing same-id-owner gate), and from project removal.
    • Project removal finds the project's workspaces from its terminal sweep, the client page records, the bridge's own tab owners and the failed-launch table. It releases nothing while a same-id row for another host survives, because page records carry no host.
  • sleepManagedWorktree runs the host's own sleepTerminalsForWorktree when no window is attached. A window keeps its existing renderer-ordered flow.

Why

Linked Issue

Round 4 SSH hardening, R4-5 (owned-session teardown registry). No issue filed.

Visual Proof

N/A: host-side process and page cleanup; nothing on screen changes.

Testing

  • Automated tests added/updated
  • owned-session-teardown-policy.test.ts:
    • pins the whole table;
    • headless sleep sleeps the host's terminals and refuses automatic spawns afterwards (fails on main);
    • an unproven sleep is rejected;
    • an attached window still runs the sleep;
    • project removal releases pages found through client records and through the bridge, and releases nothing while a same-id row survives.
  • The IPC runtime stubs gain the new method.
  • Local checks:
    • the full static job passed, including the runtime Electron ratchet;
    • pnpm tc passed;
    • the unit folders around the change passed (1,502 files): src/main/ipc/worktrees, src/main/runtime, src/main/browser, src/main/agent-launch. Some files fail locally the same way without this change: two orca-runtime.test.ts cases (macOS /private/var tmpdir realpaths) and the browser-manager-tab-identity and -viewport-ownership suites.
  • Live: not verified on a real serve host. The paths are covered with the runtime test harness.

Review

  • Codex (gpt-6.1-sol, high), 3 rounds; the final round is clean. Fixed:
    • the IPC test stubs;
    • a static Electron import in the shared runtime (headless page owners are now read through the bridge);
    • a headless sleep that reported success for an unproven stop.
  • Opus: found the bridge tab list carries no workspace (fixed) and the missing stubs (fixed). Its P3 notes headless sleep can now return an error where it used to return success; that is intended, since it used to do nothing.

Agent skill upstream boundary

  • Not applicable

Notes

  • SSH: disconnect stops nothing. Removal never closes pages while a same-id row survives on another host.
  • Folder workspaces take the same removal path.
  • Cross-platform: no platform-specific code.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for screenshots (reason above)
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • Lint, typecheck and the affected tests pass locally

…browser pages everywhere, headless sleep stops terminals

A declared table says what each entry point (worktree, folder and project removal,
sleep, disconnect) does to each owned kind (PTY, native chat, host browser page,
launch record), so a new kind is a compile error until decided. Removal over desktop
IPC and repo.rm now close the host's browser pages and launch records like the
runtime removal; worktree.sleep with no renderer sleeps the host's terminals instead
of doing nothing. Sleep->chat is declared pending #28445; disconnect stops nothing.
…s without a client page; stub the new runtime method
…page owners through the bridge, not Electron
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: be377231-b2b9-4f0a-9fcb-f94281e3ccce
📥 Commits

Reviewing files that changed from the base of the PR and between 25e53f4 and 987250c.

📒 Files selected for processing: 19
  • src/main/agent-launch/agent-launch-pane-attachment.ts
  • src/main/browser/agent-browser-bridge-tabs.ts
  • src/main/ipc/worktrees-test-runtime-stub.ts
  • src/main/ipc/worktrees-windows.test.ts
  • src/main/ipc/worktrees/removal/execute-worktree-removal.ts
  • src/main/ipc/worktrees/removal/register-worktree-forget-handlers.ts
  • src/main/ipc/worktrees/removal/remove-folder-workspace.ts
  • src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts
  • src/main/ipc/worktrees/removal/remove-unregistered-worktree.ts
  • src/main/ipc/worktrees/removal/retry-failed-local-worktree-removal.ts
  • src/main/ipc/worktrees/removal/worktree-removal-ownership.ts
  • src/main/runtime/folder-workspace-pty-teardown.ts
  • src/main/runtime/owned-session-teardown-policy.test.ts
  • src/main/runtime/owned-session-teardown-policy.ts
  • src/main/runtime/runtime-repository-settings-controller.ts
  • src/main/runtime/terminal/stop/project-terminal-stop.ts
  • src/main/runtime/workspaces/managed-workspace-operations.ts
  • src/main/runtime/workspaces/workspace-registration-removal.ts
  • src/main/runtime/workspaces/workspace-removal-target.ts

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

📝 Walkthrough

The changes add a typed policy for stopping or retaining owned sessions across removal, sleep, and disconnect. Cleanup paths use the policy and pass runtime context to worktree metadata cleanup, which can release host sessions. Project removal collects worktree IDs from PTY, browser-page, failed-launch, and browser-tab sources before releasing sessions. Managed-worktree sleep without a renderer now stops terminals and checks whether the stop was verified.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 98725

The investigated cleanup paths do not establish a remaining issue that should block merging. Normal checks remain appropriate.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, rationale, testing, review findings, scope, and compatibility considerations. However, the Linked Issue section names R4-5 but provides no actual iss… Add a link to the actual tracking issue in the Linked Issue section, or confirm that the author is a maintainer and explain why no issue link is required. Verify and document the required CI or local results for any checklist commands not e…
Docstring Coverage Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main changes: a unified teardown policy, host browser-page cleanup during removal, and terminal stopping during headless sleep.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, review findings, scope, and compatibility considerations. However, the Linked Issue section names R4-5 but provides no actual issue link, despite the template requiring one unless the author is a maintainer.

Resolution

Add a link to the actual tracking issue in the Linked Issue section, or confirm that the author is a maintainer and explain why no issue link is required. Verify and document the required CI or local results for any checklist commands not explicitly covered by the current testing notes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

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 f22aecf into main Oct 19, 2026
46 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.

1 participant