Skip to content

fix(runtime): a terminal close commits in the session partition that holds the tab - #27119

Merged
OrcaWin merged 3 commits into
mainfrom
np/p395-ct-b1-close-partition
Oct 10, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
np/p395-ct-b1-close-partition

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​221 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​216
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145

ELI5

Closing a terminal tab on a paired server sometimes didn't stick: the tab vanished, then came back a moment later, and orca terminal close answered tab_not_found. The server was looking for the tab in the wrong saved section. Now it looks in the section that actually holds the tab.

What Changed

  • Before: a server keeps saved tabs in sections per host ("local", "runtime:"). One workspace's tabs can end up split across two of them. The close searched only the section the workspace normally routes to, so a tab saved in the other section was never removed. The next snapshot from the server re-added it. A handle-addressed close ("close this exact terminal") reported success or tab_not_found, but the saved row stayed.
  • After: the close finds every section whose saved tabs contain that exact tab id, and removes and records the close there. If a legacy relay reattach left the same tab in two sections, both copies are closed and recorded in one durable write. A pin in the section holding the tab still blocks the close.
  • Mechanism: RuntimeWorkspaceSessionController.getHostIdsForTab(worktreeId, tabId) returns the holding partitions, routed partition first, or the routed partition alone when none holds it. The close transaction (terminalSurfaceCloseMutation) takes hostIds() instead of a single hostId(). The pane incarnation fence (requestedSession), the retirement-identity capture and resolvePtyTabCloseSurfaceAuthority read the same partition.

Why

  • The match is on the tab's uuid, never the worktree id. repoId::path repeats across hosts, so a worktree-level fallback would adopt another host's same-named workspace. The controller already refuses that, and this keeps the rule.
  • The resolver lives in the controller, which already owns partition choice. The binding writer already searches every partition this way.
  • The issue suggested refusing when two partitions hold the same tab. A tab id is a uuid, so two copies are the same tab left behind by a legacy reattach. Refusing would leave the user with a tab they can never close, so this closes and records both.
  • A close that matches nothing still records the close in the routed partition, exactly as before.

Linked Issue

Fixes #18202

Also fixes the server half of #17767 and #21339. Those issues stay open for their client-side and CLI-routing parts.

Visual Proof

N/A: server persistence change with no UI change. The new test reproduces the issue's saved state.

Testing

  • New src/main/runtime/orca-runtime-terminal-close-spill-partition.test.ts. It closes by handle a tab saved only in runtime:<env> while local holds an unrelated tab. It covers two copies of one tab, and the pin guard in the holding partition. On origin/main the first two fail: the spill row survives the close.

  • Focused suites: every runtime close test, src/main/persistence/terminal-topology/ and orca-runtime.test.ts (1558 passed).

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

  • I manually tested these changes locally

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

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

Server-internal. No wire change. SSH: unchanged; a direct-SSH partition is only touched when it holds that exact tab id. Folder workspaces: the routed partition comes from the same controller. An unroutable folder record still closes nothing, as before.

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)

…holds the tab

One worktree's tabs can be split across the local and runtime:<id> saved
partitions. The host close searched only the routed partition, so a tab
in the other one was reported tab_not_found (or recorded nowhere useful)
and the next snapshot brought it back. The close now resolves every
partition that holds that exact tab id and commits there.

Fixes #18202
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

📝 Walkthrough

Walkthrough

Terminal close operations now resolve host partitions by worktree and tab identity. The close mutation checks each listed partition, preserves the pinned-tab guard, and persists partitions where the target tab was closed. Runtime close paths use tab-associated hosts. Tests cover spill-partition tabs, duplicate copies, changed pane bindings, and pinned tabs.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to ec649

Closing a terminal tab can remove a different tab copy in another session partition and kill its process. A rebound pane in a later partition can also be retired. Resolve both issues before merging.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check Warning #18202 requires a close to refuse when the exact tab identity matches more than one partition and the owner cannot be disambiguated. getHostIdsForTab returns all matching partitions. `terminalSurfac… When the exact tab identity matches multiple partitions without a disambiguating identity, return an explicit ambiguity error before session mutation or PTY kill. Update the duplicate-copy test to require no mutation and no PTY kill.
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check Passed The description is complete and aligned with the template. It explains the problem, change, rationale, linked issues, visual proof status, testing, scope, and checklist status. The full lint, typechec…
Title check Passed The title clearly and concisely describes the main change: terminal close commits in the session partition that contains the tab.
Out of Scope Changes check Passed The production changes and tests remain connected to #18202. They resolve exact-tab partition lookup, preserve unrelated partitions, retain the matched-partition pin guard, record durable closes, and …

