fix: load large legacy pane alias migrations

This commit is contained in:
Neil
2026-05-30 05:56:35 -07:00
parent dcd087ba1e
commit 30af757a30
2 changed files with 62 additions and 2 deletions
+54
View File
@@ -17,6 +17,7 @@ import { tmpdir } from 'os'
import type {
PersistedState,
Repo,
TerminalPaneLayoutNode,
TerminalTab,
WorktreeLineage,
WorkspaceSessionState
@@ -219,6 +220,19 @@ function makeSessionWithBrowserHistory(count: number): WorkspaceSessionState {
}
}
function makeBalancedLegacyPaneLayout(start: number, end: number): TerminalPaneLayoutNode {
if (end - start === 1) {
return { type: 'leaf', leafId: `pane:${start + 1}` }
}
const midpoint = Math.floor((start + end) / 2)
return {
type: 'split',
direction: 'horizontal',
first: makeBalancedLegacyPaneLayout(start, midpoint),
second: makeBalancedLegacyPaneLayout(midpoint, end)
}
}
describe('Store', () => {
beforeEach(() => {
testState.dir = mkdtempSync(join(tmpdir(), 'orca-test-'))
@@ -3609,6 +3623,46 @@ describe('Store', () => {
)
})
it('loads legacy pane aliases from very large persisted split layouts', async () => {
const leafCount = 130_000
writeDataFile({
schemaVersion: 1,
repos: [],
worktreeMeta: {},
settings: {},
ui: {},
githubCache: { pr: {}, issue: {} },
workspaceSession: {
activeRepoId: 'r1',
activeWorktreeId: 'wt1',
activeTabId: 'tab1',
tabsByWorktree: {
wt1: [
{
id: 'tab1',
worktreeId: 'wt1',
title: 'Terminal',
customTitle: null,
color: null,
sortOrder: 0,
createdAt: 1,
ptyId: 'large-pty'
}
]
},
terminalLayoutsByTabId: {
tab1: {
root: makeBalancedLegacyPaneLayout(0, leafCount),
activeLeafId: 'pane:1',
expandedLeafId: null
}
}
}
})
await expect(createStore()).resolves.toBeDefined()
})
it('converts unambiguous dev migration rows into persisted aliases', async () => {
const stablePaneKey = makePaneKey('tab1', TEST_LEAF_1)
writeDataFile({
+8 -2
View File
@@ -1013,8 +1013,14 @@ function normalizeWorkspaceSessionPaneIdentities(
normalizedLayout: normalized.snapshot,
leafIdByInputLeafId: normalized.leafIdByInputLeafId
})
migrationUnsupportedEntries.push(...migrationEntries.migrationUnsupportedEntries)
legacyPaneKeyAliasEntries.push(...migrationEntries.legacyPaneKeyAliasEntries)
// Why: old persisted split layouts can generate enough alias rows to
// exceed V8's argument limit if the arrays are spread into push().
for (const entry of migrationEntries.migrationUnsupportedEntries) {
migrationUnsupportedEntries.push(entry)
}
for (const entry of migrationEntries.legacyPaneKeyAliasEntries) {
legacyPaneKeyAliasEntries.push(entry)
}
const leafIdByPtyId = new Map<string, string>()
const duplicatePtyIds = new Set<string>()
for (const [leafId, ptyId] of Object.entries(normalized.snapshot.ptyIdsByLeafId ?? {})) {