Skip to content

Commit 3dc70e6

Browse files
fix(queue): complete head-drifted exact reviews as superseded no-ops (#966)
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
1 parent df0e4d7 commit 3dc70e6

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ checkpoint, and status-only commits are intentionally omitted.
1818

1919
### Changed
2020

21+
- Exact reviews whose pull request head moved past the queued authority now complete as superseded no-ops (the newer push owns its own review) instead of failing and burning the item's review-failure budget.
2122
- Close-coverage proof runs now remove their model scratch files (`N-M.model.json`, `N-M.prompt.md`) from the proof artifact tree, which the apply-lane validator was correctly rejecting and failing every apply run.
2223
- Repaired legacy exact-review decisions whose empty branch was shifted to the string `0`, resolved invalid queued branches from the target repository default, and requeued temporary branch-resolution failures without spending the eight-attempt review-failure budget.
2324
- Made scheduled exact reviews immediately ready after fleet admission, automatically retried recoverable parked reviews on a bounded 5/10/20-minute cycle, and exposed backoff/park reason counts in queue status and the dashboard.

‎src/clawsweeper.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22944,9 +22944,15 @@ function reserveReviewLeaseCommand(args: Args): void {
2294422944
item.kind === "pull_request" &&
2294522945
queueAuthority.sourceHeadSha !== currentRevision
2294622946
) {
22947-
throw new UserFacingCommandError(
22948-
"Exact-review queue authority source head does not match the current pull request.",
22947+
// The PR moved past the queued head. The push that moved it enqueues its
22948+
// own exact-head event (and the scheduled sweep backstops a lost webhook),
22949+
// so this stale entry completes as a superseded no-op instead of burning
22950+
// the item's review-failure budget.
22951+
console.error(
22952+
`Exact-review queue authority source head ${queueAuthority.sourceHeadSha} does not match the current pull request head ${currentRevision}; completing as superseded.`,
2294922953
);
22954+
console.log(JSON.stringify({ status: "superseded", reason: "source_head_drift" }));
22955+
return;
2295022956
}
2295122957
const reservationAuthority =
2295222958
queueAuthority && item.kind === "pull_request" && !queueAuthority.sourceHeadSha

‎test/command.test.ts‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,93 @@ process.stdout.write("200");
276276
}
277277
});
278278

279+
test("reserve-review-lease completes as superseded when the PR head drifted past the queue authority", () => {
280+
const root = mkdtempSync(join(tmpdir(), "cmd-reserve-lease-drift-"));
281+
const binDir = join(root, "bin");
282+
const ghPath = join(binDir, "gh.js");
283+
const leasePath = join(root, "lease.json");
284+
const headSha = "0123456789abcdef0123456789abcdef01234567";
285+
const queuedHeadSha = "f".repeat(40);
286+
try {
287+
mkdirSync(binDir, { recursive: true });
288+
writeFileSync(
289+
ghPath,
290+
`
291+
const { readFileSync, writeFileSync } = require("node:fs");
292+
const leasePath = ${JSON.stringify(leasePath)};
293+
const headSha = ${JSON.stringify(headSha)};
294+
const args = process.argv.slice(2);
295+
const path = args[1] || "";
296+
if (args[0] === "api" && path === "repos/openclaw/openclaw/issues/357") {
297+
console.log(JSON.stringify({
298+
number: 357,
299+
title: "Reserve durable exact review lease",
300+
html_url: "https://github.com/openclaw/openclaw/pull/357",
301+
created_at: "2026-07-15T00:00:00Z",
302+
updated_at: "2026-07-15T00:00:00Z",
303+
closed_at: null,
304+
state: "open",
305+
locked: false,
306+
active_lock_reason: null,
307+
author_association: "CONTRIBUTOR",
308+
user: { login: "reporter" },
309+
labels: [],
310+
pull_request: {}
311+
}));
312+
} else if (args[0] === "api" && path === "repos/openclaw/openclaw/pulls/357") {
313+
console.log(JSON.stringify({ head: { sha: headSha } }));
314+
} else if (args[0] === "api" && path === "repos/openclaw/openclaw/issues/357/comments" && args.includes("--method")) {
315+
writeFileSync(leasePath, readFileSync(args[args.indexOf("--input") + 1], "utf8"));
316+
console.log(JSON.stringify({ id: 9992 }));
317+
} else if (args[0] === "api" && path.startsWith("repos/openclaw/openclaw/issues/357/comments")) {
318+
console.log(JSON.stringify(args.includes("--slurp") ? [[]] : []));
319+
} else {
320+
console.error("unexpected gh args", JSON.stringify(args));
321+
process.exit(1);
322+
}
323+
`,
324+
"utf8",
325+
);
326+
const result = spawnSync(
327+
process.execPath,
328+
[
329+
CLI,
330+
"reserve-review-lease",
331+
"--target-repo",
332+
"openclaw/openclaw",
333+
"--item-number",
334+
"357",
335+
"--review-timeout-ms",
336+
"600000",
337+
],
338+
{
339+
encoding: "utf8",
340+
env: {
341+
...process.env,
342+
...mockGhBinEnv(ghPath, binDir),
343+
GITHUB_RUN_ID: "999",
344+
GITHUB_RUN_ATTEMPT: "1",
345+
EXACT_REVIEW_QUEUE_URL: "https://queue.example.invalid",
346+
EXACT_REVIEW_ITEM_KEY: "openclaw/openclaw#357",
347+
EXACT_REVIEW_LEASE_ID: "lease-357",
348+
EXACT_REVIEW_LEASE_REVISION: "1",
349+
EXACT_REVIEW_CLAIM_GENERATION: "1",
350+
EXACT_REVIEW_SOURCE_HEAD_SHA: queuedHeadSha,
351+
},
352+
},
353+
);
354+
355+
assert.equal(result.status, 0, result.stderr);
356+
const reservation = JSON.parse(result.stdout);
357+
assert.equal(reservation.status, "superseded");
358+
assert.equal(reservation.reason, "source_head_drift");
359+
assert.match(result.stderr, /does not match the current pull request head/);
360+
assert.equal(existsSync(leasePath), false, "no lease comment may be posted on drift");
361+
} finally {
362+
rmSync(root, { recursive: true, force: true });
363+
}
364+
});
365+
279366
test("reserve-review-lease stale A preserves newer-head lease B", () => {
280367
const root = mkdtempSync(join(tmpdir(), "cmd-reserve-lease-race-"));
281368
const binDir = join(root, "bin");

0 commit comments

Comments
 (0)