fix(server): PR watches stop burning GitHub's rate limit and giving up #16208
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 4 commits into
main fromrefs/pull/16208/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/PullRequestWatchReactor.ts lines 111 to 111OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -49,0 +91,21 @@91+ const snapshot = link.snapshot;92+ return snapshot === null93+ ? ""94+ : [95+ snapshot.state,96+ snapshot.updatedAt,97+ snapshot.checksState,98+ snapshot.mergeability,99+ snapshot.reviewDecision,100+ snapshot.isDraft,101+ ].join(" ");102+};103+104+function needsRead(group: WatchGroup, last: LastRead | undefined, now: number): boolean {105+ return (106+ last === undefined ||107+ !last.quiet ||108+ last.fingerprint !== group.fingerprint ||109+ now - last.at >= QUIET_REREAD_MS ||110+ // A new watch takes its first look right away.111+ group.targets.some((target) => Date.parse(target.watch.startedAt) > last.at)
- apps/server/src/orchestration-v2/PullRequestWatchReactor.ts lines 324 to 325OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -211,13 +312,14 @@211312 { concurrency: 2 },212313 ),213314 );214- // Only host reads count towards giving up; a refused wake is not the host's fault.215- const key = failureKey(target);216315 if (Exit.isFailure(read)) {217316 if (Cause.hasInterruptsOnly(read.cause)) return yield* Effect.failCause(read.cause);218- const failures = (readFailures.get(key) ?? 0) + 1;219- readFailures.set(key, failures);220- // The count stays until the stop lands, so a failed stop is tried again next pass.317+ lastReads.delete(group.key);318+ // The host's pause refuses later reads without a request, so waiting it out is free.319+ if (isRateLimited(read.cause)) return;320+ const failures = (readFailures.get(group.key) ?? 0) + 1;321+ readFailures.set(group.key, failures);322+ // The count stays until the stops land, so a failed stop is tried again next pass.221323 if (failures >= READ_FAILURE_LIMIT) {222- yield* giveUp(target);223- readFailures.delete(key);324+ yield* eachTarget(group, giveUp);325+ readFailures.delete(group.key);
- apps/server/src/orchestration-v2/PullRequestWatchReactor.ts lines 305 to 340Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -230,17 +331,6 @@230-231- // Never advance the remark watermark past comments an incomplete read could have missed.232- const remarks = yield* readRemarks(target, reference, activity);233- const report = evaluatePullRequestWatch(watch, detail, remarks);234- if (report.changes.length > 0) {235- return yield* record(236- target,237- report.exhausted ? null : report.next,238- pullRequestWatchMessage({239- number: link.number,240- url: link.url,241- baseBranch: detail.baseBranch,242- headSha: report.next.headSha,243- report,244- }),331+ if (detail.state !== "open") {332+ lastReads.delete(group.key);333+ return yield* eachTarget(group, (target) =>334+ detail.state === "closed" ? closed(target) : record(target, null),245335 );246336 }apps/server/src/orchestration-v2/PullRequestWatchReactor.ts lines 354 to 373Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -248,3 +349,21 @@349+ });350+ yield* eachTarget(group, (target) => {351+ const report = evaluatePullRequestWatch(target.watch, detail, remarks);352+ if (report.changes.length > 0) {353+ return record(354+ target,355+ report.exhausted ? null : report.next,356+ pullRequestWatchMessage({357+ number: target.link.number,358+ url: target.link.url,359+ baseBranch: detail.baseBranch,360+ headSha: report.next.headSha,361+ report,362+ }),363+ );364+ }365+ return watchesEqual(report.next, target.watch) ? Effect.void : record(target, report.next);366+ });248367 });249368250369 const sweep = Effect.gen(function* () {
- apps/server/src/orchestration-v2/PullRequestWatchReactor.ts lines 351 to 367Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -247,0 +347,21 @@347+ // Comments a partial read could not see are read again next pass.348+ quiet:349+ remarks !== null &&350+ detail.mergeability !== "unknown" &&351+ detail.checks.every((check) => check.status !== "pending"),352+ watches: new Set(group.targets.map(watchKey)),353+ });354+ yield* eachTarget(group, (target) => {355+ const report = evaluatePullRequestWatch(target.watch, detail, remarks);356+ if (report.changes.length > 0) {357+ return record(358+ target,359+ report.exhausted ? null : report.next,360+ pullRequestWatchMessage({361+ number: target.link.number,362+ url: target.link.url,363+ baseBranch: detail.baseBranch,364+ headSha: report.next.headSha,365+ report,366+ }),367+ );
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed