Repository navigation
Description
What happened
The OS lock probe used by list and inspect acquires the thread writer lock exclusively (flock LOCK_EX|LOCK_NB) and releases it immediately when the lock is free. During that short window, a Codex process trying to take the same lock with a non-blocking try_lock fails with WouldBlock.
Upstream Codex acquires thread-writer-locks/.coordination.lock before try_lock() on the per-thread lock and treats WouldBlock as "thread … already has an active writer" (or skips publication in try_acquire_for_publication). codex-unlock never takes .coordination.lock, so its probe is not serialized with Codex's acquisition.
inspectThread probes twice per thread and list probes every lock file.
Reproduction: running dist/lock.js probeLock in a loop against an acquirer that mimics Codex (open, then flock exnb) for 3 seconds produced 4,436 WouldBlock failures out of 155,390 acquisition attempts.
What you expected
Read-only diagnostics (list, inspect) never cause a Codex writer acquisition to fail. The README and docs/cli-reference.md describe these commands as read-only without mentioning this interference.
Environment
codex-unlock0.4.0 at6227e6c- macOS 27.0 arm64, Node.js 22.14.0
Source evidence
- Probe acquires and releases the exclusive lock:
Lines 86 to 123 in 6227e6c
try { const noFollow = constants.O_NOFOLLOW ?? 0; fd = openSync(path, constants.O_RDWR | noFollow); const opened = publicSnapshot(fstatSync(fd)); if ( opened.device !== before.snapshot.device || opened.inode !== before.snapshot.inode ) { return { status: "unknown", method: "flock_exclusive_nonblocking", error: "lock file changed while it was opened", }; } try { flockSync(fd, "exnb"); } catch (error) { if (isContentionError(error)) { return { status: "held", method: "flock_exclusive_nonblocking" }; } return { status: "unknown", method: "flock_exclusive_nonblocking", error: errorText(error), }; } try { flockSync(fd, "un"); } catch (error) { return { status: "unknown", method: "flock_exclusive_nonblocking", error: `probe acquired the lock but unlock failed: ${errorText(error)}`, }; } return { status: "free", method: "flock_exclusive_nonblocking" }; - Two probes per inspected thread: and
codex-unlock/src/inspection.ts
Line 82 in 6227e6c
Promise.resolve(probeLock(lockPath)), codex-unlock/src/inspection.ts
Line 92 in 6227e6c
Promise.resolve(probeLock(lockPath)), listinspects every thread:codex-unlock/src/inspection.ts
Line 198 in 6227e6c
const sessions = await Promise.all(threadIds.map((id) => inspectThread(id, options)));
Acceptance criteria
- Probing is performed while holding
<CODEX_HOME>/thread-writer-locks/.coordination.lock(taken non-blocking; contention classified asunknown, file not created if absent), so Codex's blocking coordination acquire waits instead of failing; or the probe uses a mechanism that cannot make a concurrenttry_lockfail. - A regression test runs a probe loop concurrently with an acquirer that follows the Codex coordination protocol and observes zero WouldBlock failures.
- If the interference cannot be removed, it is documented as a limitation of
list/inspect.
Scope and limitations
- Reliability issue only; the window per probe is microseconds and requires Codex to resume or publish a thread at the same moment.
- Codex behavior was taken from the upstream rollout writer-lock source; the reproduction used a mimicking acquirer, not a real Codex process.
Checked
- No existing issue covers probe interference with Codex acquisition.
Activity
abruption commentedon Sep 28, 2026
Accepted design: coordinated probe with fail-closed guard absence
Decision recorded on 2026-09-29. This resolves the remaining design choice for #55; implementation and validation are still pending.
When a thread lock exists but its native
.coordination.lockis absent, the result isunknown. Never fall back to an uncoordinated thread-lock probe and never create the missing coordination file.ENOENTdoes not establish a safe legacy protocol: deletion, incomplete copies, and concurrent coordinator creation are also possible.Probe contract
.coordination.lockbeside the thread lock in the canonicalthread-writer-locksdirectory. Open without creation/truncation, with no-follow and nonblocking flags. Validate current-user ownership, regular-file type, link count of one, and path/descriptor device and inode identity before and after probing. Do not require mode 0600 or reject group-write permission alone; do not repair ownership or permissions.flock. Retry contention outside the critical section, using a monotonic deadline and a total acquisition budget of approximately 100 ms, capped by any remaining caller deadline. Exhaustion, unsafe paths, permission errors, or identity changes returnunknown.await, external command, transcript scan, stability delay, signal, or exit wait occurs while it is held. Release the thread descriptor and native guard throughfinally; release/close failures must not produce a successful observation.unknownpolicy concerns an existing thread lock without a usable coordinator.method: "flock_exclusive_nonblocking"and JSON Schema v1. Any additional guard evidence must be optional and backward compatible. Native lock and coordination files must not be created, deleted, truncated, or rewritten by the probe.Guarantees and limitations
For writers that follow the verified Codex coordination protocol, the probe must not cause a thread
try_lockto returnWouldBlock. The native guard can briefly delay acquisition/publication/cleanup. If the diagnostic process is stopped or paused while holding it, that delay can extend until execution resumes or the process exits; the acquisition retry budget is not a guarantee about time spent paused while holding a lock.Document diagnostics as non-mutating to file contents, ownership, permissions, and modification times, while acknowledging temporary OS locks. Do not promise access-time invariance. Uncoordinated/custom writers are outside the zero-interference guarantee. Update CLI help and applicable README, security, CLI-reference, and safety-contract text consistently.
Passive OS queries such as Linux
/proc/locksor a verified Darwin query remain follow-up work. Missing or incomplete query evidence must not be interpreted as a free lock.Implementation and acceptance gates
native-coordination.tsmodule.WouldBlockfailures.Pinned protocol evidence
File::lockusesflock(LOCK_EX)andtry_lockusesflock(LOCK_EX | LOCK_NB).