Skip to content

Commit 635a01f

Browse files
cliffhallclaude
andcommitted
fix(sdk-watch): refresh an open issue once nothing is behind its target
Copilot on #5285: a group whose last outdated copy reached the target, or that no manifest declares any more, was dropped before the refresh ran, so its open issue kept stale **yes** rows and scope labels. Such a group is now kept as settled: it files nothing and queues no analysis, but an open issue for its target is rewritten to say nothing is behind, and the scope labels its rows had called for are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 3645d92 commit 635a01f

2 files changed

Lines changed: 192 additions & 15 deletions

File tree

‎scripts/sdk-watch.mjs‎

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
// ticked checklist box alone is not a difference. Its scope labels move by
5656
// the DELTA between what the old body's rows called for and what the new
5757
// rows do, so a label triage or a maintainer applied, or removed, stays as
58-
// they left it. A closed issue is left alone.
58+
// they left it. That holds when the last outdated copy catches up or
59+
// leaves the group too: the issue is rewritten to say nothing is behind,
60+
// though the sweep still closes nothing. A closed issue is left alone.
5961
//
6062
// "An issue exists" and "it was analyzed" are different claims. The workflow
6163
// stamps `ANALYSIS_MARKER` on its comment, and an OPEN issue for the current
@@ -249,16 +251,16 @@ export function assertEveryPackageWatched(declaredByManifest, ownPackages) {
249251
}
250252

251253
/**
252-
* Decide whether one group is behind.
254+
* One group's rows against its target, whether or not anything is behind.
253255
*
254256
* @param {(typeof SDK_GROUPS)[number]} group
255257
* @param {Array<{name: string, where: string, declared: string, installed: string | null}>} rows
256258
* one per package per manifest that declares it
257259
* @param {Record<string, string>} latest per package
258260
* @returns {{group: (typeof SDK_GROUPS)[number], rows: Array<object>, target: string} | null}
259-
* `null` when nothing is declared, a latest is unknown, or nothing is behind
261+
* `null` when nothing is declared or a latest is unknown
260262
*/
261-
export function groupState(group, rows, latest) {
263+
export function markRows(group, rows, latest) {
262264
const { compare } = versioning(group.ecosystem);
263265
const names = [...new Set(rows.map((r) => r.name))];
264266
if (names.length === 0) return null;
@@ -271,10 +273,23 @@ export function groupState(group, rows, latest) {
271273
latest: latest[r.name],
272274
behind: r.installed !== null && compare(target, r.installed) > 0,
273275
}));
274-
if (!marked.some((r) => r.behind)) return null;
275276
return { group, rows: marked, target };
276277
}
277278

279+
/**
280+
* Decide whether one group is behind.
281+
*
282+
* @param {(typeof SDK_GROUPS)[number]} group
283+
* @param {Parameters<typeof markRows>[1]} rows
284+
* @param {Record<string, string>} latest per package
285+
* @returns {ReturnType<typeof markRows>}
286+
* `null` when nothing is declared, a latest is unknown, or nothing is behind
287+
*/
288+
export function groupState(group, rows, latest) {
289+
const state = markRows(group, rows, latest);
290+
return state && state.rows.some((r) => r.behind) ? state : null;
291+
}
292+
278293
/** @param {NonNullable<ReturnType<typeof groupState>>} state */
279294
export function buildIssueTitle(state) {
280295
return `chore(deps): upgrade the ${state.group.label} to ${state.target}`;
@@ -406,12 +421,32 @@ export function buildIssueBody(state) {
406421
)
407422
.join("\n");
408423

424+
const header = [
425+
`| Package | Where | Declared | Installed on \`${TARGET_BRANCH}\` | Latest | Behind |`,
426+
"| --- | --- | --- | --- | --- | --- |",
427+
];
428+
429+
// Settled: the last copy that was behind has reached the target, or left
430+
// the group, since the issue was filed (#5067).
431+
if (!rows.some((r) => r.behind)) {
432+
return [
433+
buildMarker(group, target),
434+
rows.length > 0
435+
? `**Nothing here is behind ${target} any more.** Every copy of the **${group.label}** installed on \`${TARGET_BRANCH}\` has reached it, so the upgrade this issue tracked is done.`
436+
: `**Nothing here is behind ${target} any more.** No manifest on \`${TARGET_BRANCH}\` declares the **${group.label}** any longer, so the upgrade this issue tracked no longer applies.`,
437+
"",
438+
...(rows.length > 0 ? [...header, table, ""] : []),
439+
`Release notes: https://github.com/${group.repo}/releases`,
440+
"",
441+
"Rewritten by the nightly SDK watch (#4874) when the last outdated copy cleared. The sweep closes nothing: close this issue by hand once a maintainer has confirmed it.",
442+
].join("\n");
443+
}
444+
409445
return [
410446
buildMarker(group, target),
411447
`A new **${group.label}** release is out. What is installed on \`${TARGET_BRANCH}\` is behind what ${registry} publishes.`,
412448
"",
413-
`| Package | Where | Declared | Installed on \`${TARGET_BRANCH}\` | Latest | Behind |`,
414-
"| --- | --- | --- | --- | --- | --- |",
449+
...header,
415450
table,
416451
"",
417452
...(rows.some((r) => r.latest !== target)
@@ -618,18 +653,26 @@ export function main({
618653
assertEveryPackageWatched(installs.declaredByManifest, installs.ownPackages);
619654

620655
const states = [];
656+
// Groups with nothing behind. An open issue for one still gets its rows
657+
// refreshed, or it keeps naming copies that have caught up (#5067). A
658+
// group no manifest declares any more has no target of its own (null).
659+
const settled = [];
621660
for (const group of SDK_GROUPS) {
622661
const rows = installs.rowsFor(group);
623-
if (rows.length === 0) continue;
662+
if (rows.length === 0) {
663+
settled.push({ group, rows: [], target: null });
664+
continue;
665+
}
624666
const latest = {};
625667
for (const name of new Set(rows.map((r) => r.name))) {
626668
latest[name] =
627669
group.ecosystem === "pypi"
628670
? latestPypi(name, spawn)
629671
: latestNpm(name, spawn);
630672
}
631-
const state = groupState(group, rows, latest);
632-
if (state) states.push(state);
673+
const state = markRows(group, rows, latest);
674+
if (!state) continue;
675+
(state.rows.some((r) => r.behind) ? states : settled).push(state);
633676
}
634677

635678
const emit = (filed) => {
@@ -638,9 +681,7 @@ export function main({
638681
};
639682

640683
if (states.length === 0) {
641-
log(`${SWEEP}: every MCP SDK package is current; no-op`);
642-
emit([]);
643-
return;
684+
log(`${SWEEP}: every MCP SDK package is current`);
644685
}
645686

646687
const existing = sweepIssues(repo, spawn, {
@@ -762,6 +803,41 @@ export function main({
762803
warn(`${SWEEP}: ${state.group.label} failed: ${error.message}`);
763804
}
764805
}
806+
807+
// A settled group files nothing and queues nothing; it only rewrites an
808+
// OPEN issue for its target (any target, once no manifest declares it)
809+
// to say that nothing is behind, and drops the scope labels it applied.
810+
for (const state of settled) {
811+
const { compare } = versioning(state.group.ecosystem);
812+
const open = validTargets(
813+
existing.filter(
814+
(i) => i.marker.key === state.group.key && i.state === "OPEN",
815+
),
816+
state.group,
817+
).filter(
818+
(i) =>
819+
state.target === null || compare(i.marker.target, state.target) === 0,
820+
);
821+
try {
822+
for (const issue of open) {
823+
const refresh = refreshPlan(issue, {
824+
...state,
825+
target: state.target ?? issue.marker.target,
826+
});
827+
if (!refresh) continue;
828+
writer.edit(issue.number, refresh);
829+
log(
830+
`${SWEEP}: #${issue.number} has nothing behind any more; refreshed it` +
831+
(refresh.removeLabels.length
832+
? ` and removed ${refresh.removeLabels.join(", ")}`
833+
: ""),
834+
);
835+
}
836+
} catch (error) {
837+
failures.push(`${state.group.label}: ${error.message}`);
838+
warn(`${SWEEP}: ${state.group.label} failed: ${error.message}`);
839+
}
840+
}
765841
} finally {
766842
emit(filed);
767843
}

‎scripts/sdk-watch.test.mjs‎

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,10 @@ function fakeWorld(state = {}) {
423423
if (s.createFail?.(args)) return ok({ status: 1, stderr: "boom" });
424424
return ok({ stdout: `https://github.com/o/r/issues/${s.nextIssue++}\n` });
425425
}
426-
if (a === "issue" && b === "edit") return ok();
426+
if (a === "issue" && b === "edit") {
427+
if (s.editFail) return ok({ status: 1, stderr: "edit boom" });
428+
return ok();
429+
}
427430
if (a === "issue" && b === "comment") {
428431
if (s.commentFail) return ok({ status: 1, stderr: "comment boom" });
429432
return ok();
@@ -534,7 +537,9 @@ test("a quiet night is a no-op that emits []", (t) => {
534537
run(world, { output });
535538
assert.equal(writes(world.calls).length, 0);
536539
assert.deepEqual(filedFrom(output), []);
537-
assert.ok(!world.calls.some((c) => c.args[1] === "list"));
540+
// Still listed: an open issue for a settled group may need refreshing.
541+
assert.ok(world.calls.some((c) => c.args[1] === "list"));
542+
assert.ok(!world.calls.some((c) => /milestones/.test(c.args[1] ?? "")));
538543
});
539544

540545
const sweepIssue = (number, key, target, state = "OPEN", author = bot) => ({
@@ -827,6 +832,102 @@ test("a dry run previews the refresh; a closed issue is never refreshed", (t) =>
827832
assert.equal(writes(closed.calls).length, 0);
828833
});
829834

835+
test("the last outdated copy catching up rewrites the open issue to say so", (t) => {
836+
const noPy = files({ "src/time/uv.lock": UV("2.3.0") });
837+
const [filed] = filedIssues({ files: noPy });
838+
filed.labels.push({ name: "help wanted" });
839+
// Both copies reach the target: the group files nothing and is settled.
840+
const caughtUp = files({
841+
"src/time/uv.lock": UV("2.3.0"),
842+
"package-lock.json": JSON.stringify({
843+
packages: {
844+
"": { name: "@modelcontextprotocol/servers" },
845+
"node_modules/@modelcontextprotocol/sdk": { version: "1.32.1" },
846+
"src/memory/node_modules/@modelcontextprotocol/sdk": {
847+
version: "1.32.1",
848+
},
849+
},
850+
}),
851+
});
852+
const world = fakeWorld({ issues: [filed], files: caughtUp });
853+
const output = outputFile(t);
854+
run(world, { output });
855+
const [edit, ...rest] = writes(world.calls);
856+
assert.equal(rest.length, 0);
857+
assert.deepEqual(edit.args.slice(0, 3), ["issue", "edit", "600"]);
858+
assert.deepEqual(
859+
edit.args.filter((_, i) => edit.args[i - 1] === "--remove-label"),
860+
["server-memory"],
861+
);
862+
assert.ok(!edit.args.includes("--add-label"));
863+
assert.equal(parseMarker(edit.input).target, "1.32.1");
864+
assert.match(edit.input, /Nothing here is behind 1\.32\.1 any more/);
865+
assert.doesNotMatch(edit.input, /\*\*yes\*\*/);
866+
assert.doesNotMatch(edit.input, /- \[ \]/);
867+
// Nothing to analyze, and nothing filed.
868+
assert.deepEqual(filedFrom(output), []);
869+
assert.match(world.lines.join("\n"), /#600 has nothing behind any more/);
870+
871+
// The next night finds it current; a closed one is never touched.
872+
const next = fakeWorld({
873+
issues: [{ ...filed, body: edit.input, labels: [] }],
874+
files: caughtUp,
875+
});
876+
run(next, { output: outputFile(t) });
877+
assert.equal(writes(next.calls).length, 0);
878+
const closed = fakeWorld({
879+
issues: [{ ...filed, state: "CLOSED" }],
880+
files: caughtUp,
881+
});
882+
run(closed, { output: outputFile(t) });
883+
assert.equal(writes(closed.calls).length, 0);
884+
});
885+
886+
test("a group no manifest declares any more rewrites its open issues", (t) => {
887+
const [filed] = filedIssues({
888+
files: files({ "src/time/uv.lock": UV("2.3.0") }),
889+
});
890+
// Every server moves off the v1 SDK, leaving no row in its group.
891+
const migrated = files({
892+
"src/time/uv.lock": UV("2.3.0"),
893+
"package.json": JSON.stringify({ name: "@modelcontextprotocol/servers" }),
894+
"src/memory/package.json": JSON.stringify({
895+
name: "@modelcontextprotocol/server-memory",
896+
}),
897+
});
898+
const world = fakeWorld({ issues: [filed], files: migrated });
899+
run(world, { output: outputFile(t) });
900+
const [edit, ...rest] = writes(world.calls);
901+
assert.equal(rest.length, 0);
902+
assert.deepEqual(
903+
edit.args.filter((_, i) => edit.args[i - 1] === "--remove-label"),
904+
["server-memory"],
905+
);
906+
assert.equal(parseMarker(edit.input).target, "1.32.1");
907+
assert.match(edit.input, /No manifest on `v2\/main` declares/);
908+
assert.doesNotMatch(edit.input, /\| Package \|/);
909+
assert.ok(!world.calls.some((c) => c.cmd === "npm"));
910+
});
911+
912+
test("a settled group's edit failure fails the run after the rest", (t) => {
913+
const [filed] = filedIssues({
914+
files: files({ "src/time/uv.lock": UV("2.3.0") }),
915+
});
916+
const world = fakeWorld({
917+
issues: [filed],
918+
files: files({
919+
"src/time/uv.lock": UV("2.3.0"),
920+
"package.json": "{}",
921+
"src/memory/package.json": "{}",
922+
}),
923+
editFail: true,
924+
});
925+
assert.throws(
926+
() => run(world, { output: outputFile(t) }),
927+
/1 group\(s\) failed: MCP TypeScript SDK \(v1\): gh issue edit failed/,
928+
);
929+
});
930+
830931
test("a failure after filing still emits what was filed, then fails", (t) => {
831932
const world = fakeWorld({
832933
issues: [sweepIssue(9, "python-sdk", "2.2.0")],

0 commit comments

Comments
 (0)