Skip to content

terminal: window says where each new terminal goes (no behavior change) - #26078

Merged
Jinwoo-H merged 4 commits into
mainfrom
topo-b1-5-renderer-placement
Oct 7, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
topo-b1-5-renderer-placement

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​315 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​305
Prod 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​234 $\color{#cf222e}{\Huge{\mathbf{−}}}$​115 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​119

ELI5

When a new terminal starts, main has to decide which tab and pane it belongs to, and today it partly guesses. The previous PR (#25677) let a terminal start carry a note saying where it goes, and made main compare that note with its guess. This PR makes the window write that note for every terminal it starts. Main still only records whether the note agrees with its guess; it never acts on it. One small fix rides along (below); otherwise nothing changes for users.

What Changed

Before/after for users: one fix. In a remote tab, when a pane was inserted before another pane, the window briefly sent the host the panes in the wrong order and then corrected it. Now it sends the right order once. Everything else is identical to main: same tabs, same panes, same saved state.

The fix: the pane manager now puts a pane that goes before another pane in its final spot while building the split, instead of moving it there afterwards. So everything that reads the layout as the pane appears, including the layout this PR sends, already sees the real order.

What the window now sends on pty:spawn:

  • First pane of a tab: "new tab", plus the tab's creation fields (title, custom title, color, created time, start folder, shell, quick command label, agent, view mode), read from the store.
  • A split: "split of pane X" with the direction, the ratio when the split has one, and the tab's whole layout right after the split (read from the panes on screen). The pane manager already knew the parent pane and direction; they now ride along with the cwd hint it already passes to the new pane.
  • Background launches: the agent background launch sends "new tab" with its title (no agent, because the tab it creates doesn't record one); the workspace default tabs send "new tab" with their row; the setup split sends "split of the first pane" with its layout.
  • Codex account restart: "root" when the restart rebuilds a layout that lost its leaf (the same condition that already decides that rewrite, now one shared function).
  • A reattach to a running terminal sends nothing. A respawn or wake of a known pane may send it; main ignores placement for a pane it already knows.

Shared type (src/shared/terminal-pane-placement.ts): new optional row on new tab, and ratio and proposedRoot on split. They reuse the saved-session schemas for tabs and layouts. A malformed optional field is dropped on its own, so the rest of the placement still counts.

Main: the recorded binding.placement value absent now means "a new pane arrived with no placement" (a pane main already knows reports leaf_present first). That makes it a direct count of starts that still rely on the guess, which should be zero before the guess is deleted. Still recorded in a guarded block; it cannot fail the start.

Moves only, to stay under the file-size limit: the background pane's exit-output saver moves to lib/background-pane-exit-output.ts unchanged; Codex restart uses the existing collectLeafIds instead of its own tree walk.

Why

The next step lets main build the tab or split from this note and stop guessing, which removes one way the same terminal can show up in two tabs (STA-9417). That step needs every window-started terminal to carry the note, including the tab's creation fields (otherwise main would blank them) and the post-split layout (the parent pane and a direction can't describe a split placed before a group of panes). Sending everything now, while main only compares, keeps this PR without behavior changes and lets real traces show how often the guess disagrees before anything depends on it. Putting the data on the existing spawn request avoids a second message or new state.

Linked Issue

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

Visual Proof

N/A: no visible UI change. The one fix is a brief wrong-order layout message to a remote host, which has no on-screen trace to capture.

Testing

  • Layout parity check (ORCA_BACKGROUND_LAUNCH=1 pnpm run test:e2e:terminal-layout-parity -- --base origin/main --head HEAD): all 9 scenarios, 0 differences (none declared, none undeclared).

  • pnpm tc, oxlint, oxfmt, check:code-quality:changed: pass.

  • New/updated tests: pane manager sends new tab for the first pane, split with parent and direction, and for a split placed before a group of panes; the placement completion adds the tab row and the real post-split layout (ratio read back from the panes); the transport sends placement on a fresh start and not on a reattach; the pane connection carries it to the transport; background launches and Codex restart send the expected placement; schema keeps the new fields and drops only a bad one; the main inertness test now expects leaf_present for a known pane.

  • Vitest over the touched renderer, src/main/{persistence,ipc} and shared tests: everything passes except files that fail the same way on origin/main in this environment (unrelated).

  • I manually tested these changes locally

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

Manual app testing not needed: the only behavior change is the remote-tab ordering fix above, which a unit test covers, and the parity run drives the real app for each scenario.

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

  • Wire compatibility: pty:spawn only goes from this app's window to its own main process. Placement is never forwarded to the SSH relay, remote runtimes or the web client, which build their own requests field by field. All new fields are optional; an older main ignores them (its schema strips unknown keys).
  • The split placed before a group of panes only happens today when the host already started that terminal, so it reattaches and sends no placement. The test checks the layout the new pane sees at the moment it appears.

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)

…eport-only

The window now says where each fresh terminal goes: the first pane of a tab
sends new-tab with the tab's creation fields, a split sends the parent leaf,
direction, ratio and the tree after the split, background launches send the
same, and a Codex restart that rebuilds a rootless layout sends root. A
reattach sends nothing. Main still only records whether placement names the
tab its binding write picks; its 'absent' value now counts only new leaves
without placement, so it reads the fallback mint and graft directly.

Extends the shared placement type with optional row, ratio and proposedRoot,
each dropped alone if malformed, so older and newer peers keep working.
…he tab lacks

The adopted tab is created without launchAgent, so a row naming one would
diverge from the renderer's tab once main applies placement.
…order

wrapInSplit now places the new pane first itself, so the pane-created
handler's proposedRoot sees the real post-split tree instead of the order
before the subtree split moved it.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 8c38968b-0b4a-436f-87a4-47d01d9d7a5d
📥 Commits

Reviewing files that changed from the base of the PR and between bd6890e and b398319.

📒 Files selected for processing (1)
  • src/renderer/src/lib/launch-worktree-background-terminals.test.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.


📝 Walkthrough

Walkthrough

The change adds tab-row and split-layout details to terminal placement metadata. Pane creation and background terminal spawns attach placement information, and fresh PTY spawns forward it while reattachments omit it. Background pane exit handling moves to a shared helper. Detached Codex restart and terminal topology logic update how they handle rootless or already-present leaves.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b3983

This test-only change adds checks for worktree terminal placement metadata without revealing a production regression; it appears safe to merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 30 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 describes the main change: the window sends placement information for new terminals. The “no behavior change” note matches the stated intent that main records, but does not act on, t…
Description check ✅ Passed The description covers the change, rationale, linked work, visual-proof exception, testing, compatibility, and checklist. It explains why manual testing was not needed and reports the relevant automat…
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
  • 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.

@Jinwoo-H
Jinwoo-H merged commit a002658 into main Oct 7, 2026
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