Skip to content

[Bug][macOS] codex-shim restore lock with two owner files is never reclaimed, so the launcher stays broken #8317

Closed

Description

@jayjay181818

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:

  1. On macOS with OpenCodex 2.98.0, launcher repairs had run repeatedly (leftovers dated 6 Nov 14:22 → 7 Nov 09:42).
  2. 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.
  3. ocx codex-shim install → "already in progress", every time. ocx codex-shim status → not ready, PATH inactive.
  4. 97 + 97 + 97 .stage / .probe-* leftovers had built up in ~/.opencodex and ~/.opencodex/bin.

Cause, from src/codex/shim-restore-lock.ts (unchanged on main and dev as of 7 Nov):

  • readShimRestoreLockSnapshot() returns null unless the lock directory has exactly one entry ending in .json: if (entries.length !== 1 || !entries[0].endsWith(".json")) return null;
  • reclaimStaleRestoreLock() returns false on a null snapshot, so its stale-age and isProcessAlive(pid) checks never run, and tryAcquireShimRestoreLock() 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:

  1. Reclaim when every *.json owner record has a dead pid and the newest is older than the stale timeout. Ignore or remove unknown entries.
  2. Make acquisition single-writer: only write the owner file when createdDirectory is true, or use one lock file opened with O_CREAT|O_EXCL.
  3. Clean up .stage / .probe-* leftovers after a failed attempt.
  4. 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

  1. added
    bug
    on Nov 7, 2026
  2. added
    cli
    platform
    on Nov 7, 2026
  3. Ingwannu commented on Nov 8, 2026

    @Ingwannu
    Owner

    Thanks for the detailed state and the workaround. I checked origin/dev f8dfc2f.

    Confirmed: readShimRestoreLockSnapshot returns null unless the lock directory contains exactly one entry, and that entry ends in .json (src/codex/shim-restore-lock.ts:56). reclaimStaleRestoreLock returns false on null (:86-87), so the stale-age and isProcessAlive checks (:89-90) never run. A lock directory with two dead owner files is therefore never reclaimed, and ocx codex-shim install keeps 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 .stage and .probe-* leftovers come from src/codex/shim-overlay.ts:329 and :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.

  4. Ingwannu commented on Nov 8, 2026

    @Ingwannu
    Owner

    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.

  5. added a commit that references this issue on Nov 9, 2026
    9fb295b
  6. added a commit that references this issue on Nov 9, 2026
    f3657d3
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

    bugcliplatform

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions