Repository navigation
fix(layout): save terminal rows in the tab groups' order - #28066
Conversation
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to 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 ·
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3862adf2-1517-4924-9896-77172eb8ab4e
📒 Files selected for processing (8)
src/main/persistence/loading-store/session-host-partitions.tssrc/main/persistence/loading-store/session-snapshot-operations.tssrc/main/persistence/loading-store/workspace-session-snapshot-publication.tssrc/main/runtime/orca-runtime-move-headless-mobile-session-tab.tssrc/shared/workspace-layout/terminal-row-order.test.tssrc/shared/workspace-layout/terminal-row-order.tstests/e2e/paired-runtime-retention-metrics.tstests/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) { |
There was a problem hiding this comment.
🗄️ 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.
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
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_disagreesin both cases.After: Every save leaves the terminal records in the same order as the tab groups.
Mechanism:
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.persistHeadlessTabGroups) write groups of record ids, updating tab-bar entries only when they exist. The function reads those ids as records.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-tabsand headlessmove-tab-between-groupsscenarios)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-tabstab_order_disagrees, and headlessmove-tab-between-groupstab_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,oxlintandcheck:code-quality:changedpass. 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
Notes
sortOrdernumbers.performance.memory, a cached, rounded figure that can predate the collection, so whether it failed depended on timing. The probe now collects twice and readsRuntime.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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)