Full details: Linked Issues check

Explanation

#18202 requires a close to refuse when the exact tab identity matches more than one partition and the owner cannot be disambiguated. getHostIdsForTab returns all matching partitions. terminalSurfaceCloseMutation then closes and records every match. The test closes and records every copy when legacy reattach left one in two partitions confirms this behavior. The binding-change fence covers a later mutation, but it does not resolve identical matches present at request time.


  • 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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de8243e8-bb31-4dd7-aeee-487cc5b0a4f4
📥 Commits

Reviewing files that changed from the base of the PR and between 4ec973f and 0a1a154.

📒 Files selected for processing (12)
  • src/main/persistence/terminal-topology/terminal-late-bind-layout-rules.test.ts
  • src/main/persistence/terminal-topology/terminal-leaf-move-concurrent-close.test.ts
  • src/main/persistence/terminal-topology/terminal-stale-pane-tree-client.test.ts
  • src/main/persistence/terminal-topology/terminal-topology-commit.test.ts
  • src/main/persistence/terminal-topology/terminal-topology-model.test.ts
  • src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts
  • src/main/runtime/orca-runtime-get-runtime-id.ts
  • src/main/runtime/orca-runtime-terminal-close-spill-partition.test.ts
  • src/main/runtime/orca-runtime-wait-for-mobile-terminal-surface.ts
  • src/main/runtime/runtime-workspace-session-controller.ts
  • src/main/runtime/terminal-surface-close.ts
  • src/shared/workspace-session-terminal-tab-close.ts

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

…d since it was asked

The owner fence checks only the first partition holding the tab, so a
second legacy copy rebound before admission was retired and its PTY
collected for kill. Owner-fenced closes now capture every holder and
refuse with terminal_pane_owner_changed when a later copy is new or
changed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2174776e-e85f-43b0-a3e1-dd969f574051
📥 Commits

Reviewing files that changed from the base of the PR and between 0a1a154 and 79cbc2e.

📒 Files selected for processing (4)
  • src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts
  • src/main/runtime/orca-runtime-terminal-close-spill-partition.test.ts
  • src/main/runtime/terminal-surface-close.ts
  • src/main/runtime/workspace-session-terminal-tab-retirement-identity.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.

target,
options,
requestedSession: this.getWorkspaceSessionForWorktree(worktreeId),
requestedSession: requested.values().next().value ?? null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Capture the pane incarnation from its holder.

If the first partition lists the tab but not the addressed leaf, Line 142 supplies no incarnation for that leaf. terminalSurfaceCloseMutation then uses the second partition’s current PTY binding without its requested incarnation. If that pane restarts before the durable mutation, the close can retire the replacement pane. Capture and check the requested incarnation separately for each partition that holds the leaf.

…ssions

The binding writer mutates a session in place, so comparing a captured
session reference with the current one compared a replacement with
itself. Capture an immutable copy of each holder's row, bindings and
incarnations when the close is asked.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 89ce03d3-2c56-4033-8fdf-6c3c4ccc95af
📥 Commits

Reviewing files that changed from the base of the PR and between 79cbc2e and ec649d5.

📒 Files selected for processing (5)
  • src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts
  • src/main/runtime/orca-runtime-get-runtime-id.ts
  • src/main/runtime/orca-runtime-terminal-close-spill-partition.test.ts
  • src/main/runtime/terminal-surface-close.ts
  • src/main/runtime/workspace-session-terminal-tab-retirement-identity.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/runtime/orca-runtime-get-runtime-id.ts
  • src/main/runtime/orca-runtime-terminal-close-spill-partition.test.ts
  • src/main/runtime/terminal-surface-close.ts

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

target,
options,
requestedSession: this.getWorkspaceSessionForWorktree(worktreeId),
...captureTerminalCloseRequest(worktreeId, target, hostIds(), store, fenced),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Refuse tab IDs with conflicting identities across partitions.

If two partitions contain the same tab ID with different persisted identities, this request closes both copies. Each captured copy is checked only against its own partition. The close can therefore remove and kill a different tab’s surface. Compare holder identities before mutation. Refuse the close without a write or PTY kill when the identities conflict. The linked issue explicitly requires refusal for an ambiguous match.

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]: exact terminal close snaps back when one worktree is split across local and runtime session partitions

1 participant