Skip to content

Fix remote-runtime terminal pane split authority - #13867

Merged
Jinwoo-H merged 3 commits into
mainfrom
bug-remote-runtime-workspaces-reject-terminal-pa
Aug 12, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
bug-remote-runtime-workspaces-reject-terminal-pa

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13743

Problem and invariant

A live terminal pane owned by the host's persisted workspace session must be splittable even when the host renderer has not mounted that tab. Conversely, a source pane that is not authoritatively owned must be rejected before a replacement PTY is spawned.

The remote-runtime CLI path previously spawned the new PTY and asked the host renderer to reveal/apply the split. For workspaces absent from that renderer's in-memory tab graph, the renderer rejected the tab lookup, causing the new PTY to be killed. A later stale one-leaf renderer replay could also overwrite an accepted main-process layout.

Although the report was captured on Windows, the failure is platform-neutral: it is a main/renderer ownership mismatch, not a Windows, ConPTY, filesystem, or window-lifecycle primitive.

Reproduction evidence

The same byte-identical authority test was run in all three states:

State Result
Affected latest-main behavior RED, 2/2 failed
Candidate fix GREEN, 2/2 passed
Candidate with source-authority fix disabled RED, 2/2 failed

On the final rebase onto origin/main at 444638d96b, the fix-disabled run again failed 2/2: the persisted-but-unmounted split consulted the renderer and spawned then killed its PTY, while the unowned source also spawned before rejection. Restoring the candidate returned the oracle to GREEN 2/2.

Command:

pnpm exec vitest run --config config/vitest.config.ts \
  src/main/runtime/orca-runtime-terminal-split-authority.test.ts

Design

  • Preflight the exact source authority in main from the persisted tab/layout/PTy binding, falling back to the mounted renderer graph or exact mobile projection only where appropriate.
  • Thread an expected source binding through PTY spawn and atomically CAS-check it in persistence before synchronously flushing the new binding.
  • Clean up the provider PTY if that CAS loses a concurrent close or identity change.
  • Commit persisted, unmounted splits in main without requiring renderer reveal; renderer adoption after commit is best-effort.
  • Advance terminal topology authority on split admission so stale one-leaf renderer snapshots cannot erase the committed split.
  • Replace the provisional admission leaf with the requested split direction without discarding concurrent sibling splits.

This keeps authoritative truth in the main-process session/persistence boundary, preserves the existing crash-ordering guarantee, and avoids a remote wire or persistence-schema change. A renderer-only patch would retain the spawn-before-validation race; routing every split through a transient mobile projection would use a non-authoritative surface and broaden coupling.

Risk and compatibility

The main risks are concurrent source close, persisted/live incarnation skew, normalized worktree keys, SSH host partitioning, and stale renderer replay. Tests cover those cases, including legacy sessions without a persisted incarnation. No remote protocol opcode/field, storage schema, Git behavior, provider-specific behavior, or UI styling changes are introduced. Folder workspaces, git worktrees, local hosts, SSH hosts, Windows/macOS/Linux behavior, and mixed client/server versions retain their existing interfaces.

Validation

On the final merge base:

  • Authority oracle: 2 passed; fix-disabled leg 2 failed as expected
  • Focused main-process suite: 2,032 passed, 1 skipped across 5 files
  • Electron Playwright CDP split right/down/persisted-binding scenarios: 3 passed
  • pnpm run typecheck:node
  • pnpm run check:code-quality:changed
  • pnpm run check:max-lines-ratchet
  • pnpm run check:reliability-gates
  • git diff --check

Fresh architecture/adversarial, platform/performance/security, and readiness/UX reviews completed cleanly after addressing source CAS/crash ordering, renderer-mount adoption, legacy-incarnation compatibility, and stale-replay fencing.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 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: Pro Plus

Run ID: 691f5887-0c55-46e6-b903-0548600e7ad8

📥 Commits

Reviewing files that changed from the base of the PR and between 444638d and a658867.

📒 Files selected for processing (9)
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/headless-terminal-split-layout.test.ts
  • src/main/runtime/headless-terminal-split-layout.ts
  • src/main/runtime/orca-runtime-terminal-split-authority.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/main/persistence.test.ts
  • src/main/runtime/headless-terminal-split-layout.ts
  • src/main/runtime/headless-terminal-split-layout.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime-terminal-split-authority.test.ts
  • src/main/ipc/pty.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/persistence.ts
  • src/main/ipc/pty.test.ts

📝 Walkthrough

Walkthrough

