codex - ✅(Solved) Fix Marketplace upgrade staging directories leak in `.tmp/marketplaces/.staging/` [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#21005Fetched 2026-05-05 05:54:39
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×2

Marketplace upgrade and add operations create temporary staging directories under <CODEX_HOME>/.tmp/marketplaces/.staging/ with prefixes marketplace-upgrade-* and marketplace-add-*. If the process crashes or is killed during these operations, the TempDir destructor never runs and these directories accumulate permanently with no cleanup.

On an active installation this can grow to hundreds of GB over time (each git clone is ~230MB). I personally found 2293 orphaned directories totalling 187GB on a single machine:

$ du -sh ~/.codex/.tmp/marketplaces/.staging/
187G

$ ls ~/.codex/.tmp/marketplaces/.staging/ | wc -l
2293

Error Message

  1. Activation error path in activation.rs:94-127: backup_dir.keep() is called on double-failure (rename fails AND rollback fails), permanently preserving marketplace-backup-* directories.

Root Cause

There are three leak paths:

  1. Process crash/kill: TempDir in marketplace_upgrade.rs:195-203 is never dropped, staging dir is orphaned permanently.
  2. Git clone timeout (30s in git.rs): Partially cloned directories remain in .staging/ with no cleanup.
  3. Activation error path in activation.rs:94-127: backup_dir.keep() is called on double-failure (rename fails AND rollback fails), permanently preserving marketplace-backup-* directories.

There is no equivalent of remove_stale_curated_repo_temp_dirs() (which exists in startup_sync.rs:258-341 for plugins-clone-* dirs) for the marketplace staging path.

Fix Action

Fixed

PR fix notes

PR #1: fix(plugins): clean up orphaned marketplace staging directories on startup

Description (problem / solution / changelog)

Summary

Add startup cleanup for orphaned marketplace staging directories that accumulate when the process crashes or is killed during marketplace upgrade/add operations.

Fixes openai/codex#21005

Problem

Marketplace upgrade and add operations create temp directories under <CODEX_HOME>/.tmp/marketplaces/.staging/ with prefixes marketplace-upgrade-* and marketplace-add-*. If the process is interrupted, TempDir destructors never run and these directories leak permanently. On active installations this can grow to hundreds of GB.

There is no equivalent of remove_stale_curated_repo_temp_dirs() (which cleans up plugins-clone-* dirs in startup_sync.rs:258-341) for the marketplace staging path.

Changes

  • Added remove_stale_marketplace_temp_dirs() in marketplace_upgrade.rs, modeled after the existing remove_stale_curated_repo_temp_dirs() in startup_sync.rs
  • Cleans up marketplace-upgrade-*, marketplace-add-* in .staging/, and marketplace-backup-* at the install root level — all older than 10 minutes
  • Called at the start of upgrade_configured_git_marketplaces() and add_marketplace_sync_with_cloner()

Testing

Manual verification on a machine with 2293 orphaned staging directories (187GB). After the fix, stale directories are cleaned on next marketplace operation.

🤖 Generated with Claude Code

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

Summary by CodeRabbit

New Features

  • Marketplace operations now automatically clean up stale temporary and backup directories.
  • During marketplace add and upgrade operations, temporary files from previous or incomplete operations are automatically scanned and removed.
  • Old temporary and backup directories exceeding the configured age threshold are cleaned up automatically to optimize disk space and improve overall system maintenance.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Changed files

  • codex-rs/core-plugins/src/marketplace_add.rs (modified, +2/-0)
  • codex-rs/core-plugins/src/marketplace_upgrade.rs (modified, +125/-0)

Code Example

$ du -sh ~/.codex/.tmp/marketplaces/.staging/
187G

$ ls ~/.codex/.tmp/marketplaces/.staging/ | wc -l
2293
RAW_BUFFERClick to expand / collapse

Summary

Marketplace upgrade and add operations create temporary staging directories under <CODEX_HOME>/.tmp/marketplaces/.staging/ with prefixes marketplace-upgrade-* and marketplace-add-*. If the process crashes or is killed during these operations, the TempDir destructor never runs and these directories accumulate permanently with no cleanup.

On an active installation this can grow to hundreds of GB over time (each git clone is ~230MB). I personally found 2293 orphaned directories totalling 187GB on a single machine:

$ du -sh ~/.codex/.tmp/marketplaces/.staging/
187G

$ ls ~/.codex/.tmp/marketplaces/.staging/ | wc -l
2293

Root Cause

There are three leak paths:

  1. Process crash/kill: TempDir in marketplace_upgrade.rs:195-203 is never dropped, staging dir is orphaned permanently.
  2. Git clone timeout (30s in git.rs): Partially cloned directories remain in .staging/ with no cleanup.
  3. Activation error path in activation.rs:94-127: backup_dir.keep() is called on double-failure (rename fails AND rollback fails), permanently preserving marketplace-backup-* directories.

There is no equivalent of remove_stale_curated_repo_temp_dirs() (which exists in startup_sync.rs:258-341 for plugins-clone-* dirs) for the marketplace staging path.

Proposed Fix

Add remove_stale_marketplace_temp_dirs() modeled after the existing cleanup in startup_sync.rs, called at the start of:

  • upgrade_configured_git_marketplaces()
  • add_marketplace_sync_with_cloner()

Cleans up directories older than 10 minutes, covering:

  • marketplace-upgrade-* in .staging/
  • marketplace-add-* in .staging/
  • marketplace-backup-* at the install root level

Related

  • #16004 — similar leak for plugins-clone-* directories in startup_sync.rs
  • #19834 — stale marketplace clone discoverability (separate concern)

extent analysis

TL;DR

Implement a cleanup function remove_stale_marketplace_temp_dirs() to remove orphaned marketplace staging directories.

Guidance

  • Identify the leak paths: process crash/kill, git clone timeout, and activation error path, to understand where the issue originates.
  • Implement remove_stale_marketplace_temp_dirs() to clean up directories older than 10 minutes, covering marketplace-upgrade-*, marketplace-add-*, and marketplace-backup-* directories.
  • Call the cleanup function at the start of upgrade_configured_git_marketplaces() and add_marketplace_sync_with_cloner() to prevent further accumulation.
  • Verify the fix by checking the size of the .staging/ directory and the number of orphaned directories after running the cleanup function.

Example

// Example implementation of remove_stale_marketplace_temp_dirs()
fn remove_stale_marketplace_temp_dirs() {
    // Define the directory paths and prefixes to clean up
    let staging_dir = "<CODEX_HOME>/.tmp/marketplaces/.staging/";
    let prefixes = ["marketplace-upgrade-", "marketplace-add-"];
    let backup_dir = "<CODEX_HOME>/marketplace-backup-";
    
    // Remove directories older than 10 minutes
    // ...
}

Notes

The proposed fix assumes that the remove_stale_curated_repo_temp_dirs() function in startup_sync.rs can be used as a model for the new cleanup function. The implementation details of the cleanup function are not provided, but it should cover the specified directory paths and prefixes.

Recommendation

Apply the proposed fix by implementing the remove_stale_marketplace_temp_dirs() function and calling it at the start of the specified functions, as it directly addresses the identified leak paths and provides a solution to the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - ✅(Solved) Fix Marketplace upgrade staging directories leak in `.tmp/marketplaces/.staging/` [1 pull requests, 1 participants]