fix(server): PR sync waits out a GitHub rate limit pause instead of failing every PR #16203
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 4 commits into
main fromrefs/pull/16203/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:M
- apps/server/src/orchestration-v2/PullRequestSyncReactor.ts line 336OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -315,8 +322,15 @@322+ let attempted = 0;323+ let skipped = 0;324+ let firstSkip: { readonly key: string; readonly reason: string } | undefined;315325 yield* Effect.forEach(316326 groups,317- ([key, entries]) =>318- (scope === "all" || requested.has(key)) && isDue(key, entries, nowMs)319- ? syncGroup(key, entries).pipe(320- Effect.catchCause(logSkipped("pull request sync skipped", { key })),321- )322- : Effect.void,327+ ([key, entries]) => {328+ if (!((scope === "all" || requested.has(key)) && isDue(key, entries, nowMs))) {329+ return Effect.void;330+ }331+ attempted += 1;332+ return syncGroup(key, entries).pipe(333+ Effect.catchCause((cause) => {334+ if (Cause.hasInterruptsOnly(cause)) return Effect.failCause(cause);335+ skipped += 1;336+ firstSkip ??= { key, reason: skipReason(cause) };
- @@ -323,4 +336,21 @@336+ firstSkip ??= { key, reason: skipReason(cause) };337+ return Effect.void;338+ }),339+ );340+ },323341 // As wide as one batched summary read, so the sweep's reads on a host arrive together and324342 // GitHub answers them in one request rather than one `gh pr view` apiece.325343 { concurrency: 25, discard: true },326344 );345+ // A rate limit pause or a signed-out CLI fails every due pull request the same way each346+ // minute. Report it once, then again only when the reason changes or a sweep succeeds.347+ if (firstSkip === undefined) {348+ if (attempted > 0) lastSkipReason = undefined;349+ } else if (firstSkip.reason !== lastSkipReason) {350+ lastSkipReason = firstSkip.reason;351+ yield* Effect.logWarning("pull request sync skipped", {352+ count: skipped,353+ key: firstSkip.key,354+ reason: firstSkip.reason,355+ });356+ }
t3dotgg(GitHub profile, opens in a new tab) changed the title
- apps/server/src/orchestration-v2/PullRequestSyncReactor.ts line 353OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -312,11 +338,16 @@312338 );313339 });314340341+ // Failed host reads by reason: how many, and the first key that failed that way.342+ const skips = new Map<string, { count: number; readonly key: string }>();315343 yield* Effect.forEach(316344 groups,317345 ([key, entries]) =>318- (scope === "all" || requested.has(key)) && isDue(key, entries, nowMs)319- ? syncGroup(key, entries).pipe(320- Effect.catchCause(logSkipped("pull request sync skipped", { key })),321- )322- : Effect.void,346+ Effect.suspend(() => {347+ if (!((scope === "all" || requested.has(key)) && isDue(key, entries, nowMs))) {348+ return Effect.void;349+ }350+ const first = entries[0]!;351+ const pauseKey = `${first.thread.projectId}\0${normalizeThreadPullRequestKey(first.link).host}`;352+ // Checked as each read starts, so a pause found earlier in this sweep holds the rest.353+ if ((pausedUntil.get(pauseKey) ?? 0) > nowMs) return Effect.void;apps/server/src/orchestration-v2/PullRequestSyncReactor.ts line 357OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -315,8 +342,16 @@342+ const skips = new Map<string, { count: number; readonly key: string }>();315343 yield* Effect.forEach(316344 groups,317345 ([key, entries]) =>318- (scope === "all" || requested.has(key)) && isDue(key, entries, nowMs)319- ? syncGroup(key, entries).pipe(320- Effect.catchCause(logSkipped("pull request sync skipped", { key })),321- )322- : Effect.void,346+ Effect.suspend(() => {347+ if (!((scope === "all" || requested.has(key)) && isDue(key, entries, nowMs))) {348+ return Effect.void;349+ }350+ const first = entries[0]!;351+ const pauseKey = `${first.thread.projectId}\0${normalizeThreadPullRequestKey(first.link).host}`;352+ // Checked as each read starts, so a pause found earlier in this sweep holds the rest.353+ if ((pausedUntil.get(pauseKey) ?? 0) > nowMs) return Effect.void;354+ return syncGroup(key, entries).pipe(355+ Effect.catchCause((cause) => {356+ if (Cause.hasInterruptsOnly(cause)) return Effect.failCause(cause);357+ const retryAt = rateLimitRetryAt(cause);
- @@ -315,8 +357,15 @@357+ const reason = skipReason(cause);358+ const skip = skips.get(reason);359+ if (skip === undefined) skips.set(reason, { count: 1, key });360+ else skip.count += 1;361+ return Effect.void;362+ }),363+ );315364 yield* Effect.forEach(316365 groups,317- ([key, entries]) =>318- (scope === "all" || requested.has(key)) && isDue(key, entries, nowMs)319- ? syncGroup(key, entries).pipe(320- Effect.catchCause(logSkipped("pull request sync skipped", { key })),321- )322- : Effect.void,366+ ([key, entries]) => {367+ if (!((scope === "all" || requested.has(key)) && isDue(key, entries, nowMs))) {368+ return Effect.void;369+ }370+ const first = entries[0]!;371+ const pauseKey = `${first.thread.projectId}\0${normalizeThreadPullRequestKey(first.link).host}`;
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