Repository navigation
Description
What happened
Two concurrent unlock invocations for the same thread can both send SIGTERM when their --codex-home arguments differ only in letter case on a case-insensitive filesystem (default APFS).
The operation lease key is the SHA-256 of realpathSync(codexHome) and the thread id. Node's JavaScript realpathSync preserves the caller's spelling on case-insensitive volumes, while realpathSync.native returns the on-disk case:
realpathSync('.../casehome') -> '.../casehome'
realpathSync.native('.../casehome') -> '.../CaseHome'
Both invocations therefore acquire different lease files, both pass revalidation (the native lock, owner, and lock set are identical), and both signal.
Reproduction with a same-user fixture owner that records each SIGTERM and exits 300 ms later:
Second invocation --codex-home |
Outcomes A / B | SIGTERMs received |
|---|---|---|
CaseHome (identical) |
unlocked (0) / refused: concurrent_unlock_in_progress (2) |
1 |
casehome |
unlocked (0) / unlocked (0) |
2 |
CASEHOME |
unlocked (0) / unlocked (0) |
2 |
The same structure is expected for NFC/NFD-different spellings of the same path (not reproduced).
What you expected
As documented in docs/safety-race-matrix.md: "One private advisory operation lease per canonical home/thread" → "Exactly one SIGTERM; competitor refused", independent of how the home path is spelled.
Environment
codex-unlock0.4.0 at6227e6c- macOS 27.0 arm64, APFS (case-insensitive), Node.js 22.14.0
Source evidence
- Canonical home via JS
realpathSync:codex-unlock/src/coordination.ts
Line 71 in 6227e6c
canonicalHome = realpathSync(codexHome); - Lease key derived from that string:
codex-unlock/src/coordination.ts
Lines 76 to 81 in 6227e6c
const key = createHash("sha256") .update(canonicalHome) .update("\0") .update(threadId) .digest("hex"); const path = join(root, `${key}.lock`); - Invariant being violated:
codex-unlock/docs/safety-race-matrix.md
Line 14 in 6227e6c
| Two CLI unlocks inspect the same safe owner | One private advisory operation lease per canonical home/thread | Exactly one SIGTERM; competitor refused | `concurrent CLI unlock attempts send at most one SIGTERM` |
Acceptance criteria
- The lease key is derived from filesystem identity (for example
dev:inoof the resolved home or of the native thread lock file) rather than from a path string, or at minimum fromrealpathSync.native. - A regression test on a case-insensitive filesystem runs two concurrent unlocks with case-variant homes and observes exactly one SIGTERM and one
concurrent_unlock_in_progressrefusal.
Scope and limitations
- Not exploitable by another user; requires the same user to start two unlocks concurrently with differently spelled paths (for example two scripts).
- The second SIGTERM normally hits the same exiting owner; if it arrives late it produces ESRCH (
termination_failed) or, in the worst case, widens a PID-reuse window. - Experiments used scratch fixtures only; no real Codex session was signaled.
Checked
- Regression of the guarantee introduced for security: serialize concurrent unlock attempts #34 / fix: serialize concurrent unlock attempts #35; no existing issue covers path-spelling variants.
Activity
abruption commentedon Sep 28, 2026
An additional alias path with the same effect: the lease key is
sha256(realpath(codexHome) + threadId), so two different homes whosethread-writer-locks(andsessions) directories are symlinks to the same targets get different keys while inspection resolves the same native lock and owner.Reproduced with fixtures: while a lease for home A is held,
unlock --codex-home Ais refused withconcurrent_unlock_in_progress, butunlock --codex-home B(B's subdirectories symlinked to A's) returnsunlockedand sendsSIGTERM.Canonicalizing only the home spelling (for example
realpathSync.native) would not close this. Keying the lease on the canonical lock directory or the lock file's device/inode would cover both cases.Source:
codex-unlock/src/coordination.ts
Lines 71 to 80 in 6227e6c
codex-unlock/src/process.ts
Lines 301 to 321 in 6227e6c
fix: key unlock leases by native lock identity