diff --git a/src/main/codex/codex-launch-home-paths.test.ts b/src/main/codex/codex-launch-home-paths.test.ts index 5452fb3a9..886598cb6 100644 --- a/src/main/codex/codex-launch-home-paths.test.ts +++ b/src/main/codex/codex-launch-home-paths.test.ts @@ -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) => { + 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) => { if (fsMockState.failSymlink) { throw new Error('symlink disabled for test') @@ -69,6 +85,8 @@ function withWin32Platform(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 + }) + }) }) diff --git a/src/main/codex/codex-launch-home-paths.ts b/src/main/codex/codex-launch-home-paths.ts index 7b0769fee..ca94f887b 100644 --- a/src/main/codex/codex-launch-home-paths.ts +++ b/src/main/codex/codex-launch-home-paths.ts @@ -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