Skip to content

fix(lib): read the clock under the lock in cli-version-check claimDaily - #18075

Open
kyle-sexton wants to merge 2 commits into
mainfrom
fix/18063-cli-version-claim-race
Open

kyle-sexton wants to merge 2 commits into
mainfrom
fix/18063-cli-version-claim-race

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Closes #18063

Summary

lib/cli-version-check.test.sh failed on main in run 44950479481, attempt 1, job "Test Bash (6)". The suite did not stop after test 2. The FAIL: line printed after test 2 is the runner's summary line, interleaved with the streamed output. The job's failure block names the test: ✖ only one of many processes claiming the same name at once wins, AssertionError: 2 !== 1 at lib/cli-version-check.test.mjs:134. Two of 24 concurrent claim processes won.

Cause: claimDaily read the clock in a default parameter (now = Date.now()), before it took the lock. The race goes like this:

  1. A claimant reads the clock.
  2. Another claimant takes the lock and stamps a later time.
  3. The first claimant takes the lock and finds a stamp later than its own now.
  4. The future-stamp rule (last <= now fails) makes the job due, so the first claimant wins as well.

checkVersion had the same early read, with a wider window.

Fix

  • claimDaily reads the clock inside the lock when no now is passed. Claims are stamped in lock order, so a later lock holder can no longer see an earlier holder's stamp as a future one.
  • checkVersion no longer defaults now itself; it passes it through.
  • A regression test lands a claim between the late claimant's entry and its lock (it hooks mkdirSync, which runs between the two) and expects the late claimant to lose.
  • The three generated copies (context7, firecrawl, playwright) are regenerated, each with a patch fragment.

Verification

  • Before the fix, the new test fails every time: actual: { inner: true, outer: true }, expected outer: false. This is the same two-winner result CI saw.
  • After the fix, the suite passes 18 of 18, and 20 of 20 repeated whole-suite runs pass.
  • Timing reproduction of the CI test (only one of many processes claiming…), pinned to 2 CPUs with 4 busy loops at default priority and the test at nice 19:
    • before: 3 of 60 runs fail;
    • after: 0 of 60 runs fail.
    • The harness kept no failure output, so the three failures before the fix are not confirmed to be 2 !== 1. These counts match the fix but are small. The deterministic test above is the evidence that settles the cause.
    • With the test at normal priority, 60 runs on the old code showed no failure (24 cores, 2 CPUs, 1 CPU).
  • scripts/sync-shared-copies.sh --check-bump origin/main passes. scripts/check-affected.sh reports 17 passed and 3 skipped.
  • lib/prerequisites.test.mjs, which calls checkVersion, has the same 10 local failures (of 370) on this branch and on main. They come from the tools installed on this machine.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 21, 2026 18:15
claimDaily took `now` from a default parameter, before the lock. A
claimant that read the clock, then took the lock only after another
claimant had stamped a later time, saw that stamp as a future one and
claimed again, so two of 24 concurrent claims won on CI (main run
44950479481, attempt 1). The clock is now read inside the lock, and
checkVersion no longer captures it early either. A regression test
lands a claim between the clock read and the lock and expects the late
claimant to lose.

Closes #18063

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 22, 2026 00:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T00:02:37.514215Z a0a1c27 Draft marked ready
ℹ️ 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.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed a0a1c2793aab4cdb2953db30c30f6b7d746cfbba: read 8 of 8 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #18075, claimDaily clock read moved under the lock

No findings.

