Fix Codex launch-home sqlite materialization latency (#4377)

This commit is contained in:
Neil
2026-06-01 01:51:32 -07:00
committed by GitHub
parent af43dcbc4a
commit a278fd33ea
2 changed files with 45 additions and 3 deletions
+40 -1
View File
@@ -14,7 +14,12 @@ import { tmpdir } from 'node:os'
import { join } from 'node:path'
const { fsMockState } = vi.hoisted(() => ({
fsMockState: { failSymlink: false, hardLinkRace: false }
fsMockState: {
failSymlink: false,
hardLinkRace: false,
failSqliteRead: false,
readFilePaths: [] as string[]
}
}))
vi.mock('node:fs', async () => {
@@ -31,6 +36,17 @@ vi.mock('node:fs', async () => {
}
return actual.linkSync(...args)
},
readFileSync: ((...args: Parameters<typeof actual.readFileSync>) => {
const targetPath = String(args[0])
fsMockState.readFilePaths.push(targetPath)
if (
fsMockState.failSqliteRead &&
/(?:\.sqlite|\.sqlite-wal|\.sqlite-shm)$/.test(targetPath)
) {
throw new Error(`unexpected sqlite content read: ${targetPath}`)
}
return actual.readFileSync(...args)
}) as typeof actual.readFileSync,
symlinkSync: (...args: Parameters<typeof actual.symlinkSync>) => {
if (fsMockState.failSymlink) {
throw new Error('symlink disabled for test')
@@ -69,6 +85,8 @@ function withWin32Platform<T>(callback: () => T): T {
beforeEach(() => {
fsMockState.failSymlink = false
fsMockState.hardLinkRace = false
fsMockState.failSqliteRead = false
fsMockState.readFilePaths = []
tempDir = mkdtempSync(join(tmpdir(), 'orca-codex-launch-home-'))
sharedHomePath = join(tempDir, 'shared-home')
launchRootPath = join(tempDir, 'launch-root')
@@ -127,4 +145,25 @@ describe('materializeScopedCodexLaunchHome', () => {
expect(readFileSync(targetPath, 'utf-8')).toBe(readFileSync(sourcePath, 'utf-8'))
expectSameFile(targetPath, sourcePath)
})
it('does not hash sqlite contents when marking shared database links', () => {
const sourcePath = join(sharedHomePath, 'logs_2.sqlite')
writeFileSync(sourcePath, 'sqlite\n')
fsMockState.failSqliteRead = true
const launchHomePath = materializeScopedCodexLaunchHome(sharedHomePath, launchRootPath, null)
const targetPath = join(launchHomePath, 'logs_2.sqlite')
const markerPath = join(launchHomePath, '.orca-launch-home-links', 'logs_2.sqlite.json')
expect(existsSync(targetPath)).toBe(true)
expect(
fsMockState.readFilePaths.some(
(readPath) => readPath === sourcePath || readPath === targetPath
)
).toBe(false)
expect(JSON.parse(readFileSync(markerPath, 'utf-8'))).toMatchObject({
sourceDigest: null,
targetDigest: null
})
})
})
+5 -2
View File
@@ -775,6 +775,7 @@ function markLaunchEntry(
): void {
const markerPath = getLaunchEntryMarkerPath(launchHomePath, entryName)
mkdirSync(dirname(markerPath), { recursive: true })
const shouldTrackDigests = MUTABLE_SHARED_FILE_ENTRIES.has(entryName)
writeFileSync(
markerPath,
`${JSON.stringify(
@@ -782,8 +783,10 @@ function markLaunchEntry(
version: LAUNCH_HOME_MARKER_VERSION,
sourcePath,
mode,
sourceDigest: digestPathIfFile(sourcePath),
targetDigest: digestPathIfFile(join(launchHomePath, entryName))
// Why: digests are only used to reconcile mutable config-style files;
// hashing SQLite databases on every PTY launch can read gigabytes.
sourceDigest: shouldTrackDigests ? digestPathIfFile(sourcePath) : null,
targetDigest: shouldTrackDigests ? digestPathIfFile(join(launchHomePath, entryName)) : null
} satisfies LaunchEntryMarker,
null,
2