Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Fixed

- The once-a-day CLI version check no longer runs twice when two sessions start at the same moment: the shared `cli-version-check.mjs` now reads the clock after it takes its lock ([#18063](https://github.com/melodic-software/claude-code-plugins/issues/18063)).
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Fixed

- The once-a-day CLI version check no longer runs twice when two sessions start at the same moment: the shared `cli-version-check.mjs` now reads the clock after it takes its lock ([#18063](https://github.com/melodic-software/claude-code-plugins/issues/18063)).
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Fixed

- The once-a-day CLI version check no longer runs twice when two sessions start at the same moment: the shared `cli-version-check.mjs` now reads the clock after it takes its lock ([#18063](https://github.com/melodic-software/claude-code-plugins/issues/18063)).
5 changes: 3 additions & 2 deletions lib/cli-version-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ function exclusively(file, claim) {
return false;
}

export function claimDaily({ stateDir, name, now = Date.now() }) {
export function claimDaily({ stateDir, name, now }) {
const file = machineStateFile(stateDir, name);
return exclusively(file, () => {
now ??= Date.now();
const last = lastClaim(file);
if (last <= now && now - last < DAY_MS) return false;
const tmp = `${file}.${process.pid}.tmp`;
Expand Down Expand Up @@ -86,7 +87,7 @@ function release(source) {
throw new Error(`invalid source: ${source} (expected npm:<package> or github:<owner>/<repo>)`);
}

export async function checkVersion({ stateDir, cli, installed, source, hint = "", now = Date.now(), fetch = globalThis.fetch, timeoutMs = 3000 }) {
export async function checkVersion({ stateDir, cli, installed, source, hint = "", now, fetch = globalThis.fetch, timeoutMs = 3000 }) {
const { url, field } = release(source);
// Claimed before the lookup so a failed one also waits a day: unauthenticated api.github.com allows 60 requests an hour per IP, https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
if (!claimDaily({ stateDir, name: cli, now })) return { status: "skipped" };
Expand Down
27 changes: 26 additions & 1 deletion lib/cli-version-check.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { strict as assert } from "node:assert";
import { spawn, spawnSync } from "node:child_process";
import { existsSync, mkdirSync, utimesSync, writeFileSync } from "node:fs";
import fs, { existsSync, mkdirSync, utimesSync, writeFileSync } from "node:fs";
import { syncBuiltinESMExports } from "node:module";
import { dirname, join } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -135,6 +136,30 @@ test("only one of many processes claiming the same name at once wins", async ()
assert.equal(codes.filter((code) => code === 1).length, 23);
});

test("a claim that lands while another claimant is on its way to the lock makes that claimant lose", () => {
const dir = tempDir("cvc-");
const original = fs.mkdirSync;
const restore = () => {
fs.mkdirSync = original;
syncBuiltinESMExports();
};
let inner;
fs.mkdirSync = (...args) => {
restore();
const until = Date.now() + 2;
while (Date.now() < until);
inner = claimDaily({ stateDir: dir, name: "race" });
return original(...args);
};
syncBuiltinESMExports();
try {
const outer = claimDaily({ stateDir: dir, name: "race" });
assert.deepEqual({ inner, outer }, { inner: true, outer: false });
} finally {
restore();
}
});

test("a fresh lock held by another claimant refuses; a stale one is broken", () => {
const dir = tempDir("cvc-");
const lock = join(dir, "cli-version-check", "agy.json.lock");
Expand Down
5 changes: 3 additions & 2 deletions plugins/context7/lib/cli-version-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ function exclusively(file, claim) {
return false;
}

export function claimDaily({ stateDir, name, now = Date.now() }) {
export function claimDaily({ stateDir, name, now }) {
const file = machineStateFile(stateDir, name);
return exclusively(file, () => {
now ??= Date.now();
const last = lastClaim(file);
if (last <= now && now - last < DAY_MS) return false;
const tmp = `${file}.${process.pid}.tmp`;
Expand Down Expand Up @@ -88,7 +89,7 @@ function release(source) {
throw new Error(`invalid source: ${source} (expected npm:<package> or github:<owner>/<repo>)`);
}

export async function checkVersion({ stateDir, cli, installed, source, hint = "", now = Date.now(), fetch = globalThis.fetch, timeoutMs = 3000 }) {
export async function checkVersion({ stateDir, cli, installed, source, hint = "", now, fetch = globalThis.fetch, timeoutMs = 3000 }) {
const { url, field } = release(source);
// Claimed before the lookup so a failed one also waits a day: unauthenticated api.github.com allows 60 requests an hour per IP, https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
if (!claimDaily({ stateDir, name: cli, now })) return { status: "skipped" };
Expand Down
5 changes: 3 additions & 2 deletions plugins/firecrawl/lib/cli-version-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ function exclusively(file, claim) {
return false;
}

export function claimDaily({ stateDir, name, now = Date.now() }) {
export function claimDaily({ stateDir, name, now }) {
const file = machineStateFile(stateDir, name);
return exclusively(file, () => {
now ??= Date.now();
const last = lastClaim(file);
if (last <= now && now - last < DAY_MS) return false;
const tmp = `${file}.${process.pid}.tmp`;
Expand Down Expand Up @@ -88,7 +89,7 @@ function release(source) {
throw new Error(`invalid source: ${source} (expected npm:<package> or github:<owner>/<repo>)`);
}

export async function checkVersion({ stateDir, cli, installed, source, hint = "", now = Date.now(), fetch = globalThis.fetch, timeoutMs = 3000 }) {
export async function checkVersion({ stateDir, cli, installed, source, hint = "", now, fetch = globalThis.fetch, timeoutMs = 3000 }) {
const { url, field } = release(source);
// Claimed before the lookup so a failed one also waits a day: unauthenticated api.github.com allows 60 requests an hour per IP, https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
if (!claimDaily({ stateDir, name: cli, now })) return { status: "skipped" };
Expand Down
5 changes: 3 additions & 2 deletions plugins/playwright/lib/cli-version-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ function exclusively(file, claim) {
return false;
}

export function claimDaily({ stateDir, name, now = Date.now() }) {
export function claimDaily({ stateDir, name, now }) {
const file = machineStateFile(stateDir, name);
return exclusively(file, () => {
now ??= Date.now();
const last = lastClaim(file);
if (last <= now && now - last < DAY_MS) return false;
const tmp = `${file}.${process.pid}.tmp`;
Expand Down Expand Up @@ -88,7 +89,7 @@ function release(source) {
throw new Error(`invalid source: ${source} (expected npm:<package> or github:<owner>/<repo>)`);
}

export async function checkVersion({ stateDir, cli, installed, source, hint = "", now = Date.now(), fetch = globalThis.fetch, timeoutMs = 3000 }) {
export async function checkVersion({ stateDir, cli, installed, source, hint = "", now, fetch = globalThis.fetch, timeoutMs = 3000 }) {
const { url, field } = release(source);
// Claimed before the lookup so a failed one also waits a day: unauthenticated api.github.com allows 60 requests an hour per IP, https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
if (!claimDaily({ stateDir, name: cli, now })) return { status: "skipped" };
Expand Down
Loading