Skip to content

fix(terminal): remove split panes the host retired from a remote-server tab - #18387

Closed
ylcn91 wants to merge 5 commits into
stablyai:mainfrom
ylcn91:fix/remote-split-pane-close
Closed

ylcn91 wants to merge 5 commits into
stablyai:mainfrom
ylcn91:fix/remote-split-pane-close

Conversation

@ylcn91

@ylcn91 ylcn91 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

In a tab that runs on a paired remote Orca runtime, closing one half of a split terminal left an empty pane behind, and closing that empty pane killed the terminal that was still alive. Now the empty pane goes away on its own and the surviving terminal stays.

What Changed

  • terminal-live-layout-reconciliation.ts: trackRetiredLeafIds remembers the leaves the host named and then dropped while their panes are still mounted (a leaf the host never named belongs to a pane the client is still starting; a retired leaf stays pending until its pane is gone, so a removal skipped while the transport still held its PTY is retried after the exit). planTerminalLiveLayoutRemovals turns those into removals, and selectRetiredPaneIds decides which panes to close: only a pane whose transport has no PTY, never the last pane on the tab.
  • use-terminal-pane-reconciliation.ts: the host-authoritative branch applies those removals after insertions, through executeClosePane, so a retired pane gets the same cleanup a user close does (cache timer, agent status, terminal error, restored-session banner, pty binding).
  • Tests for both planners.

Why

The client sends terminal.close for the pane and drops the leaf from its layout, but the host still sees two live surfaces at that moment, so rebaseLayout refuses the membership change and republishes the two-leaf layout, and the live-layout reconciler faithfully re-inserts a pane for the retired leaf. When the host's onPtyExit then retires the leaf and publishes a one-leaf layout, the store shrinks, but the reconciler only planned insertions, so the pane stayed mounted with no PTY and no close control. Its next close request resolved to the live sibling.

Planning removals alongside insertions closes that gap. Guarding on "transport has no PTY" and "never the last pane" keeps a stale snapshot from tearing down a live split.

Linked Issue

Fixes #17770

Visual Proof

Before, split then one pane closed: a blank ghost pane stays and the next close takes the live terminal with it.

before: split
before: ghost pane after closing one side

After, same steps: the closed pane disappears and the other terminal keeps running.

after: split
after: one pane left after closing one side

Testing

Reproduced against a headless orca serve (Linux AppImage) on Ubuntu 24.04, paired over an SSH tunnel ("Add remote server" with the printed pairing URL and the SSH-tunnel option); client on macOS.

  1. Open a terminal tab in the remote-server workspace and split it; run a process in each half.
  2. Close one pane. Before: a blank pane stayed, the DOM had two .pane nodes while the store held one leaf and orca terminal list on the host listed one terminal; closing the blank pane closed the surviving terminal too. After: one pane, one leaf, one terminal, and only the closed pane's process ended.
  3. The same steps over an "Add SSH host" connection were already correct on v1.4.193 and main; that path is not touched.
  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

vitest for terminal-live-layout-reconciliation.test.ts, pnpm tc:web, oxlint, oxfmt --check and check:code-quality:changed pass; the CI workflow's lint, typecheck and test jobs were run locally on this branch. Platforms: macOS client, Linux remote runtime.

AI Disclosure

Claude Code (Fable 5.1) drafted the diagnosis, the patch and the tests. I set up the remote runtime, reproduced the bug, reviewed the change and verified it live against the running app and the host.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Only the remote-server (paired runtime) reconciliation path changes; local and "Add SSH host" tabs never take the host-authoritative branch with a retired leaf.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

…er tab

Closing one pane of a split terminal in a remote-server (paired Orca
runtime) tab left a blank ghost pane behind, and closing again from
that state killed the surviving terminal too, so the whole split was
lost.

The client sends `terminal.close` for the pane and drops the leaf from
its layout, but the host still sees two live surfaces at that moment,
so `rebaseLayout` refuses the membership change and republishes the
two-leaf layout. The live-layout reconciler faithfully re-inserts a
pane for the retired leaf. When the host's `onPtyExit` then retires
the leaf and publishes a one-leaf layout, the store shrinks but the
reconciler only planned insertions, so the pane stayed mounted with no
PTY, no close control, and no way out. Its next close request resolved
to the live sibling.

Plan removals alongside insertions: a mounted pane whose leaf the
host-authoritative layout no longer names, and whose transport has no
PTY, is closed. The last pane is never removed, and a pane still bound
to a PTY is left alone so a stale snapshot cannot tear down a live
split.

