Fix Codex launch-home sqlite materialization latency (#4377)
This commit is contained in:
@@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user