Skip to content

fix(marketplace): prune stale upgrade staging directories #30620

Open

Description

@snowboater

Summary

Marketplace Git auto-upgrade can leave full cloned repositories under:

$CODEX_HOME/.tmp/marketplaces/.staging/marketplace-upgrade-*

Those dirs are expected to be temporary upgrade staging dirs, but if a Codex process is killed or crashes while an upgrade is in flight, tempfile::TempDir cleanup does not run and the staged clone can be left behind.

Observed impact

In one affected environment, .staging contained more than 1,000 marketplace-upgrade-* directories, each a full clone of the same marketplace repository, consuming about 155G total. The installed marketplace cache itself was only about 138M.

Healthy layout should be roughly:

marketplaces/
  <marketplace>/
  .staging/        # empty, or only brief active temp dirs

Affected layout was effectively:

marketplaces/
  <marketplace>/
  .staging/
    marketplace-upgrade-AAAAAA/
    marketplace-upgrade-BBBBBB/
    marketplace-upgrade-CCCCCC/
    ...

Why this can leak

The marketplace upgrade path creates staging dirs with tempfile::Builder and a marketplace-upgrade- prefix. Normal Rust error paths should drop the TempDir and remove the staged clone, but process death before Drop runs leaves the directory behind.

A local repro with a disposable CODEX_HOME confirmed that killing the process during a marketplace clone leaves a marketplace-upgrade-* staging dir behind, and later upgrade attempts do not prune the orphan.

Proposed fix

Proposed fix branch: riverpilot:fix/marketplace-staging-prune

The proposed patch:

  • only scans $CODEX_HOME/.tmp/marketplaces/.staging
  • only removes entries named marketplace-upgrade-*
  • only removes directories, not files or symlinks
  • only removes dirs older than 24 hours
  • logs warnings and continues on cleanup errors
  • runs before the “no configured marketplaces” early return, so stale dirs can still be reclaimed when the marketplace config entry has been removed, as long as the marketplace upgrade path is invoked

It does not add retry/backoff changes or cross-process locking.

Tests in proposed fix

The branch adds tests for:

  • stale marketplace-upgrade-* directories are removed
  • fresh marketplace-upgrade-* directories are kept
  • stale wrong-prefix directories are kept
  • prefix-matching files are kept
  • installed marketplace roots are kept
  • stale staging cleanup still runs when no Git marketplaces are configured, once the marketplace upgrade path is invoked

Local validation

On the proposed branch:

cargo fmt --package codex-core-plugins
cargo test -p codex-core-plugins marketplace_upgrade -- --nocapture

The targeted marketplace upgrade suite passed.

Note

PR creation from the fork is currently blocked by repository owner restrictions, so I am filing this issue with the branch/compare link instead.

Activity

  1. added
    bug
    CLI
    skills
    on Jun 29, 2026
  2. github-actions commented on Jun 29, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. Srcanesen commented on Aug 25, 2026

    @Srcanesen

    Implementing this as PR https://github.com/Srcanesen/codex/pull/1 (branch fix/marketplace-staging-janitor — compare: main...Srcanesen:fix/marketplace-staging-janitor). This revives the proposal with a cross-process advisory lock and the curated-janitor test pattern. Fixes #21005 #32058 #38770 #39332 #39421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugskills

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions