Skip to content

chore(critique,reconcile): share hardened validators and the manifest lock — sc-1414 clusters 3+5 - #314

Merged
norvalbv merged 2 commits into
mainfrom
chore/dedup-critique
Aug 3, 2026
Merged

chore(critique,reconcile): share hardened validators and the manifest lock — sc-1414 clusters 3+5#314
norvalbv merged 2 commits into
mainfrom
chore/dedup-critique

Conversation

@norvalbv

@norvalbv norvalbv commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Shortcut sc-1414 part 2, clusters 3+5 (epic 1399).

Cluster 3 — critique

validText (bounded, control-char-rejecting text guard; byte-identical ×2) and the hardened plain-record guard (proxy/array/prototype rejection, duplicated between work-quarantine's exactObject interior and claude-subagent-stop's plainRecord) now live in evidence-record.mts — the module all three files already import. work-quarantine's exactObject keeps its stricter exact-fields/descriptor checks layered on top. NOT touched: evidence-bindings' softer exactObject (different security posture, never clone-flagged).

Cluster 5 — reconcile

The atomic-mkdir withLock mutex (identical bodies AND constants) moves from reconcile.mts + ship/reconcile-manifest-write.mts into atomic-write.mts — whose docstring already names both callers. The writer's fuller rationale comment travels with it.

Cluster 4 — deferred with rationale

decisions/check-alignment ↔ detect share the standard run-as-main gate dispatch idiom, and both feed published decisions-suite hashes — same deferral class as the eval harness (dedupe when they next change substantively).

Scan 52 → 49. Targeted suites green (critique 235 tests; ship/release paths); full suite green at pre-push; tsc clean. Net −35 lines.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved file and manifest update reliability by coordinating concurrent operations and cleaning up stale locks.
    • Strengthened validation of evidence and critique data, including text length, blank content, control characters, unexpected object types, arrays, proxies, and invalid records.
    • Improved handling of malformed or untrusted data across lifecycle and provider integrations.
  • Refactor

    • Consolidated file-locking and input-validation behavior for more consistent results across the application.

… lock — sc-1414 clusters 3+5

Cluster 3 (critique): validText (bounded, non-blank, control-char-rejecting
text guard) was byte-identical in evidence-bindings and lifecycle/
work-quarantine; the hardened plain-record guard (proxy/array/prototype
rejection) was duplicated between work-quarantine's exactObject interior and
provider-adapters/claude-subagent-stop's plainRecord. Both now live in
evidence-record.mts — the one module all three files already import —
exported as validText (+ PLAN_CRITIQUE_MAX_TEXT_BYTES) and plainRecord;
work-quarantine's exactObject keeps its stricter exact-fields/descriptor
checks on top. NOT touched: evidence-bindings' softer exactObject (different
security posture by design, and never clone-flagged).

Cluster 5 (reconcile): the atomic-mkdir withLock mutex (identical bodies AND
constants) moves from reconcile.mts + ship/reconcile-manifest-write.mts into
atomic-write.mts — whose own docstring already names both callers as the
mutators it serves. The writer's fuller rationale comment travels with it.

Cluster 4 (decisions check-alignment <-> detect) is DEFERRED with the eval-
harness rationale: the shared fragment is the standard run-as-main gate
dispatch idiom, and both files feed published decisions-suite hashes.

Repo-wide clone scan 52 -> 49. Targeted suites green (critique 235; ship/
release 322 incl. reconcile paths); tsc clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@norvalbv, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d1a610f-ab83-4de4-994f-63d75f34c11f

📥 Commits

Reviewing files that changed from the base of the PR and between 91520c3 and 0f8af07.

📒 Files selected for processing (2)
  • cli/__tests__/atomic-write-lock.test.mts
  • cli/lib/atomic-write.mts
📝 Walkthrough

Walkthrough

The PR adds a shared CLI directory-lock helper and replaces duplicate lock implementations. It also centralizes bounded text and plain-record validation for critique evidence and updates consumers to use these helpers.

Changes

