Skip to content

fix: preserve host-owned terminal identity during first mount - #23785

Open
nwparker wants to merge 7 commits into
mainfrom
nwparker/ci-runtime-owned-null-projection-rerun
Open

nwparker wants to merge 7 commits into
mainfrom
nwparker/ci-runtime-owned-null-projection-rerun

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

fix: preserve host-owned terminal identity during first mount
---BODY---
Linux validation of the updated candidate is pending; do not merge yet. The initial candidate failed 2/8 Linux repetitions. The follow-up also handles unmounted panes omitted from the transport graph while still explicitly present in the renderer session.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​205
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​146

ELI5

Opening a workspace could create duplicate agent and Setup tabs even though their terminals were already running. Keep those terminals attached to their original panes while the screen catches up.

What Changed

The host preserves its existing terminal binding when the renderer publishes the same pane with an empty binding. It also retains an unmounted pane omitted from the transport graph when the renderer’s accepted current session still explicitly publishes that exact empty pane. Host-preserved session rows are excluded from that evidence. Preservation requires runtime ownership and an exact workspace, tab, and pane match. An explicit replacement, move to another pane, removed pane, or confirmed process exit still takes precedence.

Why

Linux binding traces showed activation creating extra tabs after an empty renderer projection made the host incorrectly report live terminals as orphaned. Fixing the host's ownership decision keeps all inventory readers consistent; delaying activation or weakening the identity assertions would leave the race intact.

Linked Issue

CI failure in live-background-terminal-mount-authority.spec.ts; baseline diagnostic run: https://github.com/stablyai/orca/actions/runs/36502710956 (five failures in eight runs).

Visual Proof

Before: Linux failure has five tabs after activation. After: macOS validation retains the three original tabs through input and remount checks. The unchanged E2E verifies exact tab, leaf, PTY, handle and process identity. Screenshots use different platform window sizes.

Before: duplicate terminal tabs

After: three original tabs and Setup input

Testing

  • Automated regression added: exact inventory equality across an empty projection (fails before the fix).
  • 1,365 runtime tests passed, one skipped; includes handle/incarnation fencing and removal, move, replacement, workspace mismatch, disconnected-host and confirmed-exit cases.
  • macOS hidden Electron first-mount authority E2E passed (18.3 seconds).
  • Node typecheck and changed-code quality gate passed; the extracted session-publication reader also passes all 18 targeted regression tests.
  • Repeated Linux E2E and PR checks pending.

Terminal contract: host ownership survives a temporary renderer projection gap; no duplicate spawn or reminted identity. The oracle is full terminal inventory equality plus unchanged E2E identity/input/output assertions. Existing agent-session.provider-ownership first-mount coverage is the gate. Windows and live SSH validation remain gaps; runtime tests cover incarnation fencing and unverifiable host contact.

Review

No wire fields or opcodes change. Older clients receive the same existing terminal identity instead of a false orphan. No local-only paths, Git assumptions, or new polling; folder workspaces use the same exact workspace comparison. Each sync builds transient linear-time indexes of explicit incoming bindings and accepted empty session panes. An explicit session removal, replacement, or move supersedes retention; unchanged snapshot publications retain the same exact handle.

Agent skill upstream boundary

  • Not applicable; no upstream skill content copied.

Checklist

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

Graph synchronization now uses runtime-owned terminal projection helpers to retain eligible PTYs and published panes. Added tests cover projection behavior across null publications, snapshot changes, replacement, removal, and orphan reporting. A comment identifies verdict frames as shared by journal translation and background-task projection.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to f962d

The change keeps host-owned terminals from being duplicated when a pane briefly publishes an empty binding, and no behavioral problem was found in review. One cosmetic comment fix is suggested. Linux E2E validation is still pending on the author's side.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to f962d

Exact ownership checks limit which terminals can be retained, and no security bypass was established. The updated behavior still needs Linux validation after an earlier candidate failed intermittently.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected authority is the runtime’s association of a live PTY with a pane and workspace, including the terminal state subsequently exposed to inventory and clients. The examined resolver does not select an arbitrary PTY from an empty publication.

Trust Boundaries and Controls

  • observed — Authoritative-window checks precede graph projection. Omitted-pane retention additionally requires accepted renderer identity and a uniquely matching runtime-owned PTY; incoming PTY IDs are excluded from retention.

Resilience and Maintainability Implications

  • observed — Confirmed process exit records an exited verdict and clears runtime ownership, preventing that record from authorizing later retention; unverifiable liveness is treated differently.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving host-owned terminal identity during the first mount.
Description check ✅ Passed The description is detailed and mostly follows the repository template. It includes the ELI5, change summary, rationale, visual proof, testing, review, boundary, and checklist sections. Linux validati…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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 (1)
src/main/runtime/orca-runtime-sync-window-graph.ts (1)

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

Restore the first lines of the two truncated comments.

This change deleted only the opening line of each comment block. Line 262 now starts with "the tab/leaf graph (handles/titles/connected resolve from leaf state)". Line 279 now starts with "newer, so a graph-only change must mint a fresh stored version". Neither comment has a subject, so both are incomplete. Restore the removed opening lines, or delete each block completely.

Also applies to: 279-279


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 67189d8d-28e1-4360-b696-327db814fcc3

📥 Commits

Reviewing files that changed from the base of the PR and between c5fc0c6 and f962d37.

📒 Files selected for processing (4)
  • src/main/codex/codex-structured-journal-provider-verdicts.ts
  • src/main/runtime/orca-runtime-sync-window-graph.ts
  • src/main/runtime/runtime-owned-terminal-projection.ts
  • src/main/runtime/terminal-list-surface-lost-orphan.test.ts

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

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Refactors terminal identity tracking during graph sync.

The PR should not merge until omitted-pane retention survives an unchanged-worktree resync triggered by a stale preserved tab.

Findings

  1. P1 Published pane loses its binding ▶

Summary

The PR retains host-owned PTY bindings when a renderer graph temporarily publishes an empty pane binding or omits an unmounted pane. It adds inventory regressions for retention, replacement, removal, and process exit.

  • The new omitted-pane path loses its publication evidence during a stale-preserved-tab resync, allowing a live terminal to become orphaned.

Reviews (1) · Last reviewed commit: "chore: retrigger pull request checks"

Comment on lines +101 to +105
const published = collectRendererPublishedEmptyTerminalPanes(
graph,
this.mobileSessionTabsByWorktree,
this.acceptedRendererMobileSnapshotByWorktree
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Published pane loses its binding When an unchanged worktree has both an unmounted, renderer-published empty pane and an unrelated host-preserved tab that has become stale, syncMobileSessionTabs deletes the worktree’s accepted renderer identity before this code collects empty panes. The collector skips the still-published pane. Because its leaf is absent from graph.leaves, the host then drops the live runtime-owned binding and invalidates its handle before the requested republish arrives. Republish cannot restore the old leaf while it remains unmounted, so the terminal is reported as orphaned again. Keep the pane’s publication evidence available during the resync.

Knowledge Base Used: Terminal runtime and interaction

This branch has not been deployed

No deployments
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