Skip to content

Plugin refresh error leaves orphaned marketplace-plugin-source clones and .tmp/git-* dirs (second unawaited refresh wave) #55068

Open

Description

@Kenmege

What version of Codex is running?

codex-cli 0.160.1 (also reproduced on 0.163.0), macOS (arm64)

What happened?

$CODEX_HOME/plugins/.marketplace-plugin-source-staging/ fills with complete git clones of plugin sources (marketplace-plugin-source-XXXXXX) that are never deleted, each paired with an orphaned $CODEX_HOME/.tmp/git-XXXXXX directory. On one machine this reached ~860 directories / ~3 GB in four days, growing by roughly 100 directories per hour.

Root cause

  1. plugin/list with forceRefetch: true runs the non-curated plugin cache refresh synchronously and cleans up its own staging clones.
  2. If any configured plugin fails to refresh (in our case a local-marketplace plugin whose source path was a dangling symlink), refreshed is false and state.last_refreshed is never set (codex-rs/core-plugins/src/manager.rs, the if refreshed { state.last_refreshed = Some(request.clone()); } guard, ~L3555 on current main).
  3. Just before returning, plugin/list calls maybe_start_plugin_list_background_tasks_for_config (app-server/src/request_processors/plugins.rs). Because last_refreshed is still unset, it starts a second, unawaited refresh on a detached thread that clones every git-sourced plugin again.
  4. A client that exits the app-server shortly afterwards (for example a one-shot initialize -> plugin/list -> skills/list -> exit caller) orphans the in-flight git clone (it is reparented to PID 1). The clone completes into the staging directory, and neither it nor the GIT_DIR temp directory is ever removed, because the detached thread's TempDir guards never drop.

Related: the non-curated refresh also clones plugins configured with enabled = false. configured_non_curated_plugin_ids filters only by marketplace (core-plugins/src/loader.rs, ~L583), so disabled git plugins are cloned on every refresh.

Steps to reproduce

  1. Configure one local-marketplace plugin whose source path does not exist (dangling symlink), plus a few git-sourced plugins.
  2. Repeatedly start codex app-server --stdio, send initialize, plugin/list with {"forceRefetch": true}, then skills/list, and terminate the process as soon as skills/list returns.
  3. Watch $CODEX_HOME/plugins/.marketplace-plugin-source-staging/ and $CODEX_HOME/.tmp/git-*: clones started after plugin/list returns are orphaned and accumulate.

Evidence

  • A/B with only the broken plugin entry changed (3 runs per arm): 13 clones per refresh with the failing entry, 6 without it. The second wave disappears.
  • 10-minute live observation: 149 clones, 18 left behind before the change; 36 clones, 0 left behind after removing the failing entry.

Expected behavior

One failing plugin should not cause every refresh to re-run in the background, and no clone or temp directory should outlive the app-server process.

Suggested fixes

  • Record refresh completion per plugin (or set last_refreshed together with the error set) so a single failing plugin does not trigger a duplicate background wave.
  • Join or cancel background refresh threads on shutdown, or sweep stale marketplace-plugin-source-* and .tmp/git-* directories older than a few minutes, as is already done for curated clones (CURATED_PLUGINS_STALE_TEMP_DIR_MAX_AGE).
  • Skip plugins with enabled = false in the non-curated refresh.

