Repository navigation
feat(codex): one-time backfill of managed-home sessions into the real Codex home - #8802
brennanb2025 wants to merge 6 commits into
Conversation
…once per host Orca-launched Codex sessions currently land only in the Orca-managed runtime home, so the user's own `codex resume` picker and app history never see them (#4444, #8612). Backfill the managed sessions tree into the real ~/.codex/sessions/YYYY/MM/DD layout once per host: - hardlink first (one physical rollout log), copy as the cross-volume fallback; existing target files are always skipped, nothing in either home is deleted or moved - idempotent; per-file failures leave the completion marker unset so the next startup retries cheaply - JSONL audit log of every link/copy/failure under <userData>/codex-session-backfill/ - honors the custom Codex session source home override, mirroring the existing system->managed bridge WSL managed homes are distro-local and need an in-distro variant; that is a follow-up.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a Codex session backfill utility that scans managed session JSONL files, hardlinks or copies them into the system Codex home, records audit data, and avoids overwriting existing entries. Completion markers, retry behavior, concurrency protection, custom home resolution, and startup scheduling are included. Tests cover filesystem behavior, failures, idempotency, marker handling, retries, and delayed application startup execution. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Use asynchronous, sequential filesystem operations for the one-time rollout backfill, and avoid repeated target-directory probes. Treat inaccessible managed session roots as retryable failures instead of writing a false completion marker.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/codex/codex-session-backfill.ts (1)
308-324: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valuePrefer asynchronous
readFileto avoid blocking the main thread.To fully adhere to the PR objective of performing filesystem operations off the main thread, consider making this function
asyncand usingreadFilefromnode:fs/promisesinstead ofreadFileSync.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 486195b5-249e-4874-8d4f-613fad3d9524
📒 Files selected for processing (5)
src/main/codex/codex-session-backfill-audit.tssrc/main/codex/codex-session-backfill-copy.tssrc/main/codex/codex-session-backfill.test.tssrc/main/codex/codex-session-backfill.tssrc/main/codex/codex-session-file-listing.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/codex/codex-session-file-listing.ts
- src/main/codex/codex-session-backfill.test.ts
On a real Codex home whose filesystem supports no hardlinks (exFAT/FAT, some network mounts), the staged cross-volume copy was installed with a non-atomic copyFile(..., COPYFILE_EXCL) straight into the final rollout-*.jsonl name. An install interrupted mid-copy (app quit, crash, ENOSPC during the deferred run) could strand a truncated rollout that the next run then skips as already-present, defeating the staging design's own guarantee that a failed copy never leaves a partial session behind. Install the fully-staged copy with an atomic rename instead, guarded by an existence re-check so it keeps the never-overwrite contract (and the rename source is the same immutable managed rollout, so any clobber would be byte-identical). Cover the no-hardlink-support target and an interrupted install that must leave no partial in the user's sessions tree.
Live E2E validation — PASS (6/6)Validated live against the real Electron app (branch head
Automated live validation run as part of the pre-RC hardening sweep. |
|
Closing as superseded: this work landed on main via #9501 (real-home routing + self-contained multi-account homes) and shipped in v1.4.149 stable. Content verified present on main (module + wiring spot-checked). |
Summary
One-time, non-destructive backfill of Codex session rollout files from Orca's managed runtime home into the user's real
~/.codex/sessions/YYYY/MM/DD/tree.Codex sessions launched inside Orca currently land only in the Orca-managed
CODEX_HOME, so the user's owncodex resumepicker and Codex app history never see them (#4444, #8612). This PR makes the historical backlog visible in the provider-native home while changing nothing else about where new sessions are written. It complements the account-ownership direction in #8606 (credit to @jellychoco for the routing direction): once system-default launches move to the native home, this backfill is what keeps pre-existing Orca history discoverable there.Behavior
<userData>/codex-runtime-home/home/sessions/**incrementally (same batched walker the existing system→managed bridge uses) and places each rollout at the identical relative path under the real Codex home. Thecodex resumepicker enumerates and parses this exact layout.COPYFILE_EXCL) for cross-volume homes.EEXISThandling.<userData>/codex-session-backfill/backfill-complete.json). Per-file failures leave the marker unset so the next startup retries; the retry is cheap because everything already placed is skipped. Runs deferred (15s after service init) so startup and first PTY spawns never compete with the tree walk.<userData>/codex-session-backfill/audit.jsonl): one JSONL record per hardlink/copy/failure plus a per-run summary with skip counts.CODEX_HOMEget history where theircodex resumeactually looks).EEXIST-tolerant).Not in this PR (follow-ups)
wsl-codex-session-bridge.ts). Host (macOS/Linux/Windows) only for now.thread/readwarm-up per backfilled session).Testing
Unit (
src/main/codex/codex-session-backfill.test.ts, 11 tests, all green): layout-preserving hardlinks (inode equality), collision skip with byte-identical target preservation, broken-symlink target treated as taken, symlinked source not materialized, idempotent second run, copy fallback onEXDEV, per-file failure accounting without aborting, no target-tree creation when there is nothing to backfill, marker write/skip semantics, failure→no-marker→retry, custom source home override.Live, fully sandboxed (dev build, isolated
ORCA_DEV_USER_DATA_PATH+ overriddenHOME; the developer's real~/.codexuntouched):statshows identical inode), collision skipped with the user's variant preserved byte-exactly, user's own session untouched.hardlinkrecords +run-summary{scanned 3, linked 2, skipped 1, failed 0}; markerv1written.codex resumepicker on next open (picker output captured:1 / 2, previews shown). Since the backfill places byte-identical hardlinks of genuine rollout files, backfilled Orca sessions are discoverable the same way. (Minimal hand-crafted JSONL fixtures do not pass the picker's parse — visibility requires real rollout content, which real managed sessions have.)tsc(node project) clean,oxlintclean on touched files.