Skip to content

Commit 008c865

Browse files
committed
fix(apply): close-mode apply yields on GitHub rate limit instead of failing mid-scan
Production runs after #1160 showed close-mode apply still losing entire 600-record scan windows to mid-run 403s (e.g. run 31780550963 died 17 minutes in during per-item comment pagination). Quota exhaustion now takes the same runtime-budget yield in every apply mode: closes are per-item verified and checkpointed, the cursor trace returns the interrupted item to the next window, and apply events finalize as a clean yield.
1 parent 746cb85 commit 008c865

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

‎CHANGELOG.md‎

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

2121
- Folder reconciliation now defers with a zero-mutation result when the open-state scan hits GitHub rate limiting, so throttled proof/apply/publish runs proceed to their close and publication work instead of failing before `Apply close proposals` can run.
2222
- Comment-only sync now defers its remaining batch as a runtime-budget-style yield when GitHub rate limits a live read, instead of failing the scheduled run; the next 15-minute cycle resumes the interrupted item, and close-mode apply keeps its loud failure.
23+
- Close-mode apply now takes the same rate-limit yield as comment sync: a throttled live read mid-scan defers the remaining window to the next cycle instead of failing the run, after production runs kept losing 600-record scan windows to mid-run 403s.
2324
- Increased the AWS Crabbox root volume from 160 GB to 400 GB so trusted checks can provision with the repository's current dependency and build footprint.
2425
- GitHub-throttled terminal status updates no longer fail the finalization run; the requeue step already re-arms the acknowledgement for after the rate window.
2526

‎src/clawsweeper-command-operations.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,16 +592,14 @@ export function createCommandOperations(dependencies: CreateCommandOperationsDep
592592
runtimeBudget.onYield(error.reason);
593593
return;
594594
}
595-
if (
596-
error instanceof GitHubRateLimitError &&
597-
boolArg(args.sync_comments_only) &&
598-
runtimeBudget.onYield
599-
) {
600-
// Comment sync is idempotent and re-runs on the next 15-minute tick,
601-
// so an exhausted GitHub quota defers the remaining batch like a
602-
// runtime-budget yield instead of recording a workflow failure.
595+
if (error instanceof GitHubRateLimitError && runtimeBudget.onYield) {
596+
// Quota exhaustion is the same "out of resource, resume next cycle"
597+
// situation as a runtime-budget stop: closes are per-item verified
598+
// and checkpointed, comment sync is idempotent, and the cursor trace
599+
// returns the interrupted item to the next scheduled window. Failing
600+
// loudly here only discarded the rest of the scan window.
603601
runtimeBudget.onYield(
604-
`GitHub rate limited until ${error.retryAt}; comment sync deferred to the next cycle`,
602+
`GitHub rate limited until ${error.retryAt}; apply resumes next cycle`,
605603
);
606604
return;
607605
}

‎test/apply-live-state.test.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,7 +2920,7 @@ process.exit(1);
29202920
],
29212921
);
29222922
for (const result of report) {
2923-
assert.match(result.reason, /rate limited until .*comment sync deferred/);
2923+
assert.match(result.reason, /rate limited until .*apply resumes next cycle/);
29242924
}
29252925
assert.equal(readText(join(itemsDir, "321.md")), originalReport);
29262926
assert.equal(existsSync(join(closedDir, "321.md")), false);
@@ -2929,7 +2929,7 @@ process.exit(1);
29292929
}
29302930
});
29312931

2932-
test("close-mode apply still fails loudly when GitHub is rate limited", () => {
2932+
test("close-mode apply defers the remaining scan window when GitHub is rate limited", () => {
29332933
const root = mkdtempSync(tmpPrefix);
29342934
try {
29352935
const itemsDir = join(root, "items");
@@ -2938,7 +2938,8 @@ test("close-mode apply still fails loudly when GitHub is rate limited", () => {
29382938
const reportPath = join(root, "apply-report.json");
29392939
mkdirSync(itemsDir, { recursive: true });
29402940
mkdirSync(plansDir, { recursive: true });
2941-
writeFileSync(join(itemsDir, "321.md"), implementedCloseReport(), "utf8");
2941+
const originalReport = implementedCloseReport();
2942+
writeFileSync(join(itemsDir, "321.md"), originalReport, "utf8");
29422943

29432944
const ghMock = `
29442945
const rawArgs = process.argv.slice(2);
@@ -2951,15 +2952,22 @@ if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
29512952
console.error("unexpected gh args", JSON.stringify(args));
29522953
process.exit(1);
29532954
`;
2954-
assert.throws(
2955-
() =>
2956-
withMockGh(root, ghMock, () => {
2957-
runApplyDecisionsForTest({ itemsDir, closedDir, plansDir, reportPath });
2958-
}),
2959-
/rate limit/i,
2960-
);
2955+
withMockGh(root, ghMock, () => {
2956+
runApplyDecisionsForTest({ itemsDir, closedDir, plansDir, reportPath });
2957+
});
29612958

2962-
assert.ok(existsSync(join(itemsDir, "321.md")));
2959+
const report = JSON.parse(readText(reportPath));
2960+
assert.deepEqual(
2961+
report.map((result) => ({ number: result.number, action: result.action })),
2962+
[
2963+
{ number: 321, action: "skipped_runtime_budget" },
2964+
{ number: 0, action: "skipped_runtime_budget" },
2965+
],
2966+
);
2967+
for (const result of report) {
2968+
assert.match(result.reason, /rate limited until .*apply resumes next cycle/);
2969+
}
2970+
assert.equal(readText(join(itemsDir, "321.md")), originalReport);
29632971
assert.equal(existsSync(join(closedDir, "321.md")), false);
29642972
} finally {
29652973
rmSync(root, { recursive: true, force: true });

0 commit comments

Comments
 (0)