Activity

  1. added
    bug
    CLI
    skills
    app-server
    on Oct 18, 2026
  2. bomtobe-hgkim commented on Oct 18, 2026

    @bomtobe-hgkim

    A regression test could queue two forceRefetch calls while one plugin is broken, then wait for both refresh workers to settle before checking that staging and .tmp contain no orphan clones. I would also assert that the healthy plugin is not cloned again in a duplicate background wave and that the original failure remains visible to the caller. I work with BOMTOBE/Orke; I have not reproduced this locally, so this is a test suggestion based on the report.

  3. simfor99 commented on Nov 3, 2026

    @simfor99

    Can confirm the .tmp/git-* half of this leak on Linux/WSL2 at an extreme scale: on our machine, ~/.codex/.tmp/ had accumulated 352,950 orphaned git-XXXXXX directories (each an empty bare-git stub with HEAD, objects/info, objects/pack, refs/heads, refs/tags).

    Two operational consequences worth highlighting:

    1. Inode exhaustion and directory-inode bloat: 352,950 git-* directories consumed over 1.4 million inodes and bloated the ~/.codex/.tmp directory inode itself to 12 MiB (12,054,528 bytes). Once an ext4 directory inode grows that large, every readdir() / ls / stat walk inside ~/.codex/.tmp slows to a crawl, and even after unlinking the 352k subdirectories, ext4 does not shrink the 12 MiB directory entry table unless .tmp itself is atomically recreated.
    2. Safe automated cleanup + directory compaction: Until the upstream TempDir lifecycle is fixed, we built an open-source guard that sweeps empty ~/.codex/.tmp/git-* stubs older than 15 minutes (after verifying no process has an open FD or cwd under /proc/*/fd and /proc/*/cwd and no packfiles/loose objects exist inside objects/) and then atomically compacts ~/.codex/.tmp under flock when its directory inode exceeds 1 MiB: https://github.com/simfor99/codex-hdd-guard (MIT, Python 3.10+ stdlib only, zero dependencies).

    On our live run it cleared 352,902 stale git-* directories and shrank the .tmp directory inode from 12 MiB back down to 1008 KiB.

  4. TheOutlandsDev commented on Nov 4, 2026

    @TheOutlandsDev

    I reproduced the duplicate refresh wave on tagged rust-v0.166.0 in an offline Linux container using only synthetic local repositories.

    The focused codex-core-plugins test has two arms. Both configure a healthy Git-backed plugin. The second arm also configures a local plugin whose source is a dangling symlink. For each arm, it calls refresh_non_curated_plugin_cache_for_context, then maybe_start_non_curated_plugin_cache_refresh, waits for any scheduled background worker to settle, and counts git clone invocations with a PATH wrapper that immediately executes real Git.

    Fixture Git clones
    Healthy Git plugin only 1
    Git plugin plus broken local plugin 2

    The broken arm leaves last_refreshed unset after the explicit refresh, so the subsequent background check clones the healthy Git source again. The focused test passed (1 passed; 0 failed). This confirms the duplicate-wave mechanism on a newer release than the original report.

    This component test did not start or stop codex app-server; it waited for the manager's refresh workers to finish. It does not independently reproduce the orphaned child or directory accumulation after app-server exit. A minimal test patch and sanitized log are available if useful.

  5. TheOutlandsDev commented on Nov 4, 2026

    @TheOutlandsDev

    Follow-up to my earlier release test: I also reproduced the app-server exit portion on tagged rust-v0.166.0 in an offline Linux container with a disposable Codex home and local Git repository.

    The fixture configured one healthy Git-backed plugin and one local plugin with a dangling-symlink source. I started the tagged codex-app-server binary with plugin startup tasks disabled, sent initialize and plugin/list with forceRefetch: true, and used an executable PATH wrapper to record Git commands and pause only the second git clone. The wrapper recorded two clones: the first completed during the forced refresh, and the second began in the background after the broken plugin caused a refresh error.

    While the second clone was paused, I closed app-server stdin. App-server exited with code 0 within six seconds. Immediately afterward, the second Git wrapper PID was still alive, and both a plugins/.marketplace-plugin-source-staging/marketplace-plugin-source-* directory and a .tmp/git-* directory remained in the temporary Codex home. I then stopped the synthetic process group and removed the fixture.

    This confirms the process and directory state at app-server exit on this release. The bounded test did not let the orphan finish its clone or measure accumulation across repeated launches. No live service traffic was sent. I can provide the small Python harness and sanitized output if useful.

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

    CLIapp-serverbugskills

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions