Skip to content

fix(layout): save terminal rows in the tab groups' order - #28066

Merged
Jinwoo-H merged 5 commits into
mainfrom
fix/terminal-row-order-follows-groups
Oct 12, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
fix/terminal-row-order-follows-groups

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​100 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33

ELI5

Orca saves each workspace's tab order in two places: the tab groups (what the tab bar shows) and the list of terminal records. When you reorder tabs from a paired client, or move tabs between groups on a server running without a window, only the tab groups changed. The terminal records stayed in the old order, so the two saved orders disagreed. Now the saved terminal records always follow the tab groups' order.

What Changed

Before: A paired client reverses the tab order. The tab bar shows the new order, but the saved terminal records keep the old one. On a server with no window, moving a tab between groups left the records in creation order, and that persisted across a restart. The layout checker reported tab_order_disagrees in both cases.

After: Every save leaves the terminal records in the same order as the tab groups.

Mechanism:

  • A new pure function, orderTerminalRowsByTabGroups (src/shared/workspace-layout/terminal-row-order.ts), sorts each workspace's terminal records by the position of their tab in the groups. Records no group lists keep their relative order and go after the grouped ones. When nothing moves, it returns the same session object.
  • The Store runs it as the last step of its three session write exits: the local snapshot write, the host-partition write and the patch publish. It has to be last, because the earlier steps rebase the incoming records onto the stored ones, and that rebase is what put the old order back.
  • A group can list a terminal record's id directly. A headless host saves terminal records but no tab bar, and its group moves (persistHeadlessTabGroups) write groups of record ids, updating tab-bar entries only when they exist. The function reads those ids as records.
  • The headless group-move code no longer sorts the records itself, because the Store now does it on that same write. That code also matched records by tab-bar id, which only worked when the two ids happened to match.

Why

The tab groups are the order users see, so the records should follow them, not the other way round. Fixing it at the Store's write exits covers every writer at once: the window's saves, the headless moves, and any future writer. The alternative was to patch each place that changes group order (the reorder, the drop, splits, restoring a closed tab, detach, the headless moves) to also re-sort the records. That adds the same rule in six or more places, and the next new writer would miss it. It also would not fix the rebase step, which undid the headless sort that already existed.

Linked Issue

Fixes #

Visual Proof

N/A: the window's tab bar already showed the right order. What changes is the saved data, which the layout checker reads. Evidence is the e2e runs below.

Testing

  • I manually tested these changes locally (macOS, background dev Electron: the layout checker's client-reorder-tabs and headless move-tab-between-groups scenarios)

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

  • New unit test src/shared/workspace-layout/terminal-row-order.test.ts.

  • Removed the known-on-main entries this fixes from tests/e2e/workspace-layout-oracle-known-on-main.ts: client-reorder-tabs tab_order_disagrees, and headless move-tab-between-groups tab_order_disagrees (orcad and Electron). With those entries gone, the scenarios pass in CI. Windowed and headless layout checker run, with the orcad scenarios running: 38297695019 (all 39 tests pass).

  • Full e2e suite: 38302204326. Diffed against main at the same commit (38297736386). No failure that main does not also have. Shards 6, 7 and 12 hit the 30-minute job limit, as they do on main, and shard 11 did too here; every test in shard 11 finished with the same results as main. The oracle run predates the last commit, which only touches the heap probe.

  • pnpm tc, oxlint and check:code-quality:changed pass. The main, persistence, runtime and shared layout unit suites pass.

The paired-terminal retention spec's heap probe is fixed here too; see Notes.

AI Disclosure

Review

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

  • SSH and remote servers: the same function runs on host-partition writes, so remote partitions are ordered the same way. The wire format is unchanged: records only change order and their sortOrder numbers.
  • Folder workspaces: they are keyed the same way and handled identically.
  • Performance: one linear pass on each write over every workspace with two or more terminal records. It builds a new list of those records each time, even when nothing moves. Only the session object is reused when every record is already in place.
  • Old saved files: an older profile whose records disagree is reordered on its first save. The tab bar is the source of truth, so nothing the user sees changes.
  • Heap probe (test only): the paired-terminal retention spec failed about half the time on this branch and on the tab-bar branch, and passed on main in the runs we had. Measuring with the exact heap API showed the same roughly 20 MB on main too, in 2 of 5 runs. It is garbage that one collection pass leaves right after parking, and a second pass frees it. The test also read performance.memory, a cached, rounded figure that can predate the collection, so whether it failed depended on timing. The probe now collects twice and reads Runtime.getHeapUsage. The budget is unchanged. If the heap cannot be read, the check now fails instead of being skipped. With the fix, 6 of 6 runs pass on main and 6 of 6 on a branch, with the heap after parking at or below the baseline (runs 38301290228, 38301300121). The same commit is in the companion PR; it is identical, so whichever merges second does not conflict.

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)

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fda593a6-7437-4383-847c-06c0001312d6

📥 Commits

Reviewing files that changed from the base of the PR and between d02d03f and 8ceb78a.


You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 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: 26551ed0-a76a-4b4f-ae5f-94c1126b9d10

📥 Commits

Reviewing files that changed from the base of the PR and between e55fa4d and d02d03f.


📒 Files selected for processing (3)
  • src/shared/workspace-layout/terminal-row-order.ts
  • tests/e2e/helpers/paired-terminal-parking-oracle.ts
  • tests/e2e/paired-runtime-retention-metrics.ts

🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shared/workspace-layout/terminal-row-order.ts

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



📝 Walkthrough

Walkthrough

Workspace session writes now order terminal rows by tab-group order. Headless tab-group persistence no longer sorts or rewrites terminal row order. Tests cover the ordering behavior, and the related oracle allowlist entries were removed. Paired runtime retention sampling now reads heap usage through CDP, and CDP errors reject the sampling operation.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to d02d0

A workspace left with one terminal can retain an incorrect saved row order. The impact is narrow, but the ordering fix remains incomplete.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the primary change: saving terminal rows in tab-group order.
Description check Passed The description is detailed and covers the user impact, mechanism, rationale, testing, compatibility, performance, and checklist items. The Linked Issue field remains empty after Fixes #, but the re…

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🛠️ Fix failing CI checks 💡
  • 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: 3862adf2-1517-4924-9896-77172eb8ab4e
📥 Commits

Reviewing files that changed from the base of the PR and between 28dc0c9 and e55fa4d.

📒 Files selected for processing (8)
  • src/main/persistence/loading-store/session-host-partitions.ts
  • src/main/persistence/loading-store/session-snapshot-operations.ts
  • src/main/persistence/loading-store/workspace-session-snapshot-publication.ts
  • src/main/runtime/orca-runtime-move-headless-mobile-session-tab.ts
  • src/shared/workspace-layout/terminal-row-order.test.ts
  • src/shared/workspace-layout/terminal-row-order.ts
  • tests/e2e/paired-runtime-retention-metrics.ts
  • tests/e2e/workspace-layout-oracle-known-on-main.ts
💤 Files with no reviewable changes (1)
  • tests/e2e/workspace-layout-oracle-known-on-main.ts

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

let tabsByWorktree: WorkspaceSessionState['tabsByWorktree'] | null = null
for (const [worktreeId, rows] of Object.entries(session.tabsByWorktree ?? {})) {
const groups = session.tabGroups?.[worktreeId]
if (!groups?.length || rows.length < 2) {

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Reindex a single remaining row.

If one row has sortOrder: 1, this guard returns the session unchanged even when its group lists that row first. The write paths can then persist the stale sortOrder. Skip empty rows, but let a single row reach the zero-based assignment at Line 34.

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