Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
95de52f
fix(codex): legacy migration never overwrites transcripts or drops hi…
brennanb2025 Nov 20, 2026
cb03fef
fix(codex): import legacy prompt history only while no Codex thread i…
brennanb2025 Nov 20, 2026
e5b7009
fix(codex): never write a live shared history during the legacy migra…
brennanb2025 Nov 20, 2026
e29d179
fix(codex): keep legacy prompt history aside before anything else in …
brennanb2025 Nov 20, 2026
614be27
fix(codex): retry the legacy history import from Orca's kept copies
brennanb2025 Nov 20, 2026
c62e27c
fix(codex): run the kept legacy history import independently of sessi…
brennanb2025 Nov 20, 2026
acedce5
fix(codex): keep one real copy of each legacy history, published by r…
brennanb2025 Nov 20, 2026
1e35b8b
fix(codex): refresh the kept legacy history and refuse linked kept fo…
brennanb2025 Nov 20, 2026
1148b24
fix(codex): set the earlier kept history aside when Codex trimmed the…
brennanb2025 Nov 20, 2026
190d347
fix(codex): account removal keeps prompt history; import reads accoun…
brennanb2025 Nov 20, 2026
6e2f608
fix(codex): skip the history import where hard links are refused; say…
brennanb2025 Nov 20, 2026
048ae71
fix(codex): retry on unreadable account histories; classify only link…
brennanb2025 Nov 20, 2026
c08949a
fix(codex): mark the migration after the session copies; retry only a…
brennanb2025 Nov 20, 2026
392a18f
fix(codex): read linked account histories; ignore account folders wit…
brennanb2025 Nov 20, 2026
75dee20
fix(codex): mark the migration done only once history settles; keep a…
brennanb2025 Nov 20, 2026
7caad8a
fix(codex): keep every entry a linked prompt history passes through; …
brennanb2025 Nov 20, 2026
351c00f
fix(codex): follow a linked prompt history one component at a time; s…
brennanb2025 Nov 20, 2026
deddf1f
fix(codex): preserve each account history in the runtime home, then m…
brennanb2025 Nov 20, 2026
0c1abd9
fix(codex): preserve account histories off the main thread, before ma…
brennanb2025 Nov 20, 2026
653270d
fix(codex): delete only the logins from a home whose history is a lin…
brennanb2025 Nov 20, 2026
c184003
fix(codex): run the session pass after the history copies, and write …
brennanb2025 Nov 20, 2026
6ce1919
Merge remote-tracking branch 'origin/main' into brennanb2025/codex-le…
brennanb2025 Nov 20, 2026
9361342
fix(codex): copy histories, sessions and the marker in one synchronou…
brennanb2025 Nov 20, 2026
f53e6d6
fix(codex): remove only listed login files beside a linked history; m…
brennanb2025 Nov 20, 2026
3cc96ac
fix(codex): leave a linked secrets folder's files alone; reuse one te…
brennanb2025 Nov 20, 2026
96cf8ec
fix(codex): remove nothing from a home whose history is a link; copy …
brennanb2025 Nov 20, 2026
0c37e1d
refactor(codex): main's migration marker, capped session retries, Win…
brennanb2025 Nov 20, 2026
b5e6170
fix(codex): keep session conflict copies only from a session pass tha…
brennanb2025 Nov 20, 2026
2e64257
fix(codex): a failing session pass removes the conflict copies it made
brennanb2025 Nov 20, 2026
29ca9ef
test(codex): skip the linked account history test on Windows
brennanb2025 Nov 23, 2026
441e1c0
Merge origin/main into brennanb2025/codex-legacy-migration-no-overwrite
brennanb2025 Nov 23, 2026
992489f
test(codex): check session copies and the shared history right after …
brennanb2025 Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/main-blocking-helper-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
4 src/main/codex-accounts/runtime-home/credentials/runtime-home-service-auth-sync.ts
19 src/main/codex-accounts/runtime-home/legacy-host/legacy-shared-auth-migration.ts
2 src/main/codex-accounts/runtime-home/legacy-host/legacy-shared-config-compatibility.ts
3 src/main/codex-accounts/runtime-home/legacy-host/runtime-home-service-legacy-migration.ts
2 src/main/codex-accounts/runtime-home/legacy-host/runtime-home-service-legacy-migration.ts
11 src/main/codex-accounts/runtime-home/routing/runtime-home-service-home-routing.ts # Codex launch prep from #43365 already merged; unblocks main, async follow-up owed
9 src/main/codex-accounts/runtime-home/routing/runtime-home-service-launch.ts
8 src/main/codex-accounts/runtime-home/routing/runtime-home-service-managed-home.ts
Expand Down
2 changes: 1 addition & 1 deletion config/main-sync-fs-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
23 src/main/codex-accounts/runtime-home/credentials/runtime-home-service-auth-sync.ts
2 src/main/codex-accounts/runtime-home/credentials/runtime-home-service-wsl-core.ts
2 src/main/codex-accounts/runtime-home/legacy-host/legacy-shared-auth-migration.ts
19 src/main/codex-accounts/runtime-home/legacy-host/runtime-home-service-legacy-migration.ts
13 src/main/codex-accounts/runtime-home/legacy-host/runtime-home-service-legacy-migration.ts
1 src/main/codex-accounts/runtime-home/routing/runtime-home-service-managed-home.ts
14 src/main/codex-accounts/runtime-home/runtime-home-service-paths.ts
1 src/main/codex-accounts/runtime-home/runtime-home-service-sync.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ describe('CodexManagedHomeLifecycle.safeRemove', () => {
const f = fixture()
mkdirSync(join(f.home, 'sessions'))
writeFileSync(join(f.home, 'sessions', 'rollout.jsonl'), 'only copy\n')
writeFileSync(join(f.home, 'history.jsonl'), '{"text":"only prompt"}\n')
writeFileSync(join(f.home, 'auth.json'), '{}')

await f.lifecycle.safeRemove(f.home, 'a')

expect(readdirSync(f.home)).toEqual(['sessions'])
expect(readdirSync(f.home).sort()).toEqual(['history.jsonl', 'sessions'])
expect(readFileSync(join(f.home, 'history.jsonl'), 'utf8')).toBe('{"text":"only prompt"}\n')
expect(readFileSync(join(f.home, 'sessions', 'rollout.jsonl'), 'utf8')).toBe('only copy\n')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ const WSL_MANAGED_HOME_TIMEOUT_MS = 5_000
// that was busy at every launch may still hold its only copy, and a merge keeps conflicting
// copies (and set-aside rollout forms, listed in the cleanup manifest) beside the links; all of
// it outlives the login. A home that was shared (it has the manifest) keeps its own databases
// too: deleting them waits for a later release that has seen the shared store work.
// too: deleting them waits for a later release that has seen the shared store work. The prompt
// history stays as well: it may be the only copy of prompts never merged into the shared history.
const KEPT_HISTORY = [
'history.jsonl',
'sessions',
'archived_sessions',
SET_ASIDE_ROLLOUTS_DIR,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { randomUUID } from 'node:crypto'
import { link, lstat, open, readFile, readdir, rm } from 'node:fs/promises'
import { join } from 'node:path'
import { errnoCodeOrUnknown } from '../../../../shared/errors/errno-code'
import { track } from '../../../telemetry/client'
import type { CODEX_LEGACY_HISTORY_IMPORT_OUTCOMES } from '../../../../shared/telemetry/schemas/telemetry-codex-legacy-history-event-schemas'

type LegacyHistoryImportOutcome = (typeof CODEX_LEGACY_HISTORY_IMPORT_OUTCOMES)[number]

async function pathExists(path: string): Promise<boolean> {
try {
await lstat(path)
return true
} catch (error) {
if (errnoCodeOrUnknown(error) === 'ENOENT') {
return false
}
throw error
}
}

// Every account's own history file, ownership marker or not: a removed or shared home keeps it.
async function listAccountHistories(accountsRoot: string): Promise<string[]> {
const accounts = await readdir(accountsRoot, { withFileTypes: true }).catch((error: unknown) => {
if (errnoCodeOrUnknown(error) === 'ENOENT') {
return []
}
throw error
})
const paths: string[] = []
for (const account of accounts.filter((entry) => entry.isDirectory())) {
const historyPath = join(accountsRoot, account.name, 'home', 'history.jsonl')
const stats = await lstat(historyPath).catch(() => null)
Comment thread
brennanb2025 marked this conversation as resolved.
Resolved
if (stats?.isFile()) {
paths.push(historyPath)
}
}
return paths.sort()
}

/**
* Codex may be appending to or trimming a shared history.jsonl that exists, so only a missing one
* is created from the account histories, which are only read, and never over one Codex creates
* meanwhile. Rejects on failure, so the migration retries on the next launch.
*/
export async function importLegacyHistoriesIfSharedAbsent(
accountsRoot: string,
runtimeHistoryPath: string
): Promise<void> {
const accountHistoryPaths = await listAccountHistories(accountsRoot)
if (accountHistoryPaths.length === 0) {
return
}
let outcome: LegacyHistoryImportOutcome = 'failed'
try {
outcome = await publishLegacyHistoriesIfAbsent(accountHistoryPaths, runtimeHistoryPath)
} finally {
trackLegacyHistoryImport(outcome)
}
}

async function publishLegacyHistoriesIfAbsent(
accountHistoryPaths: readonly string[],
runtimeHistoryPath: string
): Promise<LegacyHistoryImportOutcome> {
if (await pathExists(runtimeHistoryPath)) {
return 'skipped_existing'
}
const seenLines = new Set<string>()
for (const accountHistoryPath of accountHistoryPaths) {
for (const line of (await readFile(accountHistoryPath, 'utf-8')).split('\n')) {
if (line) {
seenLines.add(line)
}
}
}
if (seenLines.size === 0) {
return 'nothing_to_import'
}
return publishWithoutOverwrite(`${[...seenLines].join('\n')}\n`, runtimeHistoryPath)
}

// exFAT, FAT32 and some network or FUSE mounts refuse hard links.
const HARD_LINK_UNSUPPORTED = new Set(['EPERM', 'ENOTSUP', 'EOPNOTSUPP', 'ENOSYS', 'EXDEV'])

async function publishWithoutOverwrite(
contents: string,
targetPath: string
): Promise<LegacyHistoryImportOutcome> {
const tmpPath = `${targetPath}.${process.pid}.${randomUUID()}.tmp`
try {
const handle = await open(tmpPath, 'wx', 0o600)
try {
await handle.writeFile(contents, 'utf-8')
await handle.sync()
} finally {
await handle.close()
}
// A hard link publishes only into a free name: one Codex created meanwhile stays as it is.
await link(tmpPath, targetPath)
return 'imported'
} catch (error) {
const code = errnoCodeOrUnknown(error)
if (code === 'EEXIST') {
return 'skipped_existing'
}
// No safe way to publish without replacing: every other way leaves a name Codex can append
// into mid-write. The account histories stay in their homes, so nothing is lost.
if (HARD_LINK_UNSUPPORTED.has(code)) {
return 'skipped_no_hard_links'
Comment thread
brennanb2025 marked this conversation as resolved.
Resolved
}
throw error
} finally {
await rm(tmpPath, { force: true })
}
}

function trackLegacyHistoryImport(outcome: LegacyHistoryImportOutcome): void {
try {
track('codex_legacy_history_import', {
outcome,
platform:
process.platform === 'win32' || process.platform === 'linux' ? process.platform : 'darwin'
})
} catch {
// Telemetry never costs the migration.
}
}
Loading
Loading