Skip to content

Commit b4d1ede

Browse files
fix(queue): absorb item-lifecycle and throttle stalls without spending review-failure budget (#968)
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
1 parent 3dc70e6 commit b4d1ede

7 files changed

Lines changed: 103 additions & 7 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,12 @@ jobs:
963963
else
964964
reserve_exit=$?
965965
fi
966+
if grep -Eqi 'rate limit exceeded|secondary rate limit|HTTP 429' "$reservation_error"; then
967+
retry_at="$(date -u -d "@$(( $(date -u +%s) + 1200 ))" +%Y-%m-%dT%H:%M:%SZ)"
968+
echo "::notice::GitHub throttled the exact-review reservation; deferring until $retry_at so the durable queue retries without spending failure budget."
969+
reservation="{\"status\":\"held\",\"retryAt\":\"$retry_at\"}"
970+
break
971+
fi
966972
if ! grep -Eqi '(exact-review queue authority changed|review revision changed|could not (confirm|identify).+review lease).+retry required' "$reservation_error"; then
967973
cat "$reservation_error" >&2
968974
exit "$reserve_exit"

‎CHANGELOG.md‎

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

1919
### Changed
2020

21+
- Exact reviews of items that closed after enqueue now complete as superseded no-ops, and GitHub-throttled reservations defer as held retries — neither spends the item's review-failure budget.
22+
- Trimmed the exact-review feed rate from 600/h to 450/h after the resumed apply and comment-sync lanes pushed the shared GitHub App installation token into rate-limit 403s.
2123
- 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.
2224
- 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.
2325
- 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.

‎dashboard/wrangler.toml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ EXACT_REVIEW_DISPATCH_DEBOUNCE_MAX_MS = "180000"
6666
EXACT_REVIEW_PENDING_SOFT_LIMIT = "600"
6767
# 200/h only sustained ~14 concurrent reviews against a 128-slot pool; with the
6868
# review/publication lane split (#953) the queue drains to zero pending while
69-
# 3,306 items have never been reviewed at all (42.9% weekly coverage). 600/h at
70-
# the measured 4.1-minute service time targets ~41 concurrent, clearing the
71-
# first-pass backlog in hours instead of days. Model spend scales with this dial.
72-
EXACT_REVIEW_TARGET_RATE_PER_HOUR = "600"
69+
# 3,306 items have never been reviewed at all (42.9% weekly coverage). Model
70+
# spend scales with this dial. 600/h saturated the GitHub App installation
71+
# token budget once the apply and comment-sync lanes resumed alongside reviews
72+
# (installation 122230863 rate-limit 403s, 2026-07-30 16:56Z): at ~30 API calls
73+
# per review, 450/h leaves the write lanes headroom inside the shared allowance
74+
# while still clearing the first-pass backlog in about a day.
75+
EXACT_REVIEW_TARGET_RATE_PER_HOUR = "450"
7376
EXACT_REVIEW_TARGET_BURST = "120"
7477
# Keep each mutation lease at 8 while allowing four isolated workflows to prepare
7578
# concurrently. Final commits still cross the single state-writer coordinator.

‎src/clawsweeper.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22924,9 +22924,14 @@ function reserveReviewLeaseCommand(args: Args): void {
2292422924
}
2292522925
const { item, state } = fetchItem(itemNumber);
2292622926
if (state !== "open") {
22927-
throw new UserFacingCommandError(
22928-
`Cannot reserve a review lease for #${itemNumber}: state is ${state}.`,
22927+
// The item was closed between enqueue and review (typically by the apply
22928+
// lane or its author). The stale entry completes as a superseded no-op
22929+
// rather than burning the item's review-failure budget.
22930+
console.error(
22931+
`Item #${itemNumber} is ${state}; completing the reservation as a superseded no-op.`,
2292922932
);
22933+
console.log(JSON.stringify({ status: "superseded", reason: "item_not_open", state }));
22934+
return;
2293022935
}
2293122936
const queueAuthority = exactReviewQueueAuthorityFromEnv();
2293222937
const expectedItemKey = `${targetRepo()}#${itemNumber}`.toLowerCase();

‎test/command.test.ts‎

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

279+
test("reserve-review-lease completes as superseded when the item closed after enqueue", () => {
280+
const root = mkdtempSync(join(tmpdir(), "cmd-reserve-lease-closed-"));
281+
const binDir = join(root, "bin");
282+
const ghPath = join(binDir, "gh.js");
283+
const leasePath = join(root, "lease.json");
284+
try {
285+
mkdirSync(binDir, { recursive: true });
286+
writeFileSync(
287+
ghPath,
288+
`
289+
const { readFileSync, writeFileSync } = require("node:fs");
290+
const leasePath = ${JSON.stringify(leasePath)};
291+
const args = process.argv.slice(2);
292+
const path = args[1] || "";
293+
if (args[0] === "api" && path === "repos/openclaw/openclaw/issues/357") {
294+
console.log(JSON.stringify({
295+
number: 357,
296+
title: "Closed before review",
297+
html_url: "https://github.com/openclaw/openclaw/pull/357",
298+
created_at: "2026-07-15T00:00:00Z",
299+
updated_at: "2026-07-15T00:00:00Z",
300+
closed_at: "2026-07-16T00:00:00Z",
301+
state: "closed",
302+
locked: false,
303+
active_lock_reason: null,
304+
author_association: "CONTRIBUTOR",
305+
user: { login: "reporter" },
306+
labels: [],
307+
pull_request: {}
308+
}));
309+
} else if (args[0] === "api" && path === "repos/openclaw/openclaw/issues/357/comments" && args.includes("--method")) {
310+
writeFileSync(leasePath, readFileSync(args[args.indexOf("--input") + 1], "utf8"));
311+
console.log(JSON.stringify({ id: 9993 }));
312+
} else {
313+
console.error("unexpected gh args", JSON.stringify(args));
314+
process.exit(1);
315+
}
316+
`,
317+
"utf8",
318+
);
319+
const result = spawnSync(
320+
process.execPath,
321+
[
322+
CLI,
323+
"reserve-review-lease",
324+
"--target-repo",
325+
"openclaw/openclaw",
326+
"--item-number",
327+
"357",
328+
"--review-timeout-ms",
329+
"600000",
330+
],
331+
{
332+
encoding: "utf8",
333+
env: {
334+
...process.env,
335+
...mockGhBinEnv(ghPath, binDir),
336+
GITHUB_RUN_ID: "999",
337+
GITHUB_RUN_ATTEMPT: "1",
338+
},
339+
},
340+
);
341+
342+
assert.equal(result.status, 0, result.stderr);
343+
const reservation = JSON.parse(result.stdout);
344+
assert.equal(reservation.status, "superseded");
345+
assert.equal(reservation.reason, "item_not_open");
346+
assert.equal(reservation.state, "closed");
347+
assert.equal(existsSync(leasePath), false, "no lease comment may be posted for closed items");
348+
} finally {
349+
rmSync(root, { recursive: true, force: true });
350+
}
351+
});
352+
279353
test("reserve-review-lease completes as superseded when the PR head drifted past the queue authority", () => {
280354
const root = mkdtempSync(join(tmpdir(), "cmd-reserve-lease-drift-"));
281355
const binDir = join(root, "bin");

‎test/dashboard-worker.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test("production doubles exact review claims and canonical publication batches",
5454
assert.match(wrangler, /EXACT_REVIEW_ACTIONS_BUDGET = "194"/);
5555
assert.match(wrangler, /EXACT_REVIEW_PUBLICATION_BATCH_SIZE = "8"/);
5656
assert.match(wrangler, /EXACT_REVIEW_PUBLICATION_BATCH_MAX_CONCURRENT = "8"/);
57-
assert.match(wrangler, /EXACT_REVIEW_TARGET_RATE_PER_HOUR = "600"/);
57+
assert.match(wrangler, /EXACT_REVIEW_TARGET_RATE_PER_HOUR = "450"/);
5858
assert.match(wrangler, /EXACT_REVIEW_TARGET_BURST = "120"/);
5959
assert.match(wrangler, /EXACT_REVIEW_PENDING_SOFT_LIMIT = "600"/);
6060
});

‎test/sweep-workflow.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ test("exact event review publishes directly with a queue-bounded canonical fallb
532532
assert.match(reserveLease.run ?? "", /RANDOM % 4/);
533533
assert.match(reserveLease.run ?? "", /status.*superseded/);
534534
assert.match(reserveLease.run ?? "", /successful no-op/);
535+
assert.match(
536+
reserveLease.run ?? "",
537+
/rate limit exceeded\|secondary rate limit\|HTTP 429/,
538+
"throttled reservations must defer as held instead of failing",
539+
);
540+
assert.match(reserveLease.run ?? "", /\\"status\\":\\"held\\",\\"retryAt\\":\\"\$retry_at\\"/);
535541
assert.match(source, /Review exact item \{0\} rev \{1\} head \{2\}/);
536542
assert.equal(
537543
reserveLease.env?.EXACT_REVIEW_ITEM_KEY,

0 commit comments

Comments
 (0)