Reproduced against a headless `orca serve` on Ubuntu 24.04 paired over
an SSH tunnel: before the change the DOM kept two `.pane` nodes while
the store held one leaf and the host listed one terminal; after it,
one pane, one leaf, one terminal, and the closed pane's process alone
ended. The same steps over an "Add SSH host" connection were already
correct on both v1.4.193 and main.

Fixes stablyai#17770
@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 3066c3e9-6422-4a1b-8feb-a4689441f3ce

📥 Commits

Reviewing files that changed from the base of the PR and between 03d8158 and da016a9.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts

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


📝 Walkthrough

Walkthrough

The change persists retired leaf IDs across reconciliations. A host-dropped leaf remains pending while its pane still has a PTY. The reconciliation effect plans removal again after the PTY clears. It skips leaves that the host never named and preserves the final pane. Tests cover retirement tracking, PTY states, missing panes, and teardown ordering.

Merge Risk: ⚪ Minimal · up to da016

This change reconciles remotely retired terminal panes only after their PTY is gone, preserving the remaining terminal and preventing blank retired panes. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #17770 by removing the retired remote pane while preserving the surviving pane and its active terminal session. The implementation and tests cover the reported reconciliation…
Out of Scope Changes check ✅ Passed The changes are limited to remote terminal layout reconciliation, pane removal handling, and related tests. No unrelated code or objectives are included.
Title check ✅ Passed The title clearly and concisely identifies the main change: removing host-retired split panes from remote-server tabs.
Description check ✅ Passed The description is complete and relevant. It includes the required ELI5, change summary, rationale, linked issue, visual proof, testing details, AI disclosure, scope notes, and completed checklist ite…
Full details: Linked Issues check

Explanation

The changes address issue #17770 by removing the retired remote pane while preserving the surviving pane and its active terminal session. The implementation and tests cover the reported reconciliation failure.

Full details: Description check

Explanation

The description is complete and relevant. It includes the required ELI5, change summary, rationale, linked issue, visual proof, testing details, AI disclosure, scope notes, and completed checklist items.

  • Fix all pre-merge checks with AI

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: Team

Run ID: 10282a63-27de-4fce-a9a8-3aa2ad8b6429

📥 Commits

Reviewing files that changed from the base of the PR and between d05dd8e and b1d1124.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pullfrog pullfrog 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.

ℹ️ No critical issues — one coverage note and a minor reuse nit.

Reviewed changes

  • planTerminalLiveLayoutRemovals — new planner returning mounted leaves the host-authoritative layout no longer names.
  • use-terminal-pane-reconciliation — the host-authoritative branch removes ghost panes after insertions, guarded on the pane owning no PTY and never removing the last pane.
  • collectLeafIds — a Set-based tree walk feeding the new planner.
  • Tests — three cases for the planner covering a retired leaf, an all-mounted layout, and a null/empty layout.

ℹ️ Removal guards have no hook-level coverage

The bug being fixed lives in use-terminal-pane-reconciliation — the transport.getPtyId() === null and getPanes().length <= 1 guards are what keep a stale snapshot from tearing down a live split. The added tests only exercise the pure planner, so the two guards that actually decide whether to close a pane are unverified by automation. The planner tests are meaningful and would fail on a wrong set diff, but a regression in the guards (e.g. dropping the last-pane check, or the no-PTY check) would ship silently.

Technical details
# Cover the removal-path guards

## Affected sites
- src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts:90-99 — closePane guard conditions

## Required outcome
- A test (or tests) that exercise the removal loop with a fake manager/transport, asserting: a pane whose transport reports a non-null ptyId is NOT closed; the last remaining pane is NOT closed; a PTY-less ghost among >1 panes IS closed.

## Open questions for the human
- Is a renderer hook harness for this reconciliation path already available, or would this need a new fixture? If the hook is impractical to unit-test, a comment stating the guards are covered by the live remote-server scenario (as done in the PR body) may suffice.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

`manager.closePane` only tears down the pane and its transport. A pane
retired by the host also owns a cache timer, an agent status, a terminal
error slot and a restored-session banner, all keyed by the pane, which a
bare close left behind. Route the removal through `executeClosePane`, the
same path a user close takes.

The selection rules move into `selectRetiredPaneIds` so they can be tested
on their own: only a pane whose transport has no PTY is closed, a pane with
no transport yet or still bound to a PTY is left alone, and the last pane on
the tab is never removed.
…anner

The planner grew its own recursive leaf walk; `collectLeafIds` in terminal-pane-layout-tree.ts already does this and handles an empty root.

@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: Team

Run ID: a018b44b-4ae4-4532-a146-ac6a08994345

📥 Commits

Reviewing files that changed from the base of the PR and between b1d1124 and c7ee34f.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

A transport reports no PTY both after its PTY ended and before its spawn
has connected, so "mounted, unnamed by the host, no PTY" also describes a
pane the client just split. A host snapshot landing in that window would
have closed it.

Remember the leaves of the last host-authoritative layout and plan a
removal only for a leaf that set contained: the host can only retire a
leaf it named. A leaf it has never named belongs to a pane still starting.

@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: Team

Run ID: f243f0b3-e437-4706-85e5-3982cdadc5b9

📥 Commits

Reviewing files that changed from the base of the PR and between 42dea7a and 03d8158.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-reconciliation.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-live-layout-reconciliation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

…oved

The host drops a leaf and ends its PTY in one step, but the two reach the
client separately. When the layout arrives first, the pane still holds its
PTY and the removal is rightly skipped; remembering only the previous
layout's leaves then forgot the leaf, so the pane stayed mounted blank
after the exit landed.

Track retired leaves explicitly: a leaf the host named before and no
longer names stays retired until its pane is gone or the host names it
again. The exit rewrites the layout's pty bindings, which re-runs the
reconciliation, and the pending leaf is removed then.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • selectRetiredPaneIds — extracted the removal-guard logic (no-PTY, never-last-pane, skip-unmounted-leaf) into a pure selector with four unit cases.
  • Full close cleanup — the host-authoritative reconciliation branch now closes retired panes through executeClosePane, running the same cache-timer/agent-status/terminal-error/banner/pty-binding cleanup a user close performs.
  • collectLeafIds reuse — dropped the local Set-based leaf walk in favor of the shared collectLeafIds from terminal-pane-layout-tree.ts.

Both concerns from the prior review are addressed: the removal guards are now exercised directly, and the leaf-collector duplication is gone. The selectRetiredPaneIds tests assert exact results and would fail if either guard regressed.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • trackRetiredLeafIds — new pure tracker that retires a mounted leaf only when the host named it in a prior layout and then dropped it, and keeps it retired until its pane is gone or the host names it again.
  • planTerminalLiveLayoutRemovals — now gates removals on the tracked retirement set, so a mounted leaf the host never named (a client split still spawning) is no longer mistaken for a ghost.
  • Reconciliation state — the hook carries hostLayoutLeafIdsRef / retiredLeafIdsRef between runs so a host retirement that lands before the transport teardown is retried once the PTY clears.

This closes the "stale snapshot tears down a spawning pane" hole the previous iteration left open, and the added trackRetiredLeafIds and mid-spawn/pre-teardown race tests assert exact results.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

nwparker added a commit that referenced this pull request Sep 8, 2026
#19365)

Adds the missing removal path to the host-authoritative layout reconciler, so a pane the host has retired is unmounted once its PTY has cleared. Fixes #17770.

The removal planner, its retired-set gate, the null-PTY guard, the never-last-pane guard and their unit tests originate from #18387 by @ylcn91. This PR adds the recovery-state dependency that makes the deferred removal actually re-run, an e2e regression spec, and a hook-parity repin.

Co-authored-by: ylcn91 <[email protected]>
@nwparker

nwparker commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Thank you for this — your diagnosis was correct and the design is yours. The removal planner, the retired-set gate, the null-PTY guard and the never-last-pane guard all landed essentially as you wrote them.

We merged it in #19365 with you credited as co-author, because that branch had also picked up three things this needed: the ptyRecoveryStatesByPaneId dependency, an e2e regression spec, and a hook-order parity repin.

That first one is worth explaining, since it's a real gap rather than a preference. Your comment says a deferred removal "is retried after the exit ... once the exit lands and rewrites the layout bindings" — we measured that the rewrite never happens: clearExitedPanePtyLayoutBindingForLeaf early-returns because the host has already dropped that binding when it shrank the layout, so nothing re-runs the effect and the ghost stays mounted. Adding the recovery-state dep is what makes your removal path actually fire.

Also worth flagging for the future: this branch was latently CI-red on the hook-order parity test (expected [ Array(209) ] to have a length of 207) from the same two useRefs. Nothing reported it because fork PRs need workflow approval, so no checks ever ran here — not your fault, but useful to know when a fork PR looks green because it's actually silent.

Closing in favour of #19365. Thanks again — this was a real bug and you found the right fix for it.

@nwparker nwparker closed this Sep 8, 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]: Closing a split pane terminates the entire split terminal session in remote workspace

2 participants