fix(ci): pace API requests to avoid rate limit thrashing

This commit is contained in:
Ashley Mensah
2026-04-28 17:30:18 +02:00
parent 695614834e
commit 4fc0cb7ec4

View File

@@ -198,10 +198,21 @@ function enforcePolicy(modelOut, pre) {
console.log(`Classifying ${candidates.length} candidates with ${MODEL}...\n`);
// 15 req/min limit → 1 request every 4s. Use 4.5s for safety margin.
const PACE_MS = 4500;
let lastRequestTime = 0;
async function paced(fn) {
const elapsed = Date.now() - lastRequestTime;
if (elapsed < PACE_MS) await sleep(PACE_MS - elapsed);
lastRequestTime = Date.now();
return fn();
}
const decisions = [];
for (const candidate of candidates) {
const pre = preScore(candidate);
const modelOut = await callGitHubModel(candidate);
const modelOut = await paced(() => callGitHubModel(candidate));
const finalDecision = enforcePolicy(modelOut, pre);
decisions.push({