Skip to content

refactor(pty): one commit step for both terminal start lanes - #31596

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/conv-c5e2-spawn-commit
Oct 22, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/conv-c5e2-spawn-commit

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​771 $\color{#cf222e}{\Huge{\mathbf{−}}}$​704 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67

ELI5

A terminal in Orca can be started two ways: by the desktop window (a new tab or split), or by the host process (the phone, a restore, orchestration, the CLI, SSH). Each way had its own copy of the "finish starting this terminal" step: save which pane owns it, register its handle, set its size, record the Codex account, publish telemetry, memory and resume identity, then reply. The two copies had drifted into different orders, and every fix to one had to be repeated in the other. This PR gives both ways one shared step.

What Changed

Before: two separate commit bodies, ipc/spawn-commit.ts + spawn-commit-persist.ts for the window and runtime/spawn-commit.ts + spawn-commit-pty-size.ts for the host, each running the same steps in a different order.

After: one shared commit, commitPtySpawn in src/main/ipc/pty/spawn-commit-assembly.ts, with its publication steps in spawn-commit-publication.ts and binding persistence in spawn-commit-binding.ts. Both lanes are now thin adapters that pass their lane's facts as data.

What a user sees does not change: same terminals, same folders, same notices, same reconnect behavior.

The shared commit step now carries #31908's existing resume-outcome callback and unavailable-resume fact for host starts, preserving behavior.

Mechanism. The shared commit takes three behavior inputs and nothing else:

  • hiddenDelivery: whether the renderer-scoped hidden-delivery transition runs here;
  • earlyExit: whether an early exit is drained by the window or thrown to the host caller;
  • joinPayload: what a joining reservation receives.

Everything else is plain data from the adapter: the binding to save with its refusal message, the registration target, the pane key and aliases, the memory session id, and the Codex launch environment. There is no lane flag, order flag or callback hiding a mode.

Order. The two lanes now share one order:

  • note commit → Codex pane account → hidden-delivery transition (window) → handle registration → size set and screen reflow → serializer readiness;
  • then telemetry → pane key and aliases → memory → resume identity → inventory → Codex lifecycle → reply.

The host records the Codex account earlier than before, and the window reflows right after the size is set. A read/write audit of every moved step shows no step reads what a moved neighbour writes, and none adds an await.

Why

The common pattern gives each terminal one creation operation that every caller goes through. A full move to that shape would also change admission, delivery and presentation, which are owned by later work. So this PR unifies only the commit, the part both lanes already share, and leaves the rest as it is on main.

Differences from the common pattern:

  • Intended: with the layout-owner switch on, a window start that a later runtime-create claim waits on now records its accepted result for that waiter, the same as a host start.
  • Intended: stable-owner adoption keeps its own shared path (pane/complete-pane-adoption.ts). It is a different outcome with its own publications, not a second fresh-spawn commit.
  • Intended: the host's post-commit hidden-delivery step stays at its current await boundary in runtime/spawn.ts. Moving it inside the shared commit would run it earlier than a replacement spawn waiting on the same pane.
  • Temporary: memorySessionId keeps the caller-specific value because unifying it changes what consumers receive. One begin/execute owner will derive the value and remove the separate earlyExit and joinPayload policies; tracked in STA-11756.
  • Temporary: codexLaunchEnv keeps the caller-specific launch environment because unifying it changes what consumers receive. It goes away when window starts move onto the host start path; tracked in STA-11757.
  • Intended: a window start without a saved pane binding publishes before the shared commit first yields; a host start with a saved pane binding reaches registration after one additional promise continuation. Exact timing for each caller would require a separate scheduling policy or moving the shared save and failure handling. The inspected production reservations still settle after the awaited start and the host hidden-delivery step. The queued restore seed stays ahead of resize on the same terminal write chain, and the next queued durable mutation remains after registration. No changed user result was reproduced in these bounded traces. Successful adopted-session claims preserve their prior return boundary.

Linked Issue

Tracked in the terminal launch-convergence sequence, step C5e-2 (commit unification).

Visual Proof

Main-versus-branch screenshots from the final-head Windows and M4Air/iOS QA runs are in Testing below. All published images were cleared for public sharing.

Testing

  • The layout-owner dark path ships to no user; covered by tests. With ORCA_LAYOUT_OWNER=main, the final-head named run passed 20 files / 312 tests, including the regression that checks resume reporting before the binding is saved (runtime/spawn-commit-run-facts.test.ts:102). It has no runtime QA arm under the lane owner’s QA ruling. Default-build QA passed on 08d69ce8ebb2 against main ea60ec5d7cb9 on Windows and M4Air with the iOS simulator.

  • Automated tests: the existing commit, size, hidden-delivery, parity, persistence, pane and stable-owner suites pass (43 files, 509 tests). One launch-record test was added, pinning that a tab is withdrawn and nothing spawns when the launch record can't open.

  • Review fix verification at 5a722c867476: 8 targeted files, 74 tests, covering both commit lanes, adopted claims, size, handles, failures and hidden delivery.

  • Real QA on the final head: Windows and M4Air/iOS main-versus-PR comparisons passed for window and host starts, hidden query replies/reveal/reload, dead-owner recovery, splits and selection/focus, early agent tabs, real Codex restart in place, Codex and Claude resume after an app restart with real replies, OpenCode one-time startup prompt/adopted attach, phone output/input, native ConPTY, exit lifecycle and deleted-folder fallback. No user-visible difference was found between the default builds.

  • Exact-head CI: full PR checks (static analysis/typecheck, five test shards, relay, cross-version wire, Linux/Windows packages) and headless persistence passed. Final integration targeted tests covered 20 unique named files, 623 passing executions and five existing skips across default and enabled configurations.

  • Runtime limits: a host refusal before start could not be induced on either build; its early-exit contract is covered by the launch-race, commit-facts and exit-durability tests in CI. The default host exit experiments instead kept the exited tab initially on both builds; Windows exited tabs disappeared after reload on both builds. OSC 11 colour replies were not remeasured this round. Windows configured-shell routing was masked by per-tab overrides; typed exits covered Windows and configured-shell exits covered M4Air. SSH/relay failure scenarios and Linux were inspected in source, not exercised in this QA run. The unshipped layout-owner banner path has tests only, as described above.

Screenshots (main ea60ec5 on the left, PR 08d69ce on the right)

Row 1: window terminal survives a renderer reload, same shell process (Windows)

main PR
main-row1-reload.png pr-row1-reload.png

Row 2: real Codex restart in place, then Codex resumes after an app restart with a real reply (M4Air)

main PR
main-row2-clean-resume-codex-final-visible.png pr-row2-clean-resume-codex-final-visible.png

Row 2: real Claude conversation resumes after the app restart with a real reply (M4Air)

main PR
main-row2-clean-resume-claude-final-visible.png pr-row2-clean-resume-claude-final-visible.png

Row 4: hidden host terminal restored on reveal after a reload (Windows)

main PR
main-row4-reveal.png pr-row4-reveal.png

Row 5: CLI split + early agent tab appended unselected (M4Air desktop)

main PR
main-row5-desktop-agent-early.png pr-row5-desktop-agent-early.png

Row 5: phone sees the agent reply (M4Air, iOS simulator)

main PR
main-row5-phone-agent-reply.png pr-row5-phone-agent-reply.png

Row 5: line typed on the phone reaches the terminal

main PR
main-row5-phone-input.png pr-row5-phone-input.png

Row 6: dead terminal owner, hidden restored pane gets a fresh shell on reveal (Windows)

main PR
main-row6-fresh.png pr-row6-fresh.png

Row 7: program exits before start finishes; tab kept showing exit code 1 (M4Air)

main PR
main-activation1-row7-activation.png pr-activation1-row7-activation.png

Row 7: host-created terminal with an exiting shell, tab kept with exit 1 (M4Air)

main PR
main-row7-proof-row7-host.png pr-row7-proof-row7-host.png

Row 8: Windows native ConPTY window tab answers DA1

main PR
main-row8-window.png pr-row8-window.png

Row 9: real OpenCode adopted session attaches without a fresh startup prompt (Windows)

main PR
main-row9-rerun-adopted.png pr-row9-rerun-adopted.png

Row 10: deleted folder falls back to the workspace root with the notice (Windows)

main PR
main-row10-missing-folder.png pr-row10-missing-folder.png

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

Cross-platform, SSH and mixed-version behavior is unchanged: no new saved field, wire operation or capability.

Author: @BrennanKB5

Review path: full, because this changes process-start ordering, pane persistence and lifecycle across desktop and host callers.

The window's pty:spawn commit and the host runtime controller's commit were two
copies of the same job (ownership, binding save, registration, size, hidden
mark, publication, reservation settle), so every fix had to land twice.

Both lanes now call one commitPtySpawn and supply what differs as data: the
binding each lane builds, its registration facts, pane key and aliases, the
Codex launch env and memory session id. Three inputs still select behavior:
hiddenDelivery (the renderer-scoped mark is refreshed here; the runtime-owned
mark stays at the host runner's await boundary), earlyExit (the window drains an
exit during start, the host throws) and joinPayload (what reservation joiners
and the caller receive).

One publication order for both lanes: note commit, Codex pane account, renderer
hidden mark, handle, size set with reflow, old-id size cleanup, serializer
readiness, restore records, command detector, telemetry, pane key and aliases,
memory registry, resume identity, inventory, Codex lifecycle, settle. Every
moved step was audited for read/write independence. Stable-owner adoption and
the adopted-claim publication set are unchanged.

Also pins that an agent launch whose record cannot open takes its tab back and
spawns nothing, and re-labels three TEMPORARY comments to their current owners.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 21, 2026 22:41
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

IPC and runtime PTY spawn paths now delegate commit work to shared assembly, with separate helpers for pane-binding persistence and committed-spawn publication. The changes also add pane-key normalization and update runtime join-payload construction. Tests cover pane reservation ordering, resume-outcome reporting during persistence, and launch-record store failure after tab publication.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 08d69

This refactor merges the window and host terminal-start commits into one shared step. For adopted agent sessions with the main layout owner enabled, the pane-create notification is no longer sent, so the view needs an extra attach round trip. Behavior stays correct. Restore the notification before or shortly after merge.

Pre-merge checks: Passed 4 · Failed 1

Failed 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 24 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 main change: consolidating both terminal start lanes into one commit step.
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.
Description check Passed The description is detailed and covers the change, rationale, testing, visual proof, scope boundaries, and compatibility considerations. The Linked Issue section does not provide the required actual i…
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, visual proof, scope boundaries, and compatibility considerations. The Linked Issue section does not provide the required actual issue reference or Fixes # entry, and the repository checklist is not included, but the description is otherwise complete and relevant.

✨ 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: 01f7e6ac-c87c-4acc-a09d-bbd5be0010cc
📥 Commits

Reviewing files that changed from the base of the PR and between 15b2cd5 and a3dbf05.

📒 Files selected for processing: 15
  • src/main/ipc/pty/delivery/attached-pty-size.ts
  • src/main/ipc/pty/ipc/spawn-commit-persist.ts
  • src/main/ipc/pty/ipc/spawn-commit.ts
  • src/main/ipc/pty/ipc/spawn-options.ts
  • src/main/ipc/pty/pane/key-state.ts
  • src/main/ipc/pty/pane/stable-owner.ts
  • src/main/ipc/pty/runtime/spawn-commit-pty-size.ts
  • src/main/ipc/pty/runtime/spawn-commit-response.ts
  • src/main/ipc/pty/runtime/spawn-commit.ts
  • src/main/ipc/pty/spawn-commit-assembly.ts
  • src/main/ipc/pty/spawn-commit-binding.ts
  • src/main/ipc/pty/spawn-commit-publication.ts
  • src/main/ipc/pty/spawn-host-env.ts
  • src/main/ipc/pty/spawn-options-assembly.ts
  • src/main/runtime/rpc/methods/agent-launch-instant-tab.test.ts
💤 Files with no reviewable changes: 2
  • src/main/ipc/pty/runtime/spawn-commit-pty-size.ts
  • src/main/ipc/pty/ipc/spawn-commit-persist.ts

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

@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/rpc/methods/agent-launch-instant-tab.test.ts: 1

497-512: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert both pane withdrawal callbacks.

The test checks only the internal { kind: 'withdrawn' } verdict. It can pass if the external callbacks are omitted. Since this suite runs for both window and main layout owners, assert reportAgentLaunchPaneVerdict for both cases and withdrawAgentLaunchPaneInMainLayout for the main-owner case.

Suggested fix
       expect(runtime.createTerminal).not.toHaveBeenCalled()
       await expect(verdicts[0]).resolves.toEqual({ kind: 'withdrawn' })
+      await vi.waitFor(() =>
+        expect(runtime.reportAgentLaunchPaneVerdict).toHaveBeenCalledWith(
+          { worktreeId: 'wt-7', tabId: TAB_ID, leafId: LEAF_ID },
+          { kind: 'withdrawn' }
+        )
+      )
+      if (owner === 'main') {
+        expect(runtime.withdrawAgentLaunchPaneInMainLayout).toHaveBeenCalledWith({
+          worktreeId: 'wt-7',
+          tabId: TAB_ID,
+          leafId: LEAF_ID
+        })
+      }

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5918b148-d1f3-487d-9459-b66061b52fdd
📥 Commits

Reviewing files that changed from the base of the PR and between a3dbf05 and ef2bf45.

📒 Files selected for processing: 2
  • config/main-layout-writer-baseline.txt
  • src/main/ipc/pty/spawn-commit-assembly.ts

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

…2-spawn-commit

# Conflicts:
#	src/main/ipc/pty/runtime/spawn-commit-response.ts

@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: 647daaa3-f2e2-4996-8cda-444f6851247a
📥 Commits

Reviewing files that changed from the base of the PR and between ef2bf45 and 1aa6b4e.

📒 Files selected for processing: 3
  • src/main/ipc/pty/ipc/spawn-commit-run-facts.test.ts
  • src/main/ipc/pty/runtime/spawn-commit-response.ts
  • src/main/ipc/pty/spawn-commit-publication.ts

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

…2-spawn-commit

# Conflicts:
#	src/main/ipc/pty/runtime/spawn-commit-response.ts
#	src/main/ipc/pty/runtime/spawn-commit.ts

@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
  • 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: c1a39e7c-0900-4193-98a4-d690f52f36c9
📥 Commits

Reviewing files that changed from the base of the PR and between 1aa6b4e and 08d69ce.

📒 Files selected for processing: 4
  • src/main/ipc/pty/runtime/spawn-commit-response.ts
  • src/main/ipc/pty/runtime/spawn-commit-run-facts.test.ts
  • src/main/ipc/pty/runtime/spawn-commit.ts
  • src/main/ipc/pty/spawn-commit-assembly.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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Window and host terminal starts had separate copies of the final save, registration and publication steps. They had drifted into different orders, making fixes easy to apply to only one entry point. This PR gives both entry points one shared commit while retaining their existing start, restore and reply behavior.

The full review loop is complete on 08d69ce8ebb2e0141a2cd37b2cc701876a1aa7af after two rounds and narrow checks of the authorized main integrations. The review removed an optional handle-registration guard, restored the adopted-session return boundary, corrected the extracted type contract and moved the existing persistence allowances with their code. Final source review found no confirmed remaining defect caused by this PR. Stable-owner adoption stays separate, all hidden-delivery mark sites remain, and there are exactly three behavior inputs. Production additions are 771 including the moved baseline allowance, below the 1,000-line stop; test additions are 80.

Real QA compared this exact head with main ea60ec5d7cb9b542d2b5b3fd986acfc8861e4560, using default builds on Windows and M4Air with an iOS simulator. The compared flows passed: window/host terminals, hidden queries and reveal/reload, dead-owner recovery, splits and focus, early agent tabs, phone output/input, native ConPTY, exit lifecycle, deleted-folder fallback, Codex restart in place, Codex and Claude resume after an app restart with real replies, and OpenCode startup/adopted attach. No user-visible difference was found between the default builds. QA used state created before the restart, real agents and isolated homes; the rigs were stopped and machine tickets released.

The complete registered CI workflow is green on this head: static analysis/typecheck, all five test shards, relay, cross-version wire compatibility, Linux/Windows packages and headless persistence. Final targeted integration verification ran 20 unique named files with 623 passing executions and five existing skips across configurations. Independent final comparison with the common pattern, compatibility, readiness and performance source reviews are complete.

Accepted differences and limits:

  • A window start without a saved pane binding no longer has its former initial yield; a bound host start adds a save-helper continuation. These timing differences were explicitly accepted after bounded source traces; identical scheduling for arbitrary observers is not claimed. QA found no changed user result.
  • With the layout-owner switch enabled, shared publication records the accepted window or host result synchronously after reservation settlement. Adopted claims retain their existing exclusion. The existing resume-outcome callback runs before binding persistence. The layout-owner dark path ships to no user; covered by tests (20 files / 312 passing), including the pre-save reporting regression. It was not runtime-QA'd.
  • A host refusal before start could not be induced on either build and remains covered by the launch-race, commit-facts and exit-durability tests. Runtime host exits kept the tab initially on both builds; on Windows the exited tabs disappeared after reload on both builds. OSC 11 colour replies were not remeasured this round. Windows configured-shell overrides were covered by typed exits there and configured-shell exits on M4Air. Linux and SSH/relay failure scenarios were reviewed in source, not exercised in this QA run.
  • Deferred, unproven concerns already present on main: a notification listener could throw during teardown; the unshipped banner fallback retains shown identities until reload; a conditional adopted-create waiter can need an extra attach. Bounded traces established no new PR regression, lost action or stranded claim. No additional guard or publication behavior was added for these concerns.

For Brennan's review

The paired screenshots below show main on the left and this PR on the right. Three places where the accepted choices matter:

  1. Shared commit and pre-save resume reporting: one assembly sequence, with adopted claims returning before ordinary publication.
  2. Accepted-result recording: settlement and switched-on waiter recording occur in one synchronous step for either caller.
  3. Host hidden-delivery boundary: the call stays immediately after the awaited commit, preserving replacement-waiter ordering.

Screenshots (main ea60ec5 on the left, PR 08d69ce on the right)

Row 1: window terminal survives a renderer reload, same shell process (Windows)

main PR
main-row1-reload.png pr-row1-reload.png

Row 2: real Codex restart in place, then Codex resumes after an app restart with a real reply (M4Air)

main PR
main-row2-clean-resume-codex-final-visible.png pr-row2-clean-resume-codex-final-visible.png

Row 2: real Claude conversation resumes after the app restart with a real reply (M4Air)

main PR
main-row2-clean-resume-claude-final-visible.png pr-row2-clean-resume-claude-final-visible.png

Row 4: hidden host terminal restored on reveal after a reload (Windows)

main PR
main-row4-reveal.png pr-row4-reveal.png

Row 5: CLI split + early agent tab appended unselected (M4Air desktop)

main PR
main-row5-desktop-agent-early.png pr-row5-desktop-agent-early.png

Row 5: phone sees the agent reply (M4Air, iOS simulator)

main PR
main-row5-phone-agent-reply.png pr-row5-phone-agent-reply.png

Row 5: line typed on the phone reaches the terminal

main PR
main-row5-phone-input.png pr-row5-phone-input.png

Row 6: dead terminal owner, hidden restored pane gets a fresh shell on reveal (Windows)

main PR
main-row6-fresh.png pr-row6-fresh.png

Row 7: program exits before start finishes; tab kept showing exit code 1 (M4Air)

main PR
main-activation1-row7-activation.png pr-activation1-row7-activation.png

Row 7: host-created terminal with an exiting shell, tab kept with exit 1 (M4Air)

main PR
main-row7-proof-row7-host.png pr-row7-proof-row7-host.png

Row 8: Windows native ConPTY window tab answers DA1

main PR
main-row8-window.png pr-row8-window.png

Row 9: real OpenCode adopted session attaches without a fresh startup prompt (Windows)

main PR
main-row9-rerun-adopted.png pr-row9-rerun-adopted.png

Row 10: deleted folder falls back to the workspace root with the notice (Windows)

main PR
main-row10-missing-folder.png pr-row10-missing-folder.png

@brennanb2025
brennanb2025 merged commit 9613563 into main Oct 22, 2026
33 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/conv-c5e2-spawn-commit branch October 22, 2026 17:06
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…31596); the unbound-registration test keeps its spawn from the suites' stand-in commit

