Sweep stale Codex marketplace staging clones on startup#6404
Conversation
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe runtime home service now sweeps stale marketplace staging and backup directories during startup and WSL runtime-home setup. The sweep uses directory name prefixes plus a one-hour age threshold, and it ignores filesystem errors and races. New tests cover aged and fresh staging directories, unrelated directories, missing marketplace trees, and WSL-specific cleanup behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6adb5405-c9e1-4dda-b9ba-87e9d91087ab
📒 Files selected for processing (2)
src/main/codex-accounts/runtime-home-service.test.tssrc/main/codex-accounts/runtime-home-service.ts
Codex CLI stages git-sourced marketplace upgrades/adds by cloning the full repo (~100-230MB each) into <CODEX_HOME>/.tmp/marketplaces/.staging/ before atomically swapping it into place. When the CLI is killed or a clone times out mid-sync, the staging clone is orphaned and never reclaimed, accumulating indefinitely under the runtime home Orca manages (openai/codex#21005, #29994 — reporters saw 22GB / 187GB / 277GB pile-ups). Orca can't fix the upstream lifecycle but owns codex-runtime-home, so it now sweeps aged orphans: dirs matching the exact upstream prefixes (marketplace-upgrade-*, marketplace-add-* under .staging/, and marketplace-backup-* at the marketplaces root) older than 1h. The sweep runs for the host runtime home on construction and for each WSL runtime home when its selection is synced. The conservative threshold (vs upstream's ~10m) avoids razing a long git clone from an externally- launched Codex process; a completed staging dir is promoted in milliseconds, so an hour-old dir is unambiguously stale. The sweep is best-effort and never blocks runtime-home setup or launch.
aaa4c43 to
ed72a09
Compare
Summary
Codex CLI stages git-sourced marketplace upgrades/adds by cloning the full repo (~100-230 MB each, mostly
.githistory) into<CODEX_HOME>/.tmp/marketplaces/.staging/marketplace-upgrade-*(andmarketplace-add-*) before atomically swapping it into place. If the CLI is killed, crashes, or a clone times out mid-sync, the staging clone is orphaned and can accumulate indefinitely under Orca's managed Codex runtime home.This is an upstream Codex bug (openai/codex#21005, openai/codex#29994). Orca does not pin the user's Codex CLI version, but it owns the runtime home the leak lands in, so this PR bounds the disk growth for Orca-launched Codex sessions.
The sweep removes only aged orphan dirs matching these exact upstream temp prefixes:
.tmp/marketplaces/.staging/marketplace-upgrade-*.tmp/marketplaces/.staging/marketplace-add-*.tmp/marketplaces/marketplace-backup-*It runs for the host runtime home on startup and for WSL runtime homes when the WSL selection is synced.
Screenshots
No visual change.
Testing
pnpm exec vitest run src/main/codex-accounts/runtime-home-service.test.tspnpm exec tsgo --noEmit -p config/tsconfig.node.jsonpnpm exec oxlint src/main/codex-accounts/runtime-home-service.ts src/main/codex-accounts/runtime-home-service.test.tspnpm exec oxfmt --write src/main/codex-accounts/runtime-home-service.ts src/main/codex-accounts/runtime-home-service.test.tsAI Review Report
Reviewed the cleanup for race safety, cross-platform behavior, and repo-fit. The review flagged that checking only the staging root directory
mtimecould delete a long-running clone whose recent writes happen deeper under.git/objects; the implementation now compares the newest mtime anywhere in the candidate subtree before deleting. The review also checked macOS/Linux/Windows path handling, including WSL UNC runtime homes; the code keepspath.join/Node fs handling already used byCodexRuntimeHomeServicefor WSL runtime-home files and leaves shell-specific WSL symlink migration unchanged.Security Audit
This change does not add IPC, network calls, command execution, dependencies, or auth handling. Path deletion is constrained to Orca's managed Codex runtime home, exact known Codex marketplace temp prefixes, and dirs whose newest subtree activity is older than one hour. The sweep is best-effort and fail-open: filesystem errors are logged and never block runtime-home setup or Codex launch.
Notes
The upstream Codex issues remain open and no upstream cleanup PR is currently merged. This Orca-side sweep is defensive and can be removed later if Orca starts pinning a Codex version that includes upstream marketplace temp cleanup.