The fix fits the race described in the closing issue (#18063). claimDaily used to read Date.now() in a default parameter, before exclusively took the lock. Now it reads the clock inside the claim callback (now ??= Date.now(), lib/cli-version-check.mjs#L58). Claims are therefore stamped in lock order, and a later lock holder can no longer see an earlier holder's stamp as a future stamp.

  • checkVersion: it passes now straight through (L90-L93). It reads now nowhere else, so an undefined value is safe.
  • CLI paths: main calls claimDaily and checkVersion without now, so both CLI commands get the fix.
  • New regression test: it hooks fs.mkdirSync, which exclusively calls before it opens the lock. The hook runs syncBuiltinESMExports() so the lib's named import sees the change. Inside the hook, a second claim lands after a 2 ms busy wait. Before the fix, the outer claimant's now came before the inner stamp, so it also won. After the fix, it reads a later time under the lock and loses.
  • The test can't pass vacuously: if the hook never fired, inner would stay undefined and deepEqual would fail. restore() runs both inside the hook and in finally, so the stub can't leak into later tests.
  • Copies: the three plugin copies (context7, firecrawl, playwright) are byte-identical to the shared lib change. Each gets an identical bump: patch fragment, which is the right level for a bug fix.

Closing issue #18063: its only criterion is to fix the quarantined suite lib/cli-version-check.test.sh. The change meets it, and the new deterministic test would fail if the race came back. I did not run the suite: the pass counts in the PR are the author's claim and unverified here.

Loosened checks: none. The diff adds a test and changes no assertion, threshold, skip or runner. The prompt has no loosened_check_verdict: or loosened_check_patterns: line, so the default fail with no consumer entries applies. It also has no loosened_check_decision_record: line, so the citation requirement was not checked. Loosened checks would be marked: fail (bundled default); patterns: 0.

Manifests: no plugin.json or marketplace.json changed.

Prior findings: none (first review of this PR).

Verifier dropped 0 of 0 candidates.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed a0a1c2793aab4cdb2953db30c30f6b7d746cfbba: read 8 of 8 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security issues found

This change fixes a race in claimDaily in the shared lib/cli-version-check.mjs. It now reads the clock inside the lock (now ??= Date.now()) instead of in a default parameter, and checkVersion passes now through without setting a default. The PR also adds a deterministic regression test and copies the fix into the three plugins (context7, firecrawl, playwright), with a patch changelog fragment for each.

What I checked:

  • Uses of now: in checkVersion, now is used only as the argument to claimDaily (lib/cli-version-check.mjs#L93). An undefined value therefore never reaches later code, so the date stamp and the stale-lock math are unchanged.
  • Locking and rate limiting: the lock, the stale-lock break and the atomic temp-file write are unchanged. The fix makes the once-a-day claim stricter, which helps keep within the unauthenticated GitHub API rate limit.
  • Test code: the new test temporarily replaces fs.mkdirSync (via syncBuiltinESMExports) and puts the original back in a finally block. It runs only inside the test process.
  • Plugin manifests and trust controls: no plugin.json or marketplace.json changes. No trust control, merge hold, workflow, token or kill-switch path is touched, and no changed file matches a trusted-path glob.
  • PR context: the description matches the diff and contains no embedded instructions.

The three plugin copies have the same change as plugins/context7/lib/cli-version-check.mjs, and the three changelog fragments are identical. Each copy sits at an ordinary lib/ or .changes/ path, so the content does the same thing at every path.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

The pr-verify verifier failed head a0a1c2793aab4cdb2953db30c30f6b7d746cfbba. What it wrote, as data:

Summary: The PR closes issue #18063, but the issue has no trusted spec text, so there is nothing to
  judge the diff against. The issue's `body` is null in spec-text.json, it has no spec comments, and
  the automation lanes bot filed it. Intake triage held it in needs-owner-decision because no
  trusted human posted acceptance criteria. The rules require `fail` when no linked issue has
  trusted spec text. On its merits, the code change looks correct. `claimDaily` now reads
  `Date.now()` inside the lock when no `now` is passed, and `checkVersion` passes `now` through.
  That stops a late claimant from treating an earlier holder's stamp as a future stamp and also
  winning. The three generated copies (context7, firecrawl and playwright) are changed the same way,
  and each has a patch changelog fragment. The new regression test hooks `fs.mkdirSync` with
  `syncBuiltinESMExports` to slip a claim in between the late claimant's entry and its lock. It
  would fail on the old code. CI is no evidence either way: Select Tests was `skipped`
  (https://github.com/melodic-software/claude-code-plugins/actions/runs/44965387262/job/137033152728),
  so the run was a re-run that ran no suite, and `lib/cli-version-check.test.sh` did not run on the
  judged head. No binary files, no changes to the takeover set (trusted actors, guard actions,
  CODEOWNERS, submodules) and no credentials appear in the diff.
- Issue #18063 has no trusted spec text: its body is null in spec-text.json and it has no spec
  comments, because the automation bot filed it and no trusted human has posted acceptance criteria.
  A listed human must add the confirmed `- [ ]` criteria to the issue, or post them as their own
  comment, before this PR can be verified. The diff needs no change for this.

This pull request leaves the merge queue, and ci-status holds it out while it carries pr-verify-failed. A pr-verify pass removes the label, at a new commit or at this same head: once a trusted person edits the body, and only trusted people have edited it since the fail, this head is judged again, so a fail on the body or the issues it links needs only the body fixed, no new commit.

@github-actions github-actions Bot added the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 22, 2026
@github-actions github-actions Bot removed the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Nov 22, 2026
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.

Quarantined suite fails on main: lib/cli-version-check.test.sh

1 participant