Terminal split creation resolves source authority across persisted, mounted, and projected terminal state. Persistence validates source tab, worktree, leaf, PTY, and incarnation data before admitting bindings. PTY startup propagates expected source metadata and reports terminal_split_source_not_found for stale sources. Headless layouts replace provisional leaves while preserving concurrent siblings. Runtime flows order persistence, reveal, remote publication, and cleanup for failed creation. Tests cover local, SSH, renderer, remote, stale, and concurrent split scenarios.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. 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 #13743 by validating split authority, preventing premature PTY creation, preserving layouts, and handling remote-runtime workspaces.
Out of Scope Changes check ✅ Passed The implementation and tests remain focused on remote-runtime terminal split authority, persistence validation, PTY cleanup, and stale layout protection.
Title check ✅ Passed The title clearly identifies the main change: fixing terminal pane split authority for remote runtimes.
Description check ✅ Passed The description explains the problem, design, risks, linked issue, testing, and validation with sufficient detail.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

🧹 Nitpick comments (2)
src/main/runtime/headless-terminal-split-layout.test.ts (1)

155-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert mapping values instead of key order.

Object.keys(...) compared with toEqual pins the insertion order of ptyIdsByLeafId. Key order is an implementation detail of how the map is rebuilt, not part of the split-layout contract. A later refactor that reorders the spread would fail this test without any behavior change. The test also does not assert that leaf-c is rebound from provisional-pty to pty-c, which is the point of this scenario.

♻️ Proposed assertion change
     expect(countTerminalLayoutLeaves(next.root)).toBe(3)
-    expect(Object.keys(next.ptyIdsByLeafId!)).toEqual(['leaf-a', 'leaf-b', 'leaf-c'])
+    expect(next.ptyIdsByLeafId).toEqual({
+      'leaf-a': 'pty-a',
+      'leaf-b': 'pty-b',
+      'leaf-c': 'pty-c'
+    })
src/main/persistence.ts (1)

6792-6808: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value

Consider binding the source expectation to the target tab.

The validation confirms the source tab, leaf, PTY, and incarnation. It does not confirm that args.tabId equals expected.tabId. The write path below uses bindingWorktreeId, which is derived from the source expectation, for tab lookup, minimal tab creation, and the active-tab bookkeeping. If a future caller passes a source expectation from one tab while binding a leaf into a different tab, this method would create that unrelated tab inside the source worktree and advance the source repo's topology fence.

The current runtime caller passes the same parentTabId for both, so this is defensive only.

🛡️ Proposed guard
     if (args.expectedSourceBinding) {
       const expected = args.expectedSourceBinding
+      if (expected.tabId !== args.tabId) {
+        return false
+      }
       const sourceTab = session.tabsByWorktree?.[bindingWorktreeId]?.find(

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe0156e0-bce1-4b17-a26e-ec9e853040c0

📥 Commits

Reviewing files that changed from the base of the PR and between 842641a and 3c922d6.

📒 Files selected for processing (9)
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/headless-terminal-split-layout.test.ts
  • src/main/runtime/headless-terminal-split-layout.ts
  • src/main/runtime/orca-runtime-terminal-split-authority.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

@Jinwoo-H
Jinwoo-H force-pushed the bug-remote-runtime-workspaces-reject-terminal-pa branch from a427d9a to d8cfee4 Compare August 11, 2026 22:20
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H
Jinwoo-H force-pushed the bug-remote-runtime-workspaces-reject-terminal-pa branch from d8cfee4 to bce911d Compare August 11, 2026 23:00

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b7c25f9-39ae-4b73-b635-656c7f02be90

📥 Commits

Reviewing files that changed from the base of the PR and between d8cfee4 and bce911d5c200efcc33cff35502ac9f60e89529c1.

📒 Files selected for processing (4)
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/ipc/pty.ts
  • src/main/ipc/pty.test.ts
  • src/main/runtime/orca-runtime.test.ts

Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H
Jinwoo-H force-pushed the bug-remote-runtime-workspaces-reject-terminal-pa branch from 580ee22 to a379dfc Compare August 11, 2026 23:35
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H
Jinwoo-H force-pushed the bug-remote-runtime-workspaces-reject-terminal-pa branch from a379dfc to a658867 Compare August 12, 2026 02:18
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Jinwoo-H
Jinwoo-H merged commit 7a58f72 into main Aug 12, 2026
44 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 13, 2026
* fix(runtime): preserve remote terminal pane splits

* test(runtime): tighten split authority guards

* fix(runtime): revalidate transient split sources

---------

Co-authored-by: E2E Test <[email protected]>
(cherry picked from commit 7a58f72)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(runtime): preserve remote terminal pane splits

* test(runtime): tighten split authority guards

* fix(runtime): revalidate transient split sources

---------

Co-authored-by: E2E Test <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant