GeezerVison is showing github.com — fix(server): links on hosts the server cannot browse no longer re-rea… · pingdotgg/t3code@18d9026
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts +56-1Lines changed: 56 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, | @@ -166,7 +167,7 @@ interface HarnessOptions { | 166 | 167 | readonly snapshot: TestShellSnapshot; | 167 | 168 | readonly summary?: ( | 168 | 169 | input: PullRequestRef, | 169 | | - ) => Effect.Effect<PullRequestSummary, PullRequestOperationError>; | | 170 | + ) => Effect.Effect<PullRequestSummary, PullRequestService.PullRequestError>; | 170 | 171 | readonly stack?: ( | 171 | 172 | input: PullRequestRef, | 172 | 173 | ) => Effect.Effect<PullRequestStack | null, PullRequestOperationError>; | @@ -1519,6 +1520,60 @@ describe("PullRequestSyncReactor", () => { | 1519 | 1520 | ), | 1520 | 1521 | ); | 1521 | 1522 |
| | 1523 | + it.effect("reads a link on a host it cannot browse on the slow cadence", () => | | 1524 | + Effect.scoped( | | 1525 | + Effect.gen(function* () { | | 1526 | + yield* TestClock.setTime(Date.parse(NOW)); | | 1527 | + const fixture = yield* makeHarness({ | | 1528 | + snapshot: makeSnapshot([makeThread("unsupported", { pullRequests: [makeLink(7)] })]), | | 1529 | + summary: (input) => | | 1530 | + input.number === 7 | | 1531 | + ? Effect.fail(new PullRequestUnavailableError({ reason: "provider-unsupported" })) | | 1532 | + : Effect.succeed(makeSummary(input)), | | 1533 | + }); | | 1534 | + const reads = (number: number) => | | 1535 | + Ref.get(fixture.summaryCalls).pipe( | | 1536 | + Effect.map((calls) => calls.filter((call) => call.number === number).length), | | 1537 | + ); | | 1538 | + | | 1539 | + yield* Effect.gen(function* () { | | 1540 | + const reactor = yield* startAndSweep(fixture); | | 1541 | + yield* sweepAgain(fixture, reactor); | | 1542 | + assert.strictEqual(yield* reads(7), 1); | | 1543 | + | | 1544 | + // Only the failing link waits; another link on the same host still reads. | | 1545 | + yield* Ref.set( | | 1546 | + fixture.snapshots, | | 1547 | + makeSnapshot([makeThread("unsupported", { pullRequests: [makeLink(7), makeLink(8)] })]), | | 1548 | + ); | | 1549 | + yield* sweepAgain(fixture, reactor); | | 1550 | + assert.strictEqual(yield* reads(8), 1); | | 1551 | + assert.strictEqual(yield* reads(7), 1); | | 1552 | + | | 1553 | + yield* TestClock.adjust("13 minutes"); | | 1554 | + yield* Queue.take(fixture.snapshotReads); | | 1555 | + yield* reactor.drain; | | 1556 | + assert.strictEqual(yield* reads(7), 2); | | 1557 | + | | 1558 | + // A refresh the user asks for reads through the pause, for example after a sign-in. | | 1559 | + yield* reactor.requestSync({ | | 1560 | + host: "github.com", | | 1561 | + repository: "owner/repository", | | 1562 | + number: 7, | | 1563 | + }); | | 1564 | + yield* Queue.take(fixture.snapshotReads); | | 1565 | + yield* reactor.drain; | | 1566 | + assert.strictEqual(yield* reads(7), 3); | | 1567 | + | | 1568 | + // A failed refresh does not keep bypassing the pause. | | 1569 | + yield* sweepAgain(fixture, reactor); | | 1570 | + yield* sweepAgain(fixture, reactor); | | 1571 | + assert.strictEqual(yield* reads(7), 3); | | 1572 | + }).pipe(Effect.provide(fixture.layer)); | | 1573 | + }), | | 1574 | + ), | | 1575 | + ); | | 1576 | + | 1522 | 1577 | it.effect.each([ | 1523 | 1578 | "gh pr merge 7 --squash 2>&1 | tail -3", | 1524 | 1579 | "cafe pr merge 7 --squash", | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.ts +18-1Lines changed: 18 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | isOrchestrationV2WorkActive, | 4 | 4 | type OrchestrationV2TurnItem, | 5 | 5 | type PullRequestSummary, | | 6 | + PullRequestUnavailableError, | 6 | 7 | type ThreadId, | 7 | 8 | type ThreadPullRequestKey, | 8 | 9 | type ThreadPullRequestLink, | @@ -175,6 +176,7 @@ export function changeRequestsCreatedBy(input: string, output: string) { | 175 | 176 | } | 176 | 177 |
| 177 | 178 | const isPullRequestProviderError = Schema.is(PullRequestProviderError); | | 179 | +const isPullRequestUnavailableError = Schema.is(PullRequestUnavailableError); | 178 | 180 |
| 179 | 181 | type SnapshotFields = Omit<ThreadPullRequestSnapshot, "syncedAt">; | 180 | 182 |
| @@ -316,6 +318,11 @@ function rateLimitRetryAt(cause: Cause.Cause<unknown>): number | undefined { | 316 | 318 | return undefined; | 317 | 319 | } | 318 | 320 |
| | 321 | +function isProviderUnsupported(cause: Cause.Cause<unknown>): boolean { | | 322 | + const error = Cause.squash(cause); | | 323 | + return isPullRequestUnavailableError(error) && error.reason === "provider-unsupported"; | | 324 | +} | | 325 | + | 319 | 326 | function isUnsettled(thread: ProjectionStore.ProjectionThreadPullRequests): boolean { | 320 | 327 | return thread.settledOverride !== "settled" && thread.settledAt === null; | 321 | 328 | } | @@ -348,6 +355,8 @@ export const make = Effect.gen(function* () { | 348 | 355 | const retryStacks = new Set<string>(); | 349 | 356 | // Pause per project and host because credentials are project-specific; leave paused PRs due until reset. | 350 | 357 | const pausedUntil = new Map<string, number>(); | | 358 | + // Links whose host this server cannot browse; only sweeps wait, a requested refresh reads through. | | 359 | + const unsupportedUntil = new Map<string, number>(); | 351 | 360 |
| 352 | 361 | const isDue = (key: string, entries: ReadonlyArray<LinkEntry>, nowMs: number): boolean => { | 353 | 362 | if (requested.has(key) || retryStacks.has(key)) return true; | @@ -404,6 +413,7 @@ export const make = Effect.gen(function* () { | 404 | 413 | for (const key of lastSyncedAt.keys()) if (!groups.has(key)) lastSyncedAt.delete(key); | 405 | 414 | for (const key of retryStacks) if (!groups.has(key)) retryStacks.delete(key); | 406 | 415 | for (const key of requested.keys()) if (!groups.has(key)) requested.delete(key); | | 416 | + for (const key of unsupportedUntil.keys()) if (!groups.has(key)) unsupportedUntil.delete(key); | 407 | 417 |
| 408 | 418 | const linkedThisSweep = new Set<string>(); | 409 | 419 | // Fresh stack reads by group, so a member flagged by a sibling is compared against what the | @@ -582,12 +592,18 @@ export const make = Effect.gen(function* () { | 582 | 592 | const skips = new Map<string, { count: number; readonly key: string }>(); | 583 | 593 | const readGroup = (key: string, entries: ReadonlyArray<LinkEntry>, pauseKey: string) => | 584 | 594 | syncGroup(key, entries).pipe( | | 595 | + Effect.tap(() => Effect.sync(() => unsupportedUntil.delete(key))), | 585 | 596 | Effect.catchCause((cause) => { | 586 | 597 | if (Cause.hasInterruptsOnly(cause)) return Effect.failCause(cause); | 587 | 598 | const retryAt = rateLimitRetryAt(cause); | 588 | 599 | if (retryAt !== undefined) { | 589 | 600 | pausedUntil.set(pauseKey, Math.max(retryAt, pausedUntil.get(pauseKey) ?? 0)); | 590 | 601 | } | | 602 | + if (isProviderUnsupported(cause)) { | | 603 | + unsupportedUntil.set(key, nowMs + SLOW_SYNC_INTERVAL_MS); | | 604 | + // The refresh was answered; keeping it would bypass the pause on every sweep. | | 605 | + requested.delete(key); | | 606 | + } | 591 | 607 | const reason = skipReason(cause); | 592 | 608 | const skip = skips.get(reason); | 593 | 609 | if (skip === undefined) skips.set(reason, { count: 1, key }); | @@ -606,7 +622,8 @@ export const make = Effect.gen(function* () { | 606 | 622 | // Check pauses at each read so changes during the sweep apply immediately. | 607 | 623 | return Clock.currentTimeMillis.pipe( | 608 | 624 | Effect.flatMap((startedAtMs) => | 609 | | - (pausedUntil.get(pauseKey) ?? 0) > startedAtMs | | 625 | + (pausedUntil.get(pauseKey) ?? 0) > startedAtMs || | | 626 | + (!requested.has(key) && (unsupportedUntil.get(key) ?? 0) > startedAtMs) | 610 | 627 | ? Effect.void | 611 | 628 | : readGroup(key, entries, pauseKey), | 612 | 629 | ), | |
|