GeezerVison is showing github.com — fix(server): PR sync backs off links on hosts it cannot read (#36901) · pingdotgg/t3code@ea05ea5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/git/GitManager.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,7 @@ import * as PubSub from "effect/PubSub"; | 18 | 18 | import * as Ref from "effect/Ref"; | 19 | 19 | import * as Schema from "effect/Schema"; | 20 | 20 | import * as Scope from "effect/Scope"; | | 21 | +import * as Semaphore from "effect/Semaphore"; | 21 | 22 | import * as Stream from "effect/Stream"; | 22 | 23 | import { | 23 | 24 | GitActionProgressEvent, | @@ -189,6 +190,9 @@ const PR_LOOKUP_FAILURE_MAX_TTL = Duration.minutes(15); | 189 | 190 | const PR_LOOKUP_CACHE_CAPACITY = 2_048; | 190 | 191 | const PR_LOOKUP_GIT_STATE_TTL = Duration.minutes(5); | 191 | 192 | const SETTLED_PR_LOOKUP_RECHECK_INTERVAL = Duration.minutes(15); | | 193 | +// Shared by every background caller (backfill, settlement, cleanup), so startup discovery | | 194 | +// cannot fill the git and forge process slots that foreground work also needs. | | 195 | +const BRANCH_PR_LOOKUP_CONCURRENCY = 4; | 192 | 196 | const PR_THREAD_CONTEXT_BYTES = 16_000; | 193 | 197 | const PR_THREAD_COMMAND_OUTPUT_CHARS = 2_000; | 194 | 198 | const isSourceControlProviderError = Schema.is(SourceControlProviderError); | @@ -2579,6 +2583,7 @@ export const make = Effect.gen(function* () { | 2579 | 2583 | prLookupGitStateByKey.set(entryKey, { readAtMs, value }); | 2580 | 2584 | return value; | 2581 | 2585 | }); | | 2586 | + const branchPrLookups = yield* Semaphore.make(BRANCH_PR_LOOKUP_CONCURRENCY); | 2582 | 2587 | const settledPrLookupByBranchKey = new Map< | 2583 | 2588 | string, | 2584 | 2589 | { readonly url: string; readonly fingerprint: string; readonly confirmedAtMs: number } | @@ -2879,7 +2884,7 @@ export const make = Effect.gen(function* () { | 2879 | 2884 | }); | 2880 | 2885 | } | 2881 | 2886 | return confirmed; | 2882 | | - }); | | 2887 | + }, branchPrLookups.withPermits(1)); | 2883 | 2888 |
| 2884 | 2889 | const checkedOutPullRequest: GitManager["Service"]["checkedOutPullRequest"] = Effect.fn( | 2885 | 2890 | "checkedOutPullRequest", | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts +41-1Lines changed: 41 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | ProjectId, | 9 | 9 | ProviderInstanceId, | 10 | 10 | PullRequestOperationError, | | 11 | + PullRequestUnavailableError, | 11 | 12 | RunId, | 12 | 13 | ThreadId, | 13 | 14 | TurnItemId, | @@ -180,7 +181,7 @@ interface HarnessOptions { | 180 | 181 | readonly snapshot: TestShellSnapshot; | 181 | 182 | readonly summary?: ( | 182 | 183 | input: PullRequestRef, | 183 | | - ) => Effect.Effect<PullRequestSummary, PullRequestOperationError>; | | 184 | + ) => Effect.Effect<PullRequestSummary, PullRequestService.PullRequestError>; | 184 | 185 | readonly stack?: ( | 185 | 186 | input: PullRequestRef, | 186 | 187 | ) => Effect.Effect<PullRequestStack | null, PullRequestOperationError>; | @@ -1674,6 +1675,45 @@ describe("PullRequestSyncReactor", () => { | 1674 | 1675 | }), | 1675 | 1676 | ); | 1676 | 1677 |
| | 1678 | + it.effect("stops reading a pull request on a host it cannot browse each sweep", () => | | 1679 | + Effect.gen(function* () { | | 1680 | + yield* TestClock.setTime(Date.parse(NOW)); | | 1681 | + const fixture = yield* makeHarness({ | | 1682 | + snapshot: makeSnapshot([ | | 1683 | + makeThread("unsupported", { pullRequests: [makeLink(9, { state: "open" })] }), | | 1684 | + makeThread("fine", { pullRequests: [makeLink(8, { state: "open" })] }), | | 1685 | + ]), | | 1686 | + summary: (input) => | | 1687 | + input.number === 9 | | 1688 | + ? Effect.fail(new PullRequestUnavailableError({ reason: "provider-unsupported" })) | | 1689 | + : Effect.succeed(makeSummary(input)), | | 1690 | + }); | | 1691 | + const unsupportedReads = Ref.get(fixture.summaryCalls).pipe( | | 1692 | + Effect.map((calls) => calls.filter((call) => call.number === 9).length), | | 1693 | + ); | | 1694 | + yield* Effect.gen(function* () { | | 1695 | + const reactor = yield* startAndSweep(fixture); | | 1696 | + for (let index = 0; index < 5; index += 1) yield* sweepAgain(fixture, reactor); | | 1697 | + const afterSweeps = yield* unsupportedReads; | | 1698 | + | | 1699 | + // A refresh another link asks for must not re-read the unsupported one as well. | | 1700 | + yield* reactor.requestSync(makeLink(9)); | | 1701 | + yield* Queue.take(fixture.snapshotReads); | | 1702 | + yield* reactor.drain; | | 1703 | + const afterItsRefresh = yield* unsupportedReads; | | 1704 | + for (let index = 0; index < 3; index += 1) { | | 1705 | + yield* reactor.requestSync(makeLink(8)); | | 1706 | + yield* Queue.take(fixture.snapshotReads); | | 1707 | + yield* reactor.drain; | | 1708 | + } | | 1709 | + assert.deepStrictEqual( | | 1710 | + { afterSweeps, afterItsRefresh, afterOtherRefreshes: yield* unsupportedReads }, | | 1711 | + { afterSweeps: 1, afterItsRefresh: 2, afterOtherRefreshes: 2 }, | | 1712 | + ); | | 1713 | + }).pipe(Effect.provide(fixture.layer)); | | 1714 | + }), | | 1715 | + ); | | 1716 | + | 1677 | 1717 | it.effect( | 1678 | 1718 | "holds missing links through sibling and link updates but honors a reader refresh", | 1679 | 1719 | () => | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.ts +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -366,7 +366,8 @@ export const make = Effect.gen(function* () { | 366 | 366 | // linking dozens of pull requests) is read together and shares the summary batches. | 367 | 367 | let requestedSweepQueued = false; | 368 | 368 | const retryStacks = new Set<string>(); | 369 | | - // Group keys the host answered not-found for; they are read on the slow cadence until found. | | 369 | + // Group keys the host answered not-found for, or this server cannot read (no CLI, signed out, | | 370 | + // unsupported host); they are read on the slow cadence until a read succeeds. | 370 | 371 | const missing = new Set<string>(); | 371 | 372 | // Pause per project and host because credentials are project-specific; leave paused PRs due until reset. | 372 | 373 | const pausedUntil = new Map<string, number>(); | @@ -510,9 +511,10 @@ export const make = Effect.gen(function* () { | 510 | 511 | if (invalidated) yield* pullRequests.invalidate({ reference: ref }); | 511 | 512 | const summary = yield* pullRequests.summary(ref, { recoverTransientFailure: false }).pipe( | 512 | 513 | Effect.tapError((error) => | 513 | | - error.reason === "not-found" | | 514 | + error.reason === "not-found" || error._tag === "PullRequestUnavailableError" | 514 | 515 | ? Effect.sync(() => { | 515 | | - // Not-found is a host answer: it consumes the refresh and starts the backoff. | | 516 | + // Not-found, or a host this server cannot read, won't change by asking again | | 517 | + // next sweep: it consumes the refresh and starts the backoff. | 516 | 518 | missing.add(key); | 517 | 519 | lastSyncedAt.set(key, nowMs); | 518 | 520 | requested.delete(key); | |
|