perf: append codex migration diagnostics (#4147)

This commit is contained in:
Neil
2026-05-31 06:02:44 -07:00
committed by GitHub
parent 7476f2c0ed
commit 9f11558543
2 changed files with 22 additions and 6 deletions
@@ -2771,6 +2771,8 @@ describe('CodexRuntimeHomeService', () => {
const runtimeSessionsDir = join(getRuntimeCodexHomePath(), 'sessions')
mkdirSync(runtimeSessionsDir, { recursive: true })
writeFileSync(join(runtimeSessionsDir, 'session.json'), '{"turns":[1]}', 'utf-8')
mkdirSync(join(runtimeSessionsDir, 'nested'), { recursive: true })
writeFileSync(join(runtimeSessionsDir, 'nested', 'session.json'), '{"turns":[2]}', 'utf-8')
const managedHomePath = createManagedAuth(
testState.userDataDir,
'account-1',
@@ -2779,6 +2781,8 @@ describe('CodexRuntimeHomeService', () => {
const legacySessionsDir = join(managedHomePath, 'sessions')
mkdirSync(legacySessionsDir, { recursive: true })
writeFileSync(join(legacySessionsDir, 'session.json'), '{"turns":[1,2]}', 'utf-8')
mkdirSync(join(legacySessionsDir, 'nested'), { recursive: true })
writeFileSync(join(legacySessionsDir, 'nested', 'session.json'), '{"turns":[2,3]}', 'utf-8')
const store = createStore(createSettings())
const { CodexRuntimeHomeService } = await import('./runtime-home-service')
@@ -2790,9 +2794,17 @@ describe('CodexRuntimeHomeService', () => {
).toBe('{"turns":[1,2]}')
expect(
readFileSync(
join(testState.userDataDir, 'codex-runtime-home', 'migration-diagnostics.jsonl'),
join(runtimeSessionsDir, 'nested', 'session.orca-legacy-account-1.json'),
'utf-8'
)
).toContain('"type":"session-conflict"')
).toBe('{"turns":[2,3]}')
const diagnostics = readFileSync(
join(testState.userDataDir, 'codex-runtime-home', 'migration-diagnostics.jsonl'),
'utf-8'
)
.trim()
.split('\n')
expect(diagnostics).toHaveLength(2)
expect(diagnostics[0]).toContain('"type":"session-conflict"')
})
})
@@ -3,6 +3,7 @@ contract for Codex inside Orca. Keeping path resolution, system-default
snapshots, auth materialization, and recovery together prevents account-switch
semantics from drifting across PTY launch, login, and quota fetch paths. */
import {
appendFileSync,
copyFileSync,
existsSync,
chmodSync,
@@ -995,10 +996,13 @@ export class CodexRuntimeHomeService {
private appendMigrationDiagnostic(record: Record<string, string>): void {
const diagnosticsPath = this.getMigrationDiagnosticsPath()
const existingContents = existsSync(diagnosticsPath)
? readFileSync(diagnosticsPath, 'utf-8')
: ''
writeFileAtomically(diagnosticsPath, `${existingContents}${JSON.stringify(record)}\n`)
try {
appendFileSync(diagnosticsPath, `${JSON.stringify(record)}\n`, { encoding: 'utf-8' })
} catch (error) {
// Why: conflict diagnostics are useful, but must not make the one-shot
// migration fail after the session file has already been preserved.
console.warn('[codex-runtime-home] Failed to append migration diagnostic:', error)
}
}
private captureSystemDefaultSnapshot(options: { force: boolean }): void {