Skip to content

fix(terminal): keep a pane moved to a new tab on paired runtimes - #32973

Closed
bengry wants to merge 2 commits into
stablyai:mainfrom
bengry:bengry/pane-move-to-tab-sync
Closed

bengry wants to merge 2 commits into
stablyai:mainfrom
bengry:bengry/pane-move-to-tab-sync

Conversation

@bengry

@bengry bengry commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you drag a pane out of a split into its own tab on a remote Orca server, only your window learned about the move. The server still had the old layout and kept sending it back, so the pane jumped back into the split. Now your window tells the server, and the server saves the move.

What Changed

  • Before: in a paired-runtime worktree, "move pane to new tab" changed only the window store. The paired client's moveLeafToNewTab returns not_held (web-terminal-api.ts), and shipped hosts register layout.apply only in layout-owner builds. The next host snapshot rebuilt the old tab from parentTabId and the pane snapped back.
  • After: a new host RPC commits the move in the host session through the existing planTerminalLeafMove, then republishes the session tabs.
  • The host commits through commitLeafMoveAndRekey, the leaf move a local window already uses, so no new main-process layout writer is added (layout-writer ratchet).
 detachTerminalPaneToTab
   moveLeafToNewTab
-    window.api.pty.moveLeafToNewTab        -> not_held (paired client)
-    applyMove (window store only)          -> next host snapshot reverts it
+    if source tab mirrors a host tab and the pane has a pty
+      moveWebRuntimeLeafToNewTab           -> session.tabs.movePaneToNewTab (dispatched first)
+      applyMove under web-terminal-<hostTabId>   (createTab opt-in: mirroredHostTab)
+    else
+      window.api.pty.moveLeafToNewTab      (unchanged)

 host: session.tabs.movePaneToNewTab
+  validate (isTerminalLeafMoveRequest) + source tab visible to the client
+  window-owned host -> not_held
+  commitLeafMoveAndRekey (the same leaf move a local window commits) -> planTerminalLeafMove
+  rehydrate session tabs + notify clients
  • The window applies the move first, under the mirrored id that the host snapshot will use, so the snapshot confirms the local state rather than racing it.
  • An older host (unknown method), a refused move, or a window-owned host falls back to today's behaviour: the next snapshot snaps the pane back. No PTY is killed.
  • A leaf with no pty yet keeps the old path.

Why

The host is authoritative for which leaf belongs to which tab, so the move has to be committed there. The host already has a durable leaf move (planTerminalLeafMove). This PR adds the missing RPC to reach it from a paired client. layout.apply movePaneToNewTab would cover this once layout-owner builds ship. Until then, shipped hosts have no RPC that can change leaf membership (session.tabs.updatePaneLayout changes geometry only).

Linked Issue

Fixes #32939

Visual Proof

No recording attached. Evidence from an end-to-end run:

  • a real pointer drag in a paired Electron desktop client

  • against a headless Electron --serve host

  • on Linux with Xvfb

  • Before (main): final client: web-terminal-10bbe5fe{d95aa7c7, 50198b0b}. The dragged leaf is back in the source tab. The host never moved it.

  • After (this branch): samples at +0, +50, +100, +250, +500 and +1000 ms all show {"web-terminal-a179ce76":["744c394c"],"web-terminal-16d9f559":["e5bf9d19"]}.

    • leafConnects=1 freshSpawns=0: one reattach, no remount.
    • Same host pty.
    • A marker echoed through the host is visible in the moved pane.

Testing

  • I manually tested these changes locally
    • Linux host: orcad built from this branch, paired with the browser client served by orcad --web-client-root.
    • Dragged a pane to a new tab, switched tabs, and ran output in the other panes. The pane stayed.
    • The host layout showed the moved leaf alone in the new tab. The topology revision went up.
  • Automated tests added/updated
    • headless-move-leaf-to-new-tab.test.ts: the real planTerminalLeafMove on a headless session with 2 leaves. Checks the persisted layouts and parentTabId in listMobileSessionTabs, and that an invalid id is refused with the session unchanged.
    • session-tabs-move-pane-to-new-tab.test.ts: RPC dispatch.
    • terminal-pane-tab-detach-runtime-host.test.ts: the local move happens before the host answers, with the mirrored id and opt-in. On refusal, applyMove runs exactly once.
    • web-runtime-leaf-move.test.ts: host ids, and an old host or RPC error mapped to not_held.
    • terminal-tab-mirrored-id.test.ts: real store. An opted-in mirrored id is kept, a duplicate throws, and the id is rejected without the opt-in.
    • Host-level repro against orcad: 19 of 19 checks pass on the branch. On main the method is unknown.
  • pnpm typecheck passes. oxlint and oxfmt pass on changed files. vitest passes on the related suites (store/terminals, web-runtime, terminal-pane-tab-detach, rpc session-tab, web-session-tabs-sync, main/runtime/headless, shared/terminal): 1547 tests.
    • I did not run the full pnpm lint or the whole pnpm test.

