Repository navigation
Description
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
plugin/listwithforceRefetch: trueruns the non-curated plugin cache refresh synchronously and cleans up its own staging clones.- If any configured plugin fails to refresh (in our case a local-marketplace plugin whose source path was a dangling symlink),
refreshedis false andstate.last_refreshedis never set (codex-rs/core-plugins/src/manager.rs, theif refreshed { state.last_refreshed = Some(request.clone()); }guard, ~L3555 on currentmain). - Just before returning,
plugin/listcallsmaybe_start_plugin_list_background_tasks_for_config(app-server/src/request_processors/plugins.rs). Becauselast_refreshedis still unset, it starts a second, unawaited refresh on a detached thread that clones every git-sourced plugin again. - A client that exits the app-server shortly afterwards (for example a one-shot
initialize -> plugin/list -> skills/list -> exitcaller) orphans the in-flightgit clone(it is reparented to PID 1). The clone completes into the staging directory, and neither it nor theGIT_DIRtemp directory is ever removed, because the detached thread'sTempDirguards 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
- Configure one local-marketplace plugin whose source path does not exist (dangling symlink), plus a few git-sourced plugins.
- Repeatedly start
codex app-server --stdio, sendinitialize,plugin/listwith{"forceRefetch": true}, thenskills/list, and terminate the process as soon asskills/listreturns. - Watch
$CODEX_HOME/plugins/.marketplace-plugin-source-staging/and$CODEX_HOME/.tmp/git-*: clones started afterplugin/listreturns 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_refreshedtogether 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 = falsein the non-curated refresh.
Activity
bomtobe-hgkim commentedon Oct 18, 2026
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.
simfor99 commentedon Nov 3, 2026
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 orphanedgit-XXXXXXdirectories (each an empty bare-git stub withHEAD,objects/info,objects/pack,refs/heads,refs/tags).Two operational consequences worth highlighting:
git-*directories consumed over 1.4 million inodes and bloated the~/.codex/.tmpdirectory inode itself to 12 MiB (12,054,528bytes). Once an ext4 directory inode grows that large, everyreaddir()/ls/ stat walk inside~/.codex/.tmpslows to a crawl, and even after unlinking the 352k subdirectories, ext4 does not shrink the 12 MiB directory entry table unless.tmpitself is atomically recreated.TempDirlifecycle 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 orcwdunder/proc/*/fdand/proc/*/cwdand no packfiles/loose objects exist insideobjects/) and then atomically compacts~/.codex/.tmpunderflockwhen 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.tmpdirectory inode from 12 MiB back down to 1008 KiB.TheOutlandsDev commentedon Nov 4, 2026
I reproduced the duplicate refresh wave on tagged
rust-v0.166.0in an offline Linux container using only synthetic local repositories.The focused
codex-core-pluginstest 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 callsrefresh_non_curated_plugin_cache_for_context, thenmaybe_start_non_curated_plugin_cache_refresh, waits for any scheduled background worker to settle, and countsgit cloneinvocations with aPATHwrapper that immediately executes real Git.The broken arm leaves
last_refreshedunset 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.TheOutlandsDev commentedon Nov 4, 2026
Follow-up to my earlier release test: I also reproduced the app-server exit portion on tagged
rust-v0.166.0in 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-serverbinary with plugin startup tasks disabled, sentinitializeandplugin/listwithforceRefetch: true, and used an executablePATHwrapper to record Git commands and pause only the secondgit 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.