Repository navigation
fix(server): pull request links whose reads keep failing back off instead of re-reading every minute #31969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(server): pull request links whose reads keep failing back off instead of re-reading every minute #31969
Changes from all commits
f188c79
8edf3a2
4397f86
9eab4ba
0974f3a
cc131a6
303e5d3
42add88
bb63fa7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ export const QUIET_SYNC_INTERVAL_MS = 5 * 60 * 1_000; | |
| // A pull request closed this long ago is rarely reopened, so the sweep stops reading it, as it | ||
| // does merged ones. A reader that sees it open, or a requested refresh, still reads it at once. | ||
| const CLOSED_FINAL_AFTER_MS = 24 * 60 * 60 * 1_000; | ||
| // A link whose host read failed waits a sweep, then twice as long after each further failure. | ||
| const FAILED_READ_BACKOFF_MS = 60 * 1_000; | ||
|
|
||
| const isChangeRequestCloseCommand = (command: string) => | ||
| sourceControlDefinitions.definitions.some( | ||
|
|
@@ -369,13 +371,15 @@ export const make = Effect.gen(function* () { | |
| // linking dozens of pull requests) is read together and shares the summary batches. | ||
| let requestedSweepQueued = false; | ||
| const retryStacks = new Set<string>(); | ||
| const failedReads = new Map<string, { readonly retryAtMs: number; readonly backoffMs: number }>(); | ||
| // Group keys the host answered not-found for, or this server cannot read (no CLI, signed out, | ||
| // unsupported host); they are read on the slow cadence until a read succeeds. | ||
| const missing = new Set<string>(); | ||
| // Pause per project and host because credentials are project-specific; leave paused PRs due until reset. | ||
| const pausedUntil = new Map<string, number>(); | ||
|
|
||
| const isDue = (key: string, entries: ReadonlyArray<LinkEntry>, nowMs: number): boolean => { | ||
| if ((failedReads.get(key)?.retryAtMs ?? 0) > nowMs) return false; | ||
| if (requested.has(key)) return true; | ||
| const active = entries.filter((entry) => isUnsettled(entry.thread)); | ||
| if (active.length === 0) return false; | ||
|
|
@@ -425,12 +429,17 @@ export const make = Effect.gen(function* () { | |
|
|
||
| // A host-level refresh reaches every project, each retaining its own pending retry. | ||
| for (const [key, entries] of groups) { | ||
| if (pendingRequests.has(threadPullRequestKeyOf(entries[0]!.link))) requested.add(key); | ||
| if (!pendingRequests.has(threadPullRequestKeyOf(entries[0]!.link))) continue; | ||
| requested.add(key); | ||
| // A new request reads at once; a failure after it backs off further, not from the start. | ||
| const failed = failedReads.get(key); | ||
| if (failed !== undefined) failedReads.set(key, { ...failed, retryAtMs: nowMs }); | ||
| } | ||
| pendingRequests.clear(); | ||
|
|
||
| for (const key of lastSyncedAt.keys()) if (!groups.has(key)) lastSyncedAt.delete(key); | ||
| for (const key of retryStacks) if (!groups.has(key)) retryStacks.delete(key); | ||
| for (const key of failedReads.keys()) if (!groups.has(key)) failedReads.delete(key); | ||
| for (const key of missing) if (!groups.has(key)) missing.delete(key); | ||
| for (const key of requested.keys()) if (!groups.has(key)) requested.delete(key); | ||
|
|
||
|
|
@@ -599,6 +608,7 @@ export const make = Effect.gen(function* () { | |
| } | ||
| // The host answered, so the cadence clock ticks even if a dispatch below is rejected. | ||
| lastSyncedAt.set(key, nowMs); | ||
| failedReads.delete(key); | ||
| requested.delete(key); | ||
| yield* Effect.forEach( | ||
| entries, | ||
|
|
@@ -624,6 +634,13 @@ export const make = Effect.gen(function* () { | |
| const retryAt = rateLimitRetryAt(cause); | ||
| if (retryAt !== undefined) { | ||
| pausedUntil.set(pauseKey, Math.max(retryAt, pausedUntil.get(pauseKey) ?? 0)); | ||
| } else { | ||
| const previous = failedReads.get(key); | ||
| const backoffMs = | ||
| previous === undefined | ||
| ? FAILED_READ_BACKOFF_MS | ||
| : Math.min(previous.backoffMs * 2, SLOW_SYNC_INTERVAL_MS); | ||
| failedReads.set(key, { retryAtMs: nowMs + backoffMs, backoffMs }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Start the retry delay when the failure occurs.
Read the clock in the failure handler and add
|
||
| } | ||
| const reason = skipReason(cause); | ||
| const skip = skips.get(reason); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a non-rate-limit failure this always records
failedReads(1m, then doubling to the 15m slow interval). The PR body says interruptions are excluded from backoff, but the branch visible here only special-casesrateLimitRetryAt.Does an Effect interruption (for example stopping the reactor mid-sweep, or a fiber interrupt while
glabis still running) get filtered before thiselse, or can it leave the link backed off until a later successful read clears the map? If interruptions already bail out earlier this is fine — asking because a restart would otherwise make a flaky host look "paused" for up to 15 minutes with no host pause recorded.