Skip to content

fix(lock): age the admitted sidecar snapshot during contention - #1045

Merged
steipete merged 2 commits into
mainfrom
fix/root-sidecar-contention
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/root-sidecar-contention

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Async Root-backed lock acquisition can reject with path-mismatch during an ordinary owner handoff when the payload omits createdAt. After reading an admitted snapshot, the async default stale policy stats its pathname again. A release in that gap produces ENOENT, incorrectly classifies the fresh record as stale, and enters a strict confirmation read that can race another release/re-create.

Use the admitted snapshot's timestamp, sharing the existing synchronous policy: valid createdAt takes precedence, otherwise use the captured modification time. The normal retry budget still governs contention. Exact identity checks, symlink/hardlink rejection, Root/ancestor validation, strict confirmation reads, and owner/reclamation authorization remain unchanged.

The deterministic regression uses real lock handles to release the sampled owner, return the real missing-path result from the historical timestamp lookup, and release/recreate a successor at the strict read's final fence. It fails on unchanged main with path-mismatch and passes with this fix. The test is also included in native-required Root admission CI. Changelog and lock documentation are updated.

Validation:

  • Regression fails on unchanged main with the expected strict-read path-mismatch; 46 focused tests pass after the fix.
  • Native-required focused boundary suite: 100/100 tests across seven files, including genuine replacement, ancestry, unknown-identity, resolver, unlink, and retry-budget controls.
  • Native ARM64 built-API contention: 10 × 100 acquisitions for each of all four cases before and after, 4,000/4,000 per revision. All 20 combined EACCES release-retry cases pass; counters, markers, and sidecars are checked.
  • Independent Codex review: scoped-clean at P0–P2.
  • pnpm check: lint, build, allocator artifact, and documentation examples pass. Local broad tests encounter temp-workspace refusals because the external scratch volume has a group-writable ancestor without sticky protection, plus watcher event/timing failures. A narrow unchanged-main control reproduces the temp/corpus and watcher failures; the volume permissions are unchanged. Local packaging also lacks the .NET-built Windows helper. Clean-runner exact-head CI supplies the broad/package gates.

Initial head e99c4b3b passed all CI, including Intel native-required proof. Main then advanced with #1044, so the branch now includes that change at fa4ed81223f2d93df651e5ec3cd69395f51f6f23. The integrated head passes 106 native-required focused tests and another 4,000/4,000 contention acquisitions; the regression also fails on the updated main base and passes on the integrated head. Final exact-head CI is green: 49 successful checks and 8 intentional skips. The final Intel native-required job confirms darwin/x64, Node 24.22.1, native require, all four cases at 100/100 and the new regression passing. Two successful Intel runs across the two heads; zero manual reruns. SHA-pinned squash merge: dc034469e1114aa784e74e71b3e9892a37f58bdb.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 27, 2026 20:07
@steipete
steipete requested a review from a team as a code owner October 27, 2026 20:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T20:25:15.308820Z fa4ed81 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes async lock stale detection use the admitted record’s timestamp instead of looking up its pathname again.

Example: A Root-backed lock contains {"owner":"original"}, omits createdAt, and has staleMs set to 60000; its owner releases after the waiter reads it.

  • Before: The missing pathname can classify the fresh record as stale and send the waiter into a strict confirmation read that fails with path-mismatch during another handoff.
  • After: The waiter ages the captured record and uses the existing contention retry path.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with a meaningful handoff regression, preserved safety boundaries, and no identified defect; independent runtime verification is limited to inspected source and hosted check metadata.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the ordinary contributor-proof gate; its real-filesystem regression was inspected, and the body reports native ARM64 built-public-API contention success, while hosted log contents remained inaccessible.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A caller waiting for an ordinarily released Root-backed lock can receive path-mismatch instead of acquiring the next available lock.
Reason: The maintainer-authored direction restores ordinary contention behavior using an existing policy owner, with no new public API or configuration.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a source-confirmed contention race still present on main and in v0.26.13; no actionable patch defect was found.

Priority: P2
Reviewed head: fa4ed81223f2d93df651e5ec3cd69395f51f6f23

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The built-public-API contention results are reported in the PR body, but their hosted log output could not be inspected because the storage redirect was blocked.
Agent review details

How this fits together

The sidecar lock layer accepts target paths, optional Root capabilities, and lock policies, then reads ownership records and either retries exclusive creation or performs separately authorized stale recovery.

flowchart TD
  A[Lock acquisition] --> B[Exclusive sidecar creation]
  B --> C[Read admitted snapshot on contention]
  C --> D[Age captured timestamp]
  D --> E[Retry exclusive creation]
  D --> F[Confirm identity and authorize stale recovery]
Loading

Technical review

Best possible solution:

Use the existing snapshot-age algorithm for both lock routes while retaining strict confirmation and separately authorized removal.

Do we have a high-confidence way to reproduce the issue?

The released source shows the extra pathname stat and catch-to-stale path, and the deterministic regression supplies the two-handoff schedule; the author reports failure on base and success on head, but no target code was executed during this review.

Is this the best way to solve the issue?

This is a focused root-cause repair: age the record already admitted rather than consult a pathname that may identify another owner, reusing the synchronous implementation without relaxing Root errors.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4362e5695886.

Provenance checked

  • Default stale-age policy keeps the original intent (396504b: The earlier hardening made valid createdAt authoritative under filesystem clock skew.)
  • Pathname metadata observation changes intended behavior with a stated reason (686c193: Metadata observations were made synchronous to avoid libuv scheduling while preserving safety fences; this PR explains why the later pathname lookup is unnecessary and races owner turnover.)
  • Synchronous policy ownership keeps the original intent (46efdfd: The existing synchronous policy ages captured metadata while Root acquisition retains its filesystem authority and strict checks.)
  • Strict Root handoff and reclaim boundaries keeps the original intent (46efdfd: Acquisition and recovery retain original authority, identity checks, guard ownership, and cleanup precedence.)
  • Native-required lock coverage keeps the original intent (59b9cc4: Real-process contention and focused boundary coverage guard Root handoffs and synchronous lock behavior.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned patch and policy: Read the complete root AGENTS.md and all introduced hunks; no nested AGENTS.md, maintainer-notes directory, or pr-simplify skill was present. The patch follows the filesystem-boundary and Unreleased changelog rules. Review remained read-only, and diff whitespace checks passed. (AGENTS.md:1, fa4ed81223f2)
  • Affected released implementation: Both fetched main and v0.26.13 perform a pathname stat after snapshot parsing and return stale on any stat failure when createdAt is absent or malformed. (src/sidecar-lock-policy.ts:125, 6c8627eb55a0)
  • Existing policy reused: The new shared helper preserves the previous synchronous algorithm exactly: valid createdAt first, otherwise captured mtime with bigint-stat support. (src/sidecar-lock-policy.ts:125, 4362e5695886)
  • Safety checks retained: Async classification remains inside admission assertions; stale results still require a strict current-snapshot comparison, and removal retains its guard, caller approval, repeated identity comparison, and final authorization checks. (src/sidecar-lock-stale-admission.ts:149, fa4ed81223f2)
  • Focused regression: The added regression uses real Root-backed lock handles and filesystem operations, releases the sampled owner during parsing, and checks successful waiter acquisition and ownership; spies and hooks arrange the historical failure schedule. (test/sidecar-lock-mtime-handoff.test.ts:13, fa4ed81223f2)
  • Discussion and exact-head validation: Read the complete PR body and all comments. The author reports base-failing/head-passing regressions and built-public-API contention runs. Exact-head native musl CI passed; two other checks remained in progress. Hosted log retrieval was blocked at the storage redirect, so those log contents were not independently inspected. (.github/workflows/ci.yml:1674, fa4ed81223f2)

Review metrics

Metric Value Why it matters
Patch scope Production +22/-33; tests +67/-2 The production reduction consolidates an existing algorithm, and the added regression covers a distinct real-filesystem handoff failure.

Labels

Label changes:

  • add P2: An ordinary Root-backed lock handoff can fail acquisition when payloads lack createdAt, but the evidence does not establish data loss or a widespread outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: An ordinary Root-backed lock handoff can fail acquisition when payloads lack createdAt, but the evidence does not establish data loss or a widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 27, 2026, 4:41 PM ET / 20:41 UTC.

@steipete
steipete merged commit dc03446 into main Oct 27, 2026
57 checks passed
@steipete
steipete deleted the fix/root-sidecar-contention branch October 27, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant