Repository navigation
Closed
Description
Client or integration
Codex CLI
Area
CLI
Summary
~/.opencodex/codex-shim.autorestore.lock/ ended up holding two owner files whose processes were both dead. OpenCodex never reclaims a lock in that state, so ocx codex-shim install reported "already in progress" indefinitely and the Codex launcher (~/.opencodex/bin/codex) stayed broken. Each attempt also left more .stage files and .probe-* folders behind.
Expected: a stale lock whose recorded owners are all dead is reclaimed, and the launcher installs.
Reproduction
Observed state, not a clean repro:
- On macOS with OpenCodex 2.98.0, launcher repairs had run repeatedly (leftovers dated 6 Nov 14:22 → 7 Nov 09:42).
- A repair at 09:42 left
~/.opencodex/codex-shim.autorestore.lock/behind holding two owner files,<pid>-<ms>-<uuid>.json, for pids 81199 and 81201. Both have the same millisecond, and neither process was alive. ocx codex-shim install→ "already in progress", every time.ocx codex-shim status→ not ready, PATH inactive.- 97 + 97 + 97
.stage/.probe-*leftovers had built up in~/.opencodexand~/.opencodex/bin.
Cause, from src/codex/shim-restore-lock.ts (unchanged on main and dev as of 7 Nov):
readShimRestoreLockSnapshot()returnsnullunless the lock directory has exactly one entry ending in.json:if (entries.length !== 1 || !entries[0].endsWith(".json")) return null;reclaimStaleRestoreLock()returnsfalseon anullsnapshot, so its stale-age andisProcessAlive(pid)checks never run, andtryAcquireShimRestoreLock()fails both attempts.- So a lock directory with two or more entries can never be reclaimed, even when every owner is dead. How two owners got into one directory isn't proven. Two owner files from the same millisecond point to a race in the acquire/retry path, e.g. a process writing its owner file into a directory it didn't create.
Suggested fix:
- Reclaim when every
*.jsonowner record has a dead pid and the newest is older than the stale timeout. Ignore or remove unknown entries. - Make acquisition single-writer: only write the owner file when
createdDirectoryis true, or use one lock file opened with O_CREAT|O_EXCL. - Clean up
.stage/.probe-*leftovers after a failed attempt. - Error text should name the lock path, list its owners and give the manual fix.
Version
2.98.0
Operating system
macOS (MacBook Pro)
Provider and model
No response
Logs or error output
ocx codex-shim install → already in progress
ocx codex-shim status → not ready (PATH inactive)Screenshots and supporting files
No response
Redacted configuration
Workaround that worked: move the lock directory aside
mv ~/.opencodex/codex-shim.autorestore.lock ~/opencodex-cleanup-<date>/
then `ocx codex-shim install` → status "ready". Then move the leftover .stage / .probe-* items aside.Checks
- I searched existing issues and documentation.
- I removed secrets, tokens, account details, request credentials, and personal data.
Activity
Ingwannu commentedon Nov 8, 2026
Thanks for the detailed state and the workaround. I checked origin/dev f8dfc2f.
Confirmed:
readShimRestoreLockSnapshotreturns null unless the lock directory contains exactly one entry, and that entry ends in.json(src/codex/shim-restore-lock.ts:56).reclaimStaleRestoreLockreturns false on null (:86-87), so the stale-age andisProcessAlivechecks (:89-90) never run. A lock directory with two dead owner files is therefore never reclaimed, andocx codex-shim installkeeps reporting "already in progress" (src/codex/shim-overlay.ts:459). That defect stands regardless of how the second owner file appeared.Not established: how the second owner file got there. On dev the owner file is written only after this process creates the directory (
shim-restore-lock.ts:122-127), and a failed mkdir writes nothing (:144-158). If you still have the lock directory, the owner file contents, and the build or package that wrote them, that would show whether this came from an older build or a manual copy. The.stageand.probe-*leftovers come fromsrc/codex/shim-overlay.ts:329and:342; we have not confirmed which path left them behind.Until a fix ships, moving the lock directory aside (as you did) is the recovery path.
Ingwannu commentedon Nov 8, 2026
Fix proposed in #8349: a stale lock is now reclaimed when every entry is a valid owner record, every owner is past the stale window with a dead PID, and the owner set is unchanged on reread. A live owner, a fresh owner or an unrecognised entry still blocks reclaim. The PR does not address how the second owner file appeared or the
.stage/.probe-*leftovers.fix(codex): reclaim stale shim restore lock with several dead owners (#…
fix(codex): reclaim stale shim restore lock with several dead owners (#…