Skip to content

refactor(terminal): carry pane placement on terminal start, report-only - #25677

Merged
Jinwoo-H merged 14 commits into
mainfrom
terminal-topology-b1-4-spawn-placement
Oct 7, 2026
Merged

Jinwoo-H merged 14 commits into
mainfrom
terminal-topology-b1-4-spawn-placement

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​494 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​493
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​138

ELI5

When a terminal starts, main has to decide which tab and pane it belongs to. Today it often guesses, and when the guess is wrong (for example, a split started by a setup script), the same terminal can end up in two tabs (Linear STA-9417). This PR makes every terminal that main starts say where it belongs, and passes that along to the place that saves the binding. For now that information is only compared against today's choice and recorded in a trace; it never changes where the terminal goes. Nothing changes for users.

What Changed

  • New src/shared/terminal-pane-placement.ts: a placement says a terminal is a new tab, a split of a given pane in a given direction, or the root of an existing tab. It carries only what this change reads; tab details, sizes and split ratios come with the change that builds tabs and splits from it. It is validated with zod; anything malformed or of an unknown kind is treated as absent.
  • pty:spawn accepts an optional placement field (IPC args, preload types, the runtime PTY controller, spawn state, persistPtyBinding args).
  • Main-side terminal starts now send it: every background create in createTerminal (CLI, agents, orchestration, worktree startup, provisioning, mobile) sends "new tab", and the PTY-backed split sends "split of pane X". Helpers in runtime/runtime-terminal-spawn-placement.ts.
  • terminal-topology/terminal-pane-placement-agreement.ts compares the placement with the tab today's write picks and records the result as binding.placement on the existing persistence.pty-binding trace span (absent, leaf_present, agrees, or a mismatch code). If the comparison throws, it records check_threw and the write continues unchanged.

Before/after for users: none. The binding write itself is untouched; the same tab is chosen and the same state is saved.

Why

Later in this refactor, main will use placement to build the tab or split itself and stop guessing, which removes one way duplicates are created. Landing the plumbing report-only first means that change can later be checked against real data on how often today's guess disagrees. The window side (the renderer sending placement) is a separate follow-up PR; so is applying placement and deleting the guess and graft code, since each of those changes saved state.

Linked Issue

Maintainer PR. Part of the terminal layout refactor (Linear STA-9417).

Visual Proof

N/A: no behavior change.

Testing

  • pnpm tc, oxlint, oxfmt and check:code-quality:changed pass; the terminal layout boundary test is unchanged.

  • Store-level inertness test on real SQLite (pty-binding-placement-inertness.test.ts): each write with placement gives the same in-memory state, saved state and return value as the same write without it, across a local new tab, existing tab, leaf already present, folder workspace, SSH new tab and SSH existing tab, hitting every agreement value; a closed tab is still refused. A forced throw from the check gives the same result. Making the write depend on placement fails three cases; removing the throw guard fails the throw case.

  • IPC threading tests with valid, missing and malformed placement, and runtime specs asserting the "new tab" and "split" placements.

  • Vitest over src/main/{persistence,ipc,runtime}: all pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Not manually tested in the app: no behavior or UI change.

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

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • 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)

Adds a placement type (new tab, split, or root) that says which tab and leaf a
new PTY joins. pty:spawn accepts it as an optional field, main's runtime creates
and PTY-backed splits supply it, and the binding write records on its trace span
whether placement names the tab today's write picks. The write never branches on
it, so bindings and saved state are unchanged. applyPtyBinding becomes
copy-on-write and returns the new session.
…report-only

Reverts applyPtyBinding to main's in-place write: placement is read before the
write and does not need a new session, so this PR keeps identical behavior.

Follow-up: build rows and splits from placement, delete persistHeadlessTerminalSplit,
the provisional-graft strip, and mobile's follow-up props write.
The agreement check is report-only, so a throw records check_threw on the span
and the binding proceeds exactly as without placement.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in 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: Advanced
  • Run ID: 39e93f59-d213-45ba-893e-0ee0f5be4528
📥 Commits

Reviewing files that changed from the base of the PR and between 854a3aa and 22b3bad.

📒 Files selected for processing (2)
  • src/main/persistence/loading-store/pty-binding-persistence.ts
  • src/main/persistence/loading-store/pty-binding-span.ts

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


📝 Walkthrough

Walkthrough

PTY spawn options now support validated terminal-pane placement values for new tabs, splits, and roots. Renderer and runtime spawn paths carry placement into persisted bindings. Binding persistence checks placement against session state and records the agreement outcome without changing binding state when the check throws.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 22b3b