CLI locking

Layer / File(s) Summary
Shared atomic lock helper
cli/lib/atomic-write.mts
Adds withLock, with atomic acquisition, retry and stale-lock handling, timeout errors, callback execution, and guaranteed cleanup.
Reconciliation lock integration
cli/lib/reconcile.mts, cli/lib/ship/reconcile-manifest-write.mts
Replaces local lock implementations with the shared withLock helper.

Critique validation

Layer / File(s) Summary
Shared evidence validators
gate-engine/critique/evidence-record.mts
Adds bounded control-free text validation and hardened plain-record validation for untrusted values.
Validator adoption
gate-engine/critique/evidence-bindings.mts, gate-engine/critique/lifecycle/work-quarantine.mts, gate-engine/critique/provider-adapters/claude-subagent-stop.mts
Uses the shared validators and removes duplicate local implementations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • norvalbv/devkit#160: Refactors locking and validation helpers used by related review workflows.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the shared validator and manifest lock changes described in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/dedup-critique

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cli/lib/atomic-write.mts`:
- Around line 44-45: Replace the age-only cleanup in the atomic-write lock flow
with ownership-safe locking and stale-holder detection, or require explicit
cleanup; never remove lockDir solely because mtime exceeds LOCK_STALE_MS. Ensure
the mechanism prevents both paused live holders and release/reacquire races from
deleting another process’s lock, while preserving safe manifest updates in the
callers using atomic-write.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c367505-65ff-44c0-a57d-b55f4c573eb0

📥 Commits

Reviewing files that changed from the base of the PR and between b0b55f7 and 91520c3.

📒 Files selected for processing (7)
  • cli/lib/atomic-write.mts
  • cli/lib/reconcile.mts
  • cli/lib/ship/reconcile-manifest-write.mts
  • gate-engine/critique/evidence-bindings.mts
  • gate-engine/critique/evidence-record.mts
  • gate-engine/critique/lifecycle/work-quarantine.mts
  • gate-engine/critique/provider-adapters/claude-subagent-stop.mts

Comment thread cli/lib/atomic-write.mts Outdated
Review follow-up on the withLock this PR moved into atomic-write.mts. The
reaping rule travelled over verbatim from both former copies, and it treated
lock AGE as proof the holder had died. It is not: a live writer paused past
the window (SIGSTOP, a suspended laptop, a long GC) still owns its lock, so
the reap let a second read-modify-write run concurrently with the first --
exactly the lost update the mutex exists to prevent.

A reap now needs three agreeing facts instead of one: stale age, a pid that
no longer exists, and a holder stamp unchanged across the check. The holder
writes `<pid>:<uuid>` inside the lock dir on acquisition, so ownership is
read rather than inferred. The stamp re-read is what defeats the
release-and-reacquire race -- a holder that released while a second process
was mid-check no longer has its successor's fresh lock deleted by age. Every
ambiguous liveness answer (EPERM, an unreadable stamp) errs toward not
reaping, and refusing to reap is always safe: the caller just times out.

Release is now ownership-checked too. The old unconditional rmSync in the
finally would strip a live holder's lock had this caller itself been wrongly
reaped, admitting a third writer -- the same defect on the way out.

Also replaced the sleepless retry spin with a 25ms pause: burning a core for
5s while the holder tries to finish its sub-ms section was making the
contention it was waiting on worse.

Residual, documented at the call: a reacquire landing between the stamp
re-read and the rmSync still races, but it needs a third party to reap the
dead holder's lock inside that window. Every wider path is closed.

New suite atomic-write-lock.test.mts (7 cases) drives the real filesystem:
stale+dead reaps, stale+alive does NOT, fresh+dead does NOT, stale+unstamped
reaps, and release leaves a lock that is no longer ours alone.

Targeted suites green (reconcile, ship-manifest, detect-merged, the new lock
suite -- 61 tests); tsc clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@norvalbv
norvalbv merged commit 4789478 into main Aug 3, 2026
1 of 2 checks passed
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.

1 participant