Skip to content

fix: coordinate native thread lock probes - #79

Merged
abruption merged 4 commits into
mainfrom
fix/55-native-coordination
Sep 29, 2026
Merged

abruption merged 4 commits into
mainfrom
fix/55-native-coordination

Conversation

@abruption

@abruption abruption commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Problem and behavior

Closes #55.

A free-lock probe briefly holds the thread lock exclusively. Without native coordination, a concurrent Codex writer can receive WouldBlock and report an active writer. Each probe now takes Codex's existing .coordination.lock first, so coordinated writers wait for the probe to finish.

Implementation

  • A synchronous, nonblocking critical section validates coordinator UID, regular/non-symlink/single-link type, path/descriptor identity, and parent identity around each thread probe. Cleanup failures become unknown.
  • Inspection retries only coordinator contention, outside the guard, for up to 100 ms per probe on a monotonic clock. Every attempt refreshes the thread-file observation to account for coordinated removal or replacement. Post-signal polling also respects its remaining termination budget.
  • The final pre-signal probe tries once and releases/closes the guard before SIGTERM, with no intervening await or microtask boundary. Contention refuses with native_coordination_busy_before_signal; lock_changed_before_signal is retained when the snapshot actually differs.
  • Lock order remains operation lease → native guard → thread probe. Process correlation stays independent of the lock probe, and process exit, actual release, and transcript invariance remain required.
  • JSON v1 gains optional lock.probe.guard evidence, with matching schema and type-only declarations. The packaged artifact includes the internal runtime module.

Compatibility and limits

An existing thread lock with a missing, unsafe, changed, or unavailable coordinator is unknown, and unlock refuses. Verified thread-lock absence retains its existing meaning. Native files are never created, deleted, rewritten, chmodded, or repaired; there is no unguarded fallback.

Normal readable coordinator modes, including 0644/0664, are accepted. Contents, inode identity, ownership, permissions, and mtime remain unchanged; access times may change. Diagnostics can briefly delay coordinated writers. SIGSTOP or a debugger pause while holding the coordinator can extend that delay until the process resumes or exits. Writers bypassing Codex's coordination protocol are outside this interference guarantee.

Validation

  • Required local install/type/lint/test/packed-install checks and platform smoke pass on macOS arm64 / Node 22.14.0. Full suite: 164 tests, 163 pass, 0 fail, 1 case-sensitive-filesystem skip.
  • Real-flock regression demonstrates the baseline WOULD_BLOCK and the guarded writer's GUARDED result without a thread attempt. Bounded coordinated acquire/drop stress observes zero probe-induced WouldBlock.
  • Tests cover busy/retry/deadline behavior, removal/replacement during retries, absent/unsafe coordinator evidence, alias paths, cleanup failures, file invariance, shutdown contention, and the final signal boundary.
  • Existing concurrent unlock, zombie/reacquisition, post-signal fault, JSON Schema, offline package installation, and type-only consumer regressions pass. The successor regression also passes 20 consecutive runs with an explicit acquisition barrier.
  • HEAD df95d30496917dd3e7658a7d1006cba18d91b647 passes all 23 hosted checks, including all 12 macOS/Linux x64/arm64 Node 22.13/current-22/current-24 combinations, packaging, security audit, and CodeQL. CI run.

Validation uses scratch homes and synthetic owners only. This PR does not publish a release.

@abruption
abruption merged commit 1d529c3 into main Sep 29, 2026
23 checks passed
@abruption
abruption deleted the fix/55-native-coordination branch September 29, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: read-only lock probe can make a concurrent Codex writer acquisition fail

1 participant