Terminal placement is currently reported without changing tab selection or saved binding state. The inspected creation and split paths preserve that behavior, with no established user-visible regression blocking merge.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 9d289

Placement information remains advisory: it does not select terminal ownership, change saved layouts, or grant additional authority. Invalid renderer input is ignored, and agreement-check failures do not block binding.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A renderer can influence placement agreement reporting through the existing spawn API, but the traced field does not independently select another pane, workspace, host partition, or PTY owner. Its incremental authority is observational rather than mutative.

Trust Boundaries and Controls

  • observed — Main validates renderer-supplied placement before forwarding it to persistence. Binding identity and host partition still determine the session and admission checks; placement reporting occurs only after the existing refusal check.

Resilience and Maintainability Implications

  • inferred — Placement does not enter reservation or registration identity, and existing persistence-failure cleanup remains in place. The added telemetry setter has no external callback: it updates an internal Map or does nothing when tracing is disabled. These mechanisms preserve the inspected ownership and failure-containment behavior.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 22 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 identifies the terminal pane-placement change and its report-only scope.
Description check ✅ Passed The description covers the required summary, rationale, linked work, visual proof, testing, compatibility notes, and checklist. It explains that the change does not alter user-visible behavior and rep…
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@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 — the full diff at e4fd652 (all 21 files, 4 commits): a report-only refactor that threads an optional TerminalPanePlacement from main-side terminal starts into the PTY binding write, where it is compared against the current session and recorded as a binding.placement span attribute. The binding write itself never branches on it.

  • New shared placement schema (src/shared/terminal-pane-placement.ts): a zod discriminated union of new-tab / split / root, with a leaf-UUID check on split.parentLeafId. Malformed or unknown kinds parse to null and are treated as absent; unknown object keys are stripped, so a newer sender's extra fields are safe.
  • Placement threaded end-to-end: pty:spawn IPC (loosely typed in spawn-types.ts, parsed once in spawn-commit-persist.ts), runtime spawn args (spawn-state.ts, spawn-preflight.ts, spawn-commit.ts), and the preload API types (the bridge forwards the whole opts object to ipcRenderer.invoke).
  • Main-side producers: runtimeNewTabPlacement for every background create in createTerminal, runtimeSplitPlacement for the PTY-backed split.
  • Report-only comparison (terminal-pane-placement-agreement.ts): classifies absent / leaf_present / agrees / tab_exists / tab_missing / parent_missing / root_occupied against the pre-write session, records it on the existing persistence.pty-binding span, and catches a throwing check as check_threw.
  • Tests: a real-SQLite inertness suite covering local/folder/SSH, mint/graft/respawn, tombstone refusal, and a forced throw; an IPC threading test for valid/missing/malformed placement and the runtime host-admitted binding; and schema unit tests.

I traced the report-only invariant to its edges: applyPtyBinding and createMinimalPersistedTerminalTab destructure fixed fields rather than spreading placement, and the fast-lane predicate is unchanged, so the field cannot reach memory or saved state on either the IPC or runtime path. The inertness test pins that directly.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (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 — the increment since the prior pullfrog review (c166171..9d28971: one authored commit plus two clean origin/main sync merges).

  • Narrowed the placement schema: terminal-pane-placement.ts now carries only the fields the agreement check reads — new-tab is { kind: 'new-tab' }, split keeps only parentLeafId/direction (dropping ratio and proposedRoot), and parentLeafId gains a max(128) bound. Zod still strips unknown keys, so a richer sender parses down cleanly.
  • Realigned producers, dependencies and tests: runtimeNewTabPlacement() takes no arguments (the spawn still runs at cols: 120, rows: 40; only the duplicated size left the placement), runtimeSplitPlacement drops its ratio, the now-dead RUNTIME_TERMINAL_SPAWN_GRID export was removed, and the schema, IPC threading and inertness fixtures were updated to match.

The binding write remains report-only and untouched. I confirmed no remaining references to the removed fields, that both sync merges auto-merged with no conflict-resolved files, and that pnpm tc plus the three placement test files pass.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

…ology-b1-4

# Conflicts:
#	src/main/persistence/loading-store/pty-binding-persistence.ts
#	src/main/persistence/loading-store/pty-binding-span.ts
…ology-b1-4

# Conflicts:
#	src/main/persistence/loading-store/pty-binding-persistence.ts
@Jinwoo-H
Jinwoo-H merged commit d1fe11c into main Oct 7, 2026
44 of 48 checks passed
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