AI Disclosure

Written with Claude Code: Claude Opus 5.5 orchestrating, with Sonnet and Opus subagents for code tracing, implementation, review and the e2e repro. I reviewed the diff and ran the manual test.

Review

Door: two-way. Additive RPC plus a client path that falls back to today's behaviour. Revert is clean, and no persisted format changes.

Blast radius: paired-runtime pane moves.

  • Known limit, window-owned hosts: a host that runs the desktop app keeps its layout in its renderer, so it returns not_held and the bug remains there.
  • Known limit, possible flicker: a host snapshot that lands in the short gap between the optimistic move and the host commit can show the pane back in the source tab for one frame. The next snapshot moves it forward again. I did not observe this, but a busy host with agent-status traffic is the likely trigger.
  • Small side effect on fallback: agent status moved with the pane can be dropped when the mirrored tab is pruned.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, or docs.

Notes

  • Security: the RPC requires workspace permission and checks that the source tab is visible to the client. The host validates the request shape before any write. It refuses an existing target id and a leaf held by another tab.
  • Cross-platform: no platform-specific code.
  • Remote SSH: this is the remote path.
  • Mobile: not wired.
  • Backwards compatibility: a new client with an old host falls back. An old client with a new host never calls the RPC.

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 (e2e log evidence above; no recording)
  • 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
    • Left unticked because pnpm test fails here. It also fails on main.
    • On a Linux host, pnpm lint, pnpm typecheck and pnpm build pass on this branch.
    • pnpm test fails on this branch with 68 files / 101 tests. The same 68 files and 101 tests fail on its base 18555204 from main, run the same way. This branch adds no new failures.
    • The failures come from the environment, not from the code under test:
      • tests/e2e/cross-version-wire/*: needs release tags (v1.4.190) that a shallow clone does not have.
      • Real-git and shell tests.
      • fish node-pty tests.
      • config/scripts git-ref tests.

Moving a split pane to a new tab in a paired-runtime worktree changed only
the window store. The host never learned about the move, so the next host
snapshot rebuilt the old tab and the pane snapped back.

Add a session.tabs.movePaneToNewTab RPC that commits the move in the host
session through planTerminalLeafMove and republishes the session tabs.
For a mirrored host tab, the renderer applies the move first under the
mirrored id the host snapshot will use, then asks the host to commit it.
An older host or a refused move falls back to the old local-only move.

Fixes stablyai#32939
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: acb327ae-9a97-470c-9a6c-d7ba2b596602
📥 Commits

Reviewing files that changed from the base of the PR and between 810ffb2 and 710399d.

📒 Files selected for processing: 4
  • src/main/ipc/pty/ipc/leaf-move.ts
  • src/main/runtime/headless-move-leaf-to-new-tab.test.ts
  • src/main/runtime/rpc/methods/session-tab-mutation-methods.ts
  • src/main/runtime/session-tabs/headless-terminal-tab-close.ts

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

📝 Walkthrough

The change adds a workspace RPC and a headless runtime path for moving a terminal leaf between tabs. The renderer creates and validates mirrored host tab IDs, sends move requests to the host, and applies runtime-hosted pane detachment locally without waiting for the host response. Tests cover host move results, invalid requests, mirrored IDs, and renderer behavior when the host accepts or refuses a move.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 71039

The paired-runtime pane move is ready to merge after normal checks. The documented window-owned-host limitation remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: preserving pane moves to new tabs on paired runtimes.
Description check Passed The description is complete and directly addresses the template. It explains the user impact, implementation, rationale, linked issue, testing, limitations, compatibility, and checklist status. It als…
Linked Issues check Passed Linked issue #32939 requires that moving a split pane to a new tab persists on a paired runtime. The pane must stay in the new tab after a tab switch or agent output, and the runtime topology must rec…
Out of Scope Changes check Passed Every changed area in the summary connects to the #32939 objective of committing a pane-to-new-tab move on the host:
- New RPC session.tabs.movePaneToNewTab and its schema MovePaneToNewTab (`sessi…
Full details: Description check

Explanation

The description is complete and directly addresses the template. It explains the user impact, implementation, rationale, linked issue, testing, limitations, compatibility, and checklist status. It also clearly discloses that the full test suite and full lint were not completed.

Full details: Linked Issues check

Explanation

Linked issue #32939 requires that moving a split pane to a new tab persists on a paired runtime. The pane must stay in the new tab after a tab switch or agent output, and the runtime topology must record the move.

Evidence in the reviewed code:

  • Client: terminal-pane-tab-detach.ts calls moveWebRuntimeLeafToNewTab when the source tab mirrors a host tab and the pane has a PTY. The local move then uses the mirrored host tab ID.
  • Client RPC: web-runtime-leaf-move.ts calls session.tabs.movePaneToNewTab. An RPC failure maps to not_held.
  • Host RPC: session-tab-mutation-methods.ts registers the method and checks source tab visibility.
  • Host move: headless-terminal-tab-close.ts (read at the reviewed head) implements moveMobileSessionLeafToNewTab. It returns not_held only when an authoritative window exists. It validates the request, calls commit, and on moved rehydrates the headless snapshot and notifies listeners. The commit callback is supplied by commitLeafMoveAndRekey (leaf-move.ts), which uses the store's moveTerminalLeafToNewTab, the durable leaf move.

The host commits leaf membership, so a later snapshot no longer reverts the pane. The issue reports a paired Linux runtime, which is the headless host path. The window-owned host limit in the PR does not apply to the reported environment.

Author-reported evidence: a headless orcad end-to-end run and a 19/19 host-level repro. Headless tests cover the real planTerminalLeafMove. I did not run these tests.

Limit of this review: the incremental diff from 810ffb2 to 710399d could not be read because changed blobs are missing from the checkout. I confirmed the host method at the reviewed head. Client and test changes rely on the PR summary and the prior assessment. The prior PASS is preserved because the reviewed host path matches the described design.

Full details: Out of Scope Changes check

Explanation

Every changed area in the summary connects to the #32939 objective of committing a pane-to-new-tab move on the host:

  • New RPC session.tabs.movePaneToNewTab and its schema MovePaneToNewTab (session-tabs-schemas-params.ts, session-tab-mutation-methods.ts).
  • Host method moveMobileSessionLeafToNewTab and the optional RuntimeStore.moveTerminalLeafToNewTab property (headless-terminal-tab-close.ts, runtime-store-contract.ts).
  • commitLeafMoveAndRekey now takes a narrower store type (leaf-move.ts). This supports the new host commit path.
  • Client helper moveWebRuntimeLeafToNewTab and the detach branch (web-runtime-leaf-move.ts, terminal-pane-tab-detach.ts).
  • Mirrored tab ID support (terminal-tab-id.ts, terminal-actions.ts, terminal-tab-creation.ts). The mirroredHostTab flag is opt-in, so other createTab callers keep their current validation.
  • Tests for each of these paths.

I did not find a concrete unrelated change. The PR states that no persisted format changes. The ignored generated file rpc-params-catalog.generated.ts was not inspected, and its exclusion does not affect this verdict.

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

… writer

The layout-writer ratchet allows no new main-process layout writers. The
headless host now hands the move to commitLeafMoveAndRekey, the same
commit a local window uses, and keeps only the window check, validation,
rehydrate and notify.
@nwparker

Copy link
Copy Markdown
Contributor

Thank you, @bengry, for the clear report in #32939 and for this PR. Your diagnosis was right: the move has to be committed on the host, through the existing leaf-move writer. We've shipped it in #33027 with both of your commits kept as they were. On top, we added a capability gate for older hosts, host-side placement of the new tab (keeping the order of the other tabs), the live terminal record following the pane, and an undo when the host refuses or the reply is lost, plus a paired e2e. We're closing this PR in favour of #33027. Thanks again!

@nwparker nwparker closed this Oct 26, 2026
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]: Moving a split pane to a new tab reverts in paired-runtime worktrees; the runtime topology never gets the move

2 participants