Skip to content

Commit 82d9ba9

Browse files
authored
fix(apply): comment-only sync defers on GitHub rate limit instead of failing the run (#1160)
The scheduled comment-sync lane hard-failed whenever a per-item live read hit an exhausted GitHub quota, recording a workflow failure for work that simply retries on the next 15-minute tick. The throttle now rides the existing runtime-budget yield: the interrupted item returns to the cursor, remaining batch work defers, and apply events finalize as a clean yield. Close-mode apply keeps its loud failure semantics.
1 parent c475108 commit 82d9ba9

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ checkpoint, and status-only commits are intentionally omitted.
1919
### Changed
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.
22+
- 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.
2223
- 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.
2324
- GitHub-throttled terminal status updates no longer fail the finalization run; the requeue step already re-arms the acknowledgement for after the rate window.
2425

‎src/clawsweeper-command-operations.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type {
3232
ReviewStartStatusCommentResult,
3333
} from "./clawsweeper-types.js";
3434
import { UserFacingCommandError } from "./command.js";
35+
import { GitHubRateLimitError } from "./github-retry.js";
3536
import { syncDecisionPacketRecord } from "./decision-packets.js";
3637
import { captureCanonicalRecordBaseline } from "./repair/canonical-record-baseline.js";
3738
import { type RepositoryProfile } from "./repository-profiles.js";
@@ -569,6 +570,19 @@ export function createCommandOperations(dependencies: CreateCommandOperationsDep
569570
runtimeBudget.onYield(error.reason);
570571
return;
571572
}
573+
if (
574+
error instanceof GitHubRateLimitError &&
575+
boolArg(args.sync_comments_only) &&
576+
runtimeBudget.onYield
577+
) {
578+
// Comment sync is idempotent and re-runs on the next 15-minute tick,
579+
// so an exhausted GitHub quota defers the remaining batch like a
580+
// runtime-budget yield instead of recording a workflow failure.
581+
runtimeBudget.onYield(
582+
`GitHub rate limited until ${error.retryAt}; comment sync deferred to the next cycle`,
583+
);
584+
return;
585+
}
572586
runtimeBudget.onFailure?.(error);
573587
throw error;
574588
}

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,3 +2877,91 @@ if (args[0] === "api" && args[1] === "-i" && /\\/issues\\/321\\/timeline(?:\\?|$
28772877
}
28782878
}
28792879
});
2880+
2881+
test("comment-only sync defers the remaining batch when GitHub is rate limited", () => {
2882+
const root = mkdtempSync(tmpPrefix);
2883+
try {
2884+
const itemsDir = join(root, "items");
2885+
const closedDir = join(root, "closed");
2886+
const plansDir = join(root, "plans");
2887+
const reportPath = join(root, "apply-report.json");
2888+
mkdirSync(itemsDir, { recursive: true });
2889+
mkdirSync(plansDir, { recursive: true });
2890+
const originalReport = implementedCloseReport();
2891+
writeFileSync(join(itemsDir, "321.md"), originalReport, "utf8");
2892+
2893+
const ghMock = `
2894+
const rawArgs = process.argv.slice(2);
2895+
const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
2896+
const path = args[1] || "";
2897+
if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
2898+
console.error("gh: API rate limit exceeded for installation. (HTTP 403)");
2899+
process.exit(1);
2900+
}
2901+
console.error("unexpected gh args", JSON.stringify(args));
2902+
process.exit(1);
2903+
`;
2904+
withMockGh(root, ghMock, () => {
2905+
runApplyDecisionsForTest({
2906+
itemsDir,
2907+
closedDir,
2908+
plansDir,
2909+
reportPath,
2910+
extraArgs: ["--sync-comments-only"],
2911+
});
2912+
});
2913+
2914+
const report = JSON.parse(readText(reportPath));
2915+
assert.deepEqual(
2916+
report.map((result) => ({ number: result.number, action: result.action })),
2917+
[
2918+
{ number: 321, action: "skipped_runtime_budget" },
2919+
{ number: 0, action: "skipped_runtime_budget" },
2920+
],
2921+
);
2922+
for (const result of report) {
2923+
assert.match(result.reason, /rate limited until .*comment sync deferred/);
2924+
}
2925+
assert.equal(readText(join(itemsDir, "321.md")), originalReport);
2926+
assert.equal(existsSync(join(closedDir, "321.md")), false);
2927+
} finally {
2928+
rmSync(root, { recursive: true, force: true });
2929+
}
2930+
});
2931+
2932+
test("close-mode apply still fails loudly when GitHub is rate limited", () => {
2933+
const root = mkdtempSync(tmpPrefix);
2934+
try {
2935+
const itemsDir = join(root, "items");
2936+
const closedDir = join(root, "closed");
2937+
const plansDir = join(root, "plans");
2938+
const reportPath = join(root, "apply-report.json");
2939+
mkdirSync(itemsDir, { recursive: true });
2940+
mkdirSync(plansDir, { recursive: true });
2941+
writeFileSync(join(itemsDir, "321.md"), implementedCloseReport(), "utf8");
2942+
2943+
const ghMock = `
2944+
const rawArgs = process.argv.slice(2);
2945+
const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
2946+
const path = args[1] || "";
2947+
if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
2948+
console.error("gh: API rate limit exceeded for installation. (HTTP 403)");
2949+
process.exit(1);
2950+
}
2951+
console.error("unexpected gh args", JSON.stringify(args));
2952+
process.exit(1);
2953+
`;
2954+
assert.throws(
2955+
() =>
2956+
withMockGh(root, ghMock, () => {
2957+
runApplyDecisionsForTest({ itemsDir, closedDir, plansDir, reportPath });
2958+
}),
2959+
/rate limit/i,
2960+
);
2961+
2962+
assert.ok(existsSync(join(itemsDir, "321.md")));
2963+
assert.equal(existsSync(join(closedDir, "321.md")), false);
2964+
} finally {
2965+
rmSync(root, { recursive: true, force: true });
2966+
}
2967+
});

0 commit comments

Comments
 (0)