After the main merge both start lanes register in spawn-commit-assembly.ts, after
savePtySpawnPaneBinding (or, adopted, on the live owner's pane); the census lists that file. A
phone create now writes its pane before the spawn, so the suites' stand-in spawn commit bound it
and the test of a path that registers unbound passed for the wrong reason; that test's controller
now opts out of the stand-in commit.
Jinwoo-H added a commit that referenced this pull request Oct 22, 2026
…ds a terminal asks main's layout (#32002)

* refactor(runtime): every reader of a terminal's pane goes through paneOfPty (L80)

With the layout-owner switch on, main's layout answers which tab and pane hold a terminal, and
nothing reads or writes the PTY record's tabId/paneKey copies or their graph stamp. Switch-off
reads the copies exactly as before.

* refactor(runtime): read a terminal's pane through the runtime's paneOfPty method

* fix(runtime): main's pane index answers paneOfPty before any window graph

A headless host never installs a window graph, so the query asked a publisher that did not exist
and every terminal read as paneless. The index is now made on first query; it publishes only once a
graph is installed, as before.

* test(runtime): pin that a query with no window publishes nothing

* test(runtime): a terminal summary reads its pane once (L80)

* feat(runtime): pin bind-first at registration, and one own-handle rule with or without a window (switch-on only)

* test(runtime): census and tests that every create path binds its pane before it registers (L80)

* test(runtime): a bind-first fixture that stands in for the spawn commit (L80)

* test(runtime): fixtures bind a terminal's pane before registering it, as the spawn commit does (L80)

Also, with the switch on: skip the bind-first check for a paired server's workspace, release a
closed tab's terminal ownership once main has dropped the pane, and publish a pane's agent status
from the terminal main's layout binds it to.

* feat(runtime): an exit after main's close still finds the pane it retires (switch-on only, L80 Q2)

Main's layout write records every pane it drops whose terminal no pane holds any more, in a new
optional session field closedTerminalPanesByPaneKey (same TTL and cap as closed-tab records).
Exit cleanup reads main's layout first, then that record by terminal id and incarnation, and
removes the entry it used. Older builds ignore the field.

* refactor(layout): one dropped-leaf step every live layout edit runs (switch-on only, L80 Q2)

The step receives each dropped pane (host, worktree, tab, leaf, terminal, incarnation), computed
across the whole layout so a moved pane is not dropped, and runs only for a commit that declares a
live edit. Today it records the closed-pane entries; a drop is recorded once per terminal.

* fix(runtime): a phone or headless tab close still stops and releases its live terminals after main's layout drops the panes (switch-on only, L80)

The headless close reads each row's live terminal before main's close drops the panes it is found
by, and a renderer-retired tab releases the owned terminal main left in no pane, as the explicit
close already did. Close tests now commit through main's layout and bind panes first.

* fix(runtime): a local workspace's terminal tab left in a paired server's partition is main's pane (switch-on only, L257)

Older builds could save a local worktree's tab rows into a runtime partition (#18202); its terminals
are local, so main's index takes those tabs for workspaces the router homes locally. A tab or
terminal the local partition also holds is indexed once, from there; SSH and server-owned
workspaces are skipped as before.

* test(layout): the legacy-close comparison leaves out the closed-pane record only layout-owner builds write (L80)

* test(pty): a pane whose failed start withdrew its tab resolves to terminal_not_found in layout-owner builds (L80 #7)

Main's layout no longer holds the pane, so there is no pane to answer for; window-owned builds keep
the disconnected stub from the exited terminal's record.

* test(runtime): orca-runtime suites bind panes first, as the real store and spawn commit do (L80)

Fake PTY spawns commit the binding into the pane the runtime wrote, stores list their partitions,
and SSH sessions sit in their ssh:<conn> partition; terminals registered directly bind first.

* fix(runtime): main's layout names a pane's terminal only when the workspace and stamped incarnation match (switch-on only, L80)

A record made before its adoption registers (a host restart) or a local id reused after one
matched a saved binding by id alone, so a phone or paired desktop could be handed a second handle
for the pane before the terminal's own handle arrived and stay on it.

* test(runtime): a restored pane is only unnamed in the adoption gap, and no local record rescues a paired server's tab (L80)

* test(runtime): recovery, close and routing suites set up terminals as production does (L80)

A recoverable pane is one the host inventory dropped with no exit, live terminals register
rather than appear only in the window graph, and SSH stores route as the real Store does.

* test(runtime): suspects 3, 4 and 5 bind, register and apply as production does; PR-1's main-layout closes in the part-10 and part-11 close tests (L80)

* test(runtime): a fixture store applies main's layout commands as a profile does; PR-1's own closes in the part-05, part-08 and UUID-leaf close tests (L80)

* test(runtime): the profile-store stand-in moves to its own fixture, keeping bind-first under the line limit (L80)

* test(runtime): orphan adoption reads the pane from main's layout with the switch on, not the record copy (L80)

* test(runtime): a phone's pane close and a pinned tab close are main's layout closes with the switch on (#31571), in the no-widening and surface-close tables (L80)

* test(runtime): a paired phone close commits in main's layout with no relay ack when the switch is on (#31571) (L80)

* fix(terminal): a parked pane resumes its agent once main has closed the other pane that held the session (layout-owner build, L80 P1)

* test(runtime): the parked-pane suite's restart holder is a saved pane with no registered terminal, under the line limit (L80 P1)

* fix(terminal): a spawn commit that binds a reused local terminal id unbinds it from the saved pane of the older process (layout-owner build, L80 P2)

* test(runtime): the legacy OSC row test uses the UUID leaf main's layout holds and registers its live terminal with the switch on (L80 E5)

* test(runtime): the pty-exit echo close of a dead headless tab is expected to fail with the switch on until W4's close PR (L255)

* fix(terminal): a terminal record that arrives, changes incarnation or moves workspace after main composed its panes re-composes them, so a restored pane lists once (layout-owner build, L80)

* fix(terminal): a pane bound to a terminal a paired server runs keeps that binding and host, and is never indexed as a local spilled tab (layout-owner build, L80/L257)

* fix(terminal): a pane main owns no longer proves its terminal runs; the host's inventory and the terminal's record decide, so a dropped shell reads disconnected (layout-owner build, L80)

* fix(terminal): an SSH pane whose host says its shell ended keeps its leaf on a negative or failed code, as the window does, so recovery starts a shell in it; a stale handle learns the connected replacement (layout-owner build, L80)

* fix(agent-launch): a terminal main's layout still binds counts as running through a host listing gap, so a launch never starts a second shell in its pane (layout-owner build, L80)

* fix(terminal): a disconnected terminal main still binds stays a stop target, never reads stopped unproven, and keeps an exit wait waiting until a certified exit (layout-owner build, L80)

* test(terminal): the wait unit fixture answers the exit-settled dependency

* test(terminal): realistic fixtures for three phone-row tests: unique leaf ids per pane, and a window that draws main's own panes (layout-owner build, L80)

* fix(terminal): a stale handle learns a pane's replacement only when it was resolved for that pane, its own terminal ended, and the replacement is connected there now (layout-owner build, L80)

* test(session-tabs): switch-on variant for a window's chat placement (main's layout order rules); headless phone tab order is L283

* test(terminal-close): switch-on close reds name their ledger rows (L255, L256, L259a, L259b); a same-id respawn's commit stamps its incarnation; the crossing terminal binds first

* test(terminal): the crossing registration is refused by main's workspace fence (L256 switch-on variant); the placement test's tabs are main's saved layout

* refactor(terminal): the stale-handle guard reads an issue-time pane stamp on the handle record, not a second map; moved-pane, restart and single-reader tests (layout-owner build, L80)

* test(session-tabs): switch-on variants: the desktop's tab name is main's rename, and a mobile-created tab's live shell is the one its commit registers (layout-owner build, L80)

* fix(terminal): a re-issued handle keeps its issue-time pane while no pane holds its terminal (review)

* fix(terminal): stop targets and exit waits use main's holds check (workspace and incarnation), and any exit event settles a later wait (review)

* test(session-tabs): name the switch-on placement and split-group reds L288 and L289

* fix(terminal): an exit drops a closed pane's record in the same write that retires the pane, and an unbind folds into the binding write (layout-owner build, L80)

The exit used to remove main's closed-pane entry in a session write of its own, before the
retirement write. It now reads the entry, and the retirement write for that pane drops it,
re-checked by terminal id and incarnation. An exit that keeps the surface (relay contact lost,
intentional stop) keeps the entry until a confirmed exit or its TTL.

A reused terminal id's unbind is now a pure computation that applyPtyBinding applies through
its existing writes. Two split-pane tests still expected a -1 exit to close the pane; they now
follow the ruling that any negative code keeps it. Static-gate fixes: test fixtures and tests
use typed member access instead of Reflect, and no longer use type assertions.

* test(runtime): the shared fixture store announces its session writes and the L283 store lists its partitions, as a profile Store does; L289's test passes on that store (layout-owner build, L80)

The fixture store bindPaneFirst fills now tells write listeners of every session write, direct or
by a layout command, so main's post-commit merge runs as it does on a real Store. The notice is
not enumerable, so a test's own `{ ...store }` copy, which keeps its writes elsewhere, does not
inherit a subscription it would never fire. With it, the targeted split-group create (L289) passes
at this head, so its it.fails mark goes. L283's test runs on a store that names its partitions and
stays it.fails("L283").

* fix(terminal): recovery checks the caller's handle after the cheap guards again, so the switch-off build re-issues no handle on a refused recovery (layout-owner build, L80)

The stale-handle switch point had moved the handle lookup ahead of the pane, terminal and
workspace checks. That lookup can re-issue a handle, so a switch-off recovery refused on those
checks gained a side effect base never had. The lookup runs after them again, and the switch-on
replacement check lives in one method.

* test(runtime): the layout-owner start fixture's spawn commits the pane binding before main registers the terminal, as the host does (L80 switch-on variant)

The window-tab start test came in with the main merge after bind-first; its fake spawn returned
a terminal no pane was bound to, so registration refused it. The fixture's spawn now binds the
pane first, as every other bind-first fixture does.

* fix(terminal): a new process under a reused terminal id starts with no exit code, so an exit wait on it cannot settle on the old process's code (layout-owner build, L80)

The record of a reused id kept the earlier process's lastExitCode, and with the switch on an exit
wait settles on any recorded code once the terminal reads disconnected. A new incarnation now
clears the code and cause. Also drops the L283 test's partition-list option: the fixture store
already lists its partitions.

* test(runtime): switch-on variants for four tests the full local run never loaded (L80)

- A restored pane's host lists the terminal it started; a pane main owns vouches for none.
- The other pane holding a slept session is in main's layout, so an unverifiable holder blocks
  the resume as it does through a window.
- Main sleeps a workspace whose panes it lists itself, even with a renderer attached (#31571).
- A graph sync no longer reconnects a disconnected terminal of main's pane; the inventory decides.

* test(runtime): the phone Markdown route tests use #31667's realistic store, and the untitled cases wait on L268 with the switch on

The window's tab uses main's id (the file path), and the store lists its partitions and saves each
open editor's unified tab and group, as the window does (the fixture from #31667). With the
switch on, the three untitled cases fail on L268, main's row merge dropping the untitled flag,
which #31667 fixes; they are it.fails until A1b's history includes it.

* refactor(runtime): two merged files back under the line limit, by moving A1b's additions to their helpers (L80)

After the main merge, the holder-pane check and a closed tab's live-terminal lookup pushed two
files past the line limit. The holder check is now paneHoldsSession (main-terminal-surfaces.ts)
behind one method, and the closed tab's lookup is one parent-class method. Behaviour unchanged.

* test(runtime): the headless chat tests open the chat on the publish path, as every product path does; L283 stays it.fails for the main-owned reorder

openChat recorded the chat only in the runtime's snapshot, so main's layout never held it and the
phone's reorder was refused as an unknown tab. On the publish path main's layout holds it; the
reorder is accepted but does not survive the row rebuild after a close (L283, reopened).

* test(runtime): bind-first census follows the one spawn-commit step (#31596); the unbound-registration test keeps its spawn from the suites' stand-in commit

After the main merge both start lanes register in spawn-commit-assembly.ts, after
savePtySpawnPaneBinding (or, adopted, on the live owner's pane); the census lists that file. A
phone create now writes its pane before the spawn, so the suites' stand-in spawn commit bound it
and the test of a path that registers unbound passed for the wrong reason; that test's controller
now opts out of the stand-in commit.

* test(runtime): convert four switch-on tests the disguised full runs hid

Real switch-on runs showed four files whose fakes registered terminals unbound
or confirmed a stop without its exit. Bind first, stamp the source as main
does, and deliver the exit a confirmed stop delivers. Switch-off unchanged.

* test: type the two converted fakes instead of casting them

The PTY controller fake now takes the controller's optional pane fields, and the
switch-on store is a typed RuntimeStore, so neither needs an assertion.
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