Repository navigation
refactor(terminal): carry pane placement on terminal start, report-only - #25677
Conversation
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.
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughPTY 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 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 ReviewSecurity architecture risk: ⚪ Minimal · up to 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 Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
✅ 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 ofnew-tab/split/root, with a leaf-UUID check onsplit.parentLeafId. Malformed or unknown kinds parse tonulland are treated as absent; unknown object keys are stripped, so a newer sender's extra fields are safe. - Placement threaded end-to-end:
pty:spawnIPC (loosely typed inspawn-types.ts, parsed once inspawn-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 toipcRenderer.invoke). - Main-side producers:
runtimeNewTabPlacementfor every background create increateTerminal,runtimeSplitPlacementfor the PTY-backed split. - Report-only comparison (
terminal-pane-placement-agreement.ts): classifiesabsent/leaf_present/agrees/tab_exists/tab_missing/parent_missing/root_occupiedagainst the pre-write session, records it on the existingpersistence.pty-bindingspan, and catches a throwing check ascheck_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.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
New-tab rows, sizes, split ratios and proposed trees come back with the change that builds tabs and splits from placement. Leaf ids are capped at 128 like the other session schemas.
There was a problem hiding this comment.
✅ 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.tsnow carries only the fields the agreement check reads —new-tabis{ kind: 'new-tab' },splitkeeps onlyparentLeafId/direction(droppingratioandproposedRoot), andparentLeafIdgains amax(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 atcols: 120, rows: 40; only the duplicatedsizeleft the placement),runtimeSplitPlacementdrops itsratio, the now-deadRUNTIME_TERMINAL_SPAWN_GRIDexport 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.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
(cherry picked from commit 1a5f687)
…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

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
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:spawnaccepts an optionalplacementfield (IPC args, preload types, the runtime PTY controller, spawn state,persistPtyBindingargs).createTerminal(CLI, agents, orchestration, worktree startup, provisioning, mobile) sends "new tab", and the PTY-backed split sends "split of pane X". Helpers inruntime/runtime-terminal-spawn-placement.ts.terminal-topology/terminal-pane-placement-agreement.tscompares the placement with the tab today's write picks and records the result asbinding.placementon the existingpersistence.pty-bindingtrace span (absent,leaf_present,agrees, or a mismatch code). If the comparison throws, it recordscheck_threwand 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 andcheck:code-quality:changedpass; 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
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
pty:spawnonly travels from this app's window to its own main process, and placement never reaches the SSH relay or remote-runtime RPC. The field is optional; an older window sends exactly the same binding as before (tested).pty-binding-persistence.tsandpty-binding-span.ts; whichever lands second will be rebased.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)