Skip to content

fix: harden lock contention and permission verification - #101

Merged
steipete merged 1 commit into
mainfrom
stress/concurrency
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
stress/concurrency

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • read contended sidecars through bounded, no-follow, identity-checked descriptors and reject non-file sidecars without spinning
  • make valid payload timestamps authoritative under filesystem clock skew and preserve reclaim guards owned by other synchronous acquirers
  • fail closed on empty/unverifiable fallback Windows ACL output and keep the eight-retry pathed-EPERM budget covered
  • consolidate process-exit cleanup to one listener and add real in-process and cross-process mutual-exclusion stress coverage

Findings fixed

  • synchronous stale recovery removed a foreign .reclaim directory after mkdir returned EEXIST
  • empty icacls output was classified as verified windows-acl with permissive facts
  • async sidecar inspection could follow a swapped symlink, and async/sync snapshot reads were unbounded
  • an old mtime overrode a valid future createdAt, falsely marking a lock stale
  • synchronous acquisition spun forever on a dangling-symlink sidecar, ignoring a zero deadline
  • every distinct lock-manager domain registered another permanent process exit listener

Verification

  • pnpm check (699 passed, 34 skipped)
  • pnpm test:security (64 passed)
  • git diff --check
  • autoreview Codex (--mode local): clean, no accepted/actionable findings
  • real stress: 40 concurrent in-process holders with throwing callbacks and eight independent child processes; peak critical-section occupancy remained one

Host verification ran on macOS/APFS. Windows-only denial cases remain explicitly gated and now cover the exact eight-retry budget and descriptor-based snapshot read.

@steipete
steipete requested a review from a team as a code owner August 2, 2026 22:57
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 7:01 PM ET / 23:01 UTC.

ClawSweeper review

What this changes

The PR hardens sidecar-lock contention handling and Windows permission verification, adding bounded identity-checked reads, stale-reclaim fixes, and regression/stress coverage.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 4 items remain

Keep this PR open for a focused repair: the synchronous sidecar snapshot path can still block indefinitely if an attacker swaps a checked regular sidecar for a FIFO before openSync(). That contradicts the PR’s bounded, fail-closed contention goal and the repository’s filesystem-safety policy.

Priority: P1
Reviewed head: 194be00cb29990eeacdc44393a75a02e8be5e690

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The branch has targeted tests and stated stress validation, but a high-confidence synchronous race blocks merge and the reported real-run evidence is not inspectable.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR body reports macOS stress results, but it provides no inspectable after-fix transcript or artifact and does not show the missing synchronous sidecar-swap case. After the repair, add redacted terminal output or a linked runtime artifact; redact private paths and other sensitive details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body reports macOS stress results, but it provides no inspectable after-fix transcript or artifact and does not show the missing synchronous sidecar-swap case. After the repair, add redacted terminal output or a linked runtime artifact; redact private paths and other sensitive details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Repository security contract: Repository policy treats pathnames as attacker-controlled, requires bounded fail-closed behavior for ambiguous filesystem identity, and specifically calls for swap-race regression coverage.
Synchronous FIFO swap remains blocking: The branch performs lstatSync() and then opens the pathname with O_RDONLY | O_NOFOLLOW, but omits O_NONBLOCK; a regular file swapped for a FIFO between these calls can block openSync() before the subsequent descriptor type check.
Async path already handles this race class: The async snapshot reader uses O_NONBLOCK when opening the sidecar before checking descriptor type and identity, so the synchronous implementation is inconsistent with the patch’s own bounded-open design.
Findings 1 actionable finding [P1] Make synchronous sidecar opening nonblocking
Security Needs attention Synchronous FIFO swap can block indefinitely: The synchronous lock snapshot opens a pathname after a separate lstatSync() check without O_NONBLOCK; replacing that pathname with a FIFO can block the process before descriptor type validation.

How this fits together

File-lock APIs protect filesystem-backed state with a sidecar lock file. A contending caller inspects that attacker-controlled sidecar, validates its type and identity, applies stale-lock policy, then either acquires the lock or reports a bounded failure.

flowchart LR
  A[Caller requests file lock] --> B[Sidecar lock manager]
  B --> C[Inspect lock pathname]
  C --> D[Open sidecar descriptor]
  D --> E{Regular file and same identity?}
  E -->|yes| F[Parse bounded payload]
  E -->|no| G[Fail or retry safely]
  F --> H[Stale and reclaim decision]
  H --> I[Acquire or report lock result]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body reports macOS stress results, but it provides no inspectable after-fix transcript or artifact and does not show the missing synchronous sidecar-swap case. After the repair, add redacted terminal output or a linked runtime artifact; redact private paths and other sensitive details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Make synchronous sidecar opening nonblocking (P1) - A sidecar can change from the regular file observed by lstatSync() to a FIFO before this call. Because the descriptor opens without O_NONBLOCK, openSync() can wait forever and bypass timeoutMs; mirror the async bounded-open guard and add a synchronous FIFO-swap regression.
  • Resolve security concern: Synchronous FIFO swap can block indefinitely - The synchronous lock snapshot opens a pathname after a separate lstatSync() check without O_NONBLOCK; replacing that pathname with a FIFO can block the process before descriptor type validation.
  • Resolve merge risk (P1) - Merging as written leaves a denial-of-service path: a FIFO swapped into the sidecar pathname after lstatSync() can block the calling thread indefinitely and bypass timeoutMs, including a zero deadline.

Findings

  • [P1] Make synchronous sidecar opening nonblocking — src/sidecar-lock-reclaim.ts:183
  • [high] Synchronous FIFO swap can block indefinitely — src/sidecar-lock-reclaim.ts:183
Agent review details

Security

Needs attention: The branch improves several identity fences but leaves a synchronous attacker-controlled FIFO race that can deny service.

Review metrics

Metric Value Why it matters
Patch scope 15 files affected; 572 additions; 81 deletions The PR spans lock arbitration, permission verification, public docs, and several regression suites.
Claimed stress coverage 40 in-process holders and 8 child processes The reported mutual-exclusion exercise is useful, but it does not cover the synchronous FIFO-swap race.

Merge-risk options

Maintainer options:

  1. Bound the synchronous descriptor open (recommended)
    Add platform-safe nonblocking opening to the synchronous sidecar reader and prove a FIFO swap cannot bypass the configured timeout before merge.
  2. Pause until the synchronous race is fixed
    Do not merge this hardening branch while the synchronous path can still hang on an attacker-controlled sidecar swap.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Add a bounded nonblocking synchronous sidecar-descriptor open, preserve no-follow and identity checks, and add a regression test for a FIFO swapped in after the pre-open identity check.

Technical review

Best possible solution:

Mirror the async reader’s nonblocking descriptor-open protection in the synchronous sidecar reader, retain no-follow and identity checks, and add a deterministic regular-file-to-FIFO swap regression that proves synchronous acquisition returns within its retry/timeout boundary.

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

Yes, from source: replace a regular contended lock sidecar with a FIFO after lstatSync() but before openSync(). The proposed synchronous reader opens without O_NONBLOCK, so it can hang before retry or timeout logic executes.

Is this the best way to solve the issue?

No: the branch correctly applies a nonblocking open in the asynchronous snapshot reader but omits it from synchronous inspection, leaving the claimed bounded sidecar handling incomplete.

Full review comments:

  • [P1] Make synchronous sidecar opening nonblocking — src/sidecar-lock-reclaim.ts:183
    A sidecar can change from the regular file observed by lstatSync() to a FIFO before this call. Because the descriptor opens without O_NONBLOCK, openSync() can wait forever and bypass timeoutMs; mirror the async bounded-open guard and add a synchronous FIFO-swap regression.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 209fbd1cfb9e.

Labels

Label changes:

  • add P1: A user-visible synchronous locking workflow can hang indefinitely when a hostile sidecar swap occurs.
  • add merge-risk: 🚨 security-boundary: The changed code reads attacker-controlled sidecar paths and must preserve no-follow, type, and identity safety guarantees.
  • add merge-risk: 🚨 availability: The synchronous open race can indefinitely stall a process before normal timeout handling runs.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body reports macOS stress results, but it provides no inspectable after-fix transcript or artifact and does not show the missing synchronous sidecar-swap case. After the repair, add redacted terminal output or a linked runtime artifact; redact private paths and other sensitive details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: A user-visible synchronous locking workflow can hang indefinitely when a hostile sidecar swap occurs.
  • merge-risk: 🚨 security-boundary: The changed code reads attacker-controlled sidecar paths and must preserve no-follow, type, and identity safety guarantees.
  • merge-risk: 🚨 availability: The synchronous open race can indefinitely stall a process before normal timeout handling runs.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body reports macOS stress results, but it provides no inspectable after-fix transcript or artifact and does not show the missing synchronous sidecar-swap case. After the repair, add redacted terminal output or a linked runtime artifact; redact private paths and other sensitive details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Synchronous FIFO swap can block indefinitely — src/sidecar-lock-reclaim.ts:183
    The synchronous lock snapshot opens a pathname after a separate lstatSync() check without O_NONBLOCK; replacing that pathname with a FIFO can block the process before descriptor type validation.
    Confidence: 0.98

Acceptance criteria:

  • [P1] pnpm test -- test/sidecar-lock-regression.test.ts test/file-lock-concurrency-stress.test.ts.
  • [P1] pnpm test:security.
  • [P1] pnpm check.
  • [P1] git diff --check.

What I checked:

  • Repository security contract: Repository policy treats pathnames as attacker-controlled, requires bounded fail-closed behavior for ambiguous filesystem identity, and specifically calls for swap-race regression coverage. (AGENTS.md:25, 209fbd1cfb9e)
  • Synchronous FIFO swap remains blocking: The branch performs lstatSync() and then opens the pathname with O_RDONLY | O_NOFOLLOW, but omits O_NONBLOCK; a regular file swapped for a FIFO between these calls can block openSync() before the subsequent descriptor type check. (src/sidecar-lock-reclaim.ts:183, 194be00cb299)
  • Async path already handles this race class: The async snapshot reader uses O_NONBLOCK when opening the sidecar before checking descriptor type and identity, so the synchronous implementation is inconsistent with the patch’s own bounded-open design. (src/sidecar-lock-reclaim.ts:126, 194be00cb299)
  • Test coverage gap: The added deterministic swap test covers asynchronous symlink replacement via the new pre-open hook; it does not cover synchronous regular-file-to-FIFO replacement, and the hook is not invoked by the synchronous reader. (test/sidecar-lock-regression.test.ts:427, 194be00cb299)
  • Relevant ownership history: The available current-main history attributes the lock implementation and recent permission work to Peter Steinberger; the proposed branch is also authored by that contributor. (src/file-lock-sync.ts:160, 194be00cb299)

Likely related people:

  • steipete: Current-main lock and permissions history, plus this focused branch, are authored by Peter Steinberger (@steipete). (role: recent area contributor; confidence: high; commits: 16e1bd489ae8, 64f77429ede1, 209fbd1cfb9e; files: src/file-lock-sync.ts, src/sidecar-lock-reclaim.ts, src/permissions.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make the synchronous sidecar descriptor open nonblocking and add the FIFO-swap regression.
  • Add redacted terminal output or a linked artifact for the focused regression and stress run after the fix.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Empty icacls output was accepted as verified ACL data. Sidecar inspection could follow a pathname swapped to a symlink, and both async and sync sidecar reads were unbounded. Foreign synchronous .reclaim guards could be deleted after mkdir reported EEXIST. An old mtime overrode a valid future createdAt, falsely marking live locks stale. Sync acquisition spun forever on dangling-symlink sidecars, ignoring timeoutMs: 0. Every lock-manager domain permanently added another exit listener.
@steipete
steipete force-pushed the stress/concurrency branch from 194be00 to 67297bd Compare August 2, 2026 23:24
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix: harden lock contention and permission verification This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete
steipete merged commit 396504b into main Aug 2, 2026
22 checks passed
@steipete
steipete deleted the stress/concurrency branch August 2, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant