GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): PR sync stops reading missing pull requests every minute · chickenputty/t3code@4c39cac

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • PullRequestSyncReactor.test.ts
    • PullRequestSyncReactor.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+180-4Lines changed: 180 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import * as ServerActivation from "../serverActivation.ts";
3838
import * as Orchestrator from "./Orchestrator.ts";
3939
import * as ProjectionStore from "./ProjectionStore.ts";
4040
import * as PullRequestSyncReactor from "./PullRequestSyncReactor.ts";
41-
import type { PullRequestTestThread } from "./testkit/pullRequestFixtures.ts";
41+
import { type PullRequestTestThread, v2PullRequestThread } from "./testkit/pullRequestFixtures.ts";
4242

4343
const NOW = "2026-08-28T12:00:00.000Z";
4444
const PROJECT_ID = ProjectId.make("sync-project");
@@ -162,6 +162,17 @@ function makeSummary(
162162
};
163163
}
164164

165+
/** How a host answers for a pull request it cannot find, such as one in a deleted repository. */
166+
function notFound(input: PullRequestRef) {
167+
return Effect.fail(
168+
new PullRequestOperationError({
169+
operation: "summary",
170+
detail: `GitHub could not find ${input.repository}#${input.number}.`,
171+
reason: "not-found",
172+
}),
173+
);
174+
}
175+
165176
interface HarnessOptions {
166177
readonly invalidate?: PullRequestService.PullRequestService["Service"]["invalidate"];
167178
readonly snapshot: TestShellSnapshot;
@@ -364,6 +375,16 @@ function commandRan(threadId: ThreadId, input: string): OrchestrationV2DomainEve
364375
};
365376
}
366377

378+
function pullRequestsSynced(thread: PullRequestTestThread): OrchestrationV2DomainEvent {
379+
return {
380+
type: "thread.pull-request-synced",
381+
id: EventId.make(`event:${thread.id}:pull-requests`),
382+
threadId: thread.id,
383+
occurredAt: DateTime.makeUnsafe(NOW),
384+
payload: { ...v2PullRequestThread(thread), lastVisitedAt: null },
385+
};
386+
}
387+
367388
/** What the reactor would have persisted, so the next sweep sees its own writes. */
368389
function applySync(
369390
snapshot: TestShellSnapshot,
@@ -921,7 +942,11 @@ describe("PullRequestSyncReactor", () => {
921942
makeThread("settled", {
922943
settledOverride: "settled",
923944
settledAt: "2026-08-21T00:00:00.000Z",
924-
pullRequests: [makeLink(5, { state: "open" }), makeLink(6, { state: "closed" })],
945+
pullRequests: [
946+
makeLink(5, { state: "open" }),
947+
makeLink(6, { state: "closed" }),
948+
makeLink(7),
949+
],
925950
}),
926951
]),
927952
});
@@ -942,7 +967,7 @@ describe("PullRequestSyncReactor", () => {
942967
yield* sweepAgain(fixture, reactor);
943968
assert.deepStrictEqual(
944969
(yield* Ref.get(fixture.summaryCalls)).map((call) => call.number).toSorted(),
945-
[5, 6],
970+
[5, 6, 7],
946971
);
947972
}).pipe(Effect.provide(fixture.layer));
948973
}),
@@ -1029,12 +1054,163 @@ describe("PullRequestSyncReactor", () => {
10291054
});
10301055

10311056
yield* Effect.gen(function* () {
1032-
yield* startAndSweep(fixture);
1057+
const reactor = yield* startAndSweep(fixture);
10331058

10341059
assert.deepStrictEqual(
10351060
(yield* Ref.get(fixture.syncCommands)).map((command) => command.number),
10361061
[8],
10371062
);
1063+
yield* sweepAgain(fixture, reactor);
1064+
assert.strictEqual(
1065+
(yield* Ref.get(fixture.summaryCalls)).filter((call) => call.number === 7).length,
1066+
2,
1067+
);
1068+
}).pipe(Effect.provide(fixture.layer));
1069+
}),
1070+
),
1071+
);
1072+
1073+
it.effect(
1074+
"asks every fifteen minutes for pull requests the host cannot find, until it finds them",
1075+
() =>
1076+
Effect.scoped(
1077+
Effect.gen(function* () {
1078+
yield* TestClock.setTime(Date.parse(NOW));
1079+
const found = yield* Ref.make(false);
1080+
const fixture = yield* makeHarness({
1081+
snapshot: makeSnapshot([
1082+
makeThread("renamed", {
1083+
pullRequests: [makeLink(9), makeLink(10, { state: "open" })],
1084+
}),
1085+
]),
1086+
summary: (input) =>
1087+
Ref.get(found).pipe(
1088+
Effect.flatMap((isFound) =>
1089+
isFound ? Effect.succeed(makeSummary(input)) : notFound(input),
1090+
),
1091+
),
1092+
});
1093+
1094+
yield* Effect.gen(function* () {
1095+
const reactor = yield* startAndSweep(fixture);
1096+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
1097+
for (let index = 0; index < 14; index += 1) yield* sweepAgain(fixture, reactor);
1098+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
1099+
1100+
// The repository is back, so its open pull requests return to the open cadence.
1101+
yield* Ref.set(found, true);
1102+
yield* sweepAgain(fixture, reactor);
1103+
assert.deepStrictEqual(
1104+
(yield* Ref.get(fixture.summaryCalls))
1105+
.map((call) => call.number)
1106+
.toSorted((left, right) => left - right),
1107+
[9, 9, 10, 10],
1108+
);
1109+
const commands = yield* Ref.get(fixture.syncCommands);
1110+
yield* Ref.update(fixture.snapshots, (snapshot) => applySync(snapshot, commands));
1111+
// Fork: the thread is idle, so its open pull requests wait out the ten minute pace.
1112+
yield* sweepAgain(fixture, reactor);
1113+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 4);
1114+
}).pipe(Effect.provide(fixture.layer));
1115+
}),
1116+
),
1117+
);
1118+
1119+
it.effect("keeps the slow cadence for a missing pull request whose stack read failed", () =>
1120+
Effect.scoped(
1121+
Effect.gen(function* () {
1122+
yield* TestClock.setTime(Date.parse(NOW));
1123+
const found = yield* Ref.make(true);
1124+
const fixture = yield* makeHarness({
1125+
snapshot: makeSnapshot([makeThread("renamed", { pullRequests: [makeLink(4)] })]),
1126+
summary: (input) =>
1127+
Ref.get(found).pipe(
1128+
Effect.flatMap((isFound) =>
1129+
isFound ? Effect.succeed(makeSummary(input)) : notFound(input),
1130+
),
1131+
),
1132+
stack: () =>
1133+
Effect.fail(new PullRequestOperationError({ operation: "stack", detail: "host down" })),
1134+
});
1135+
1136+
yield* Effect.gen(function* () {
1137+
const reactor = yield* startAndSweep(fixture);
1138+
// The next sweep retries the failed stack read, and finds the repository gone.
1139+
yield* Ref.set(found, false);
1140+
for (let index = 0; index < 15; index += 1) yield* sweepAgain(fixture, reactor);
1141+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
1142+
}).pipe(Effect.provide(fixture.layer));
1143+
}),
1144+
),
1145+
);
1146+
1147+
it.effect("stops asking for a requested pull request once the host cannot find it", () =>
1148+
Effect.scoped(
1149+
Effect.gen(function* () {
1150+
yield* TestClock.setTime(Date.parse(NOW));
1151+
const fixture = yield* makeHarness({
1152+
snapshot: makeSnapshot([
1153+
makeThread("settled", {
1154+
settledOverride: "settled",
1155+
settledAt: "2026-08-21T00:00:00.000Z",
1156+
pullRequests: [makeLink(5, { state: "open" })],
1157+
}),
1158+
]),
1159+
summary: notFound,
1160+
});
1161+
1162+
yield* Effect.gen(function* () {
1163+
const reactor = yield* startAndSweep(fixture);
1164+
yield* Queue.offer(fixture.stateChanges, {
1165+
host: "github.com",
1166+
repository: "owner/repository",
1167+
number: 5,
1168+
});
1169+
yield* Queue.take(fixture.snapshotReads);
1170+
yield* reactor.drain;
1171+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
1172+
1173+
for (let index = 0; index < 15; index += 1) yield* sweepAgain(fixture, reactor);
1174+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
1175+
}).pipe(Effect.provide(fixture.layer));
1176+
}),
1177+
),
1178+
);
1179+
1180+
it.effect("reads a missing pull request again for a reader, not for another link's sync", () =>
1181+
Effect.scoped(
1182+
Effect.gen(function* () {
1183+
yield* TestClock.setTime(Date.parse(NOW));
1184+
const fixture = yield* makeHarness({
1185+
snapshot: makeSnapshot([makeThread("renamed", { pullRequests: [makeLink(9)] })]),
1186+
summary: (input) =>
1187+
input.number === 9 ? notFound(input) : Effect.succeed(makeSummary(input)),
1188+
});
1189+
1190+
yield* Effect.gen(function* () {
1191+
const reactor = yield* startAndSweep(fixture);
1192+
// Linking another pull request syncs the thread's links, the unreadable one included.
1193+
const linked = makeThread("renamed", { pullRequests: [makeLink(9), makeLink(8)] });
1194+
yield* Ref.set(fixture.snapshots, makeSnapshot([linked], 2));
1195+
yield* Queue.offer(fixture.domainEvents, pullRequestsSynced(linked));
1196+
yield* Queue.take(fixture.snapshotReads);
1197+
yield* reactor.drain;
1198+
assert.deepStrictEqual(
1199+
(yield* Ref.get(fixture.summaryCalls)).map((call) => call.number),
1200+
[9, 8],
1201+
);
1202+
1203+
yield* Queue.offer(fixture.stateChanges, {
1204+
host: "github.com",
1205+
repository: "owner/repository",
1206+
number: 9,
1207+
});
1208+
yield* Queue.take(fixture.snapshotReads);
1209+
yield* reactor.drain;
1210+
assert.deepStrictEqual(
1211+
(yield* Ref.get(fixture.summaryCalls)).map((call) => call.number),
1212+
[9, 8, 9],
1213+
);
10381214
}).pipe(Effect.provide(fixture.layer));
10391215
}),
10401216
),
Collapse file

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+27-8Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,25 @@ export const make = Effect.gen(function* () {
173173
// linking dozens of pull requests) is read together and shares the summary batches.
174174
let requestedSweepQueued = false;
175175
const retryStacks = new Set<string>();
176+
// Pull requests the host last answered it cannot find, such as one in a deleted repository.
177+
const missing = new Set<string>();
176178
// Rate limit pauses by project and host, since each project reads with its own credential.
177179
// A paused host refuses every read without asking it, so the sweep leaves its pull requests
178180
// due until the pause ends rather than failing each of them every minute.
179181
const pausedUntil = new Map<string, number>();
180182

181183
const isDue = (key: string, entries: ReadonlyArray<LinkEntry>, nowMs: number): boolean => {
182-
if (requested.has(key) || retryStacks.has(key)) return true;
183-
if (entries.some((entry) => entry.link.snapshot === null)) return true;
184+
if (requested.has(key) || (retryStacks.has(key) && !missing.has(key))) return true;
184185
// Settled threads stop watching their pull requests. Unsettling one makes its links due on
185186
// the next sweep, since the cadence clock below kept running while it was settled.
186187
const active = entries.filter((entry) => isUnsettled(entry.thread));
187-
if (active.every((entry) => entry.link.snapshot?.state === "merged")) return false;
188+
if (active.length === 0) return false;
189+
// Closed requests can reopen on the host, and a missing one can come back.
188190
const last = lastSyncedAt.get(key);
191+
const slowDue = last === undefined || nowMs - last >= SLOW_SYNC_INTERVAL_MS;
192+
if (missing.has(key)) return slowDue;
193+
if (active.some((entry) => entry.link.snapshot === null)) return true;
194+
if (active.every((entry) => entry.link.snapshot?.state === "merged")) return false;
189195
const open = active.filter((entry) => entry.link.snapshot?.state === "open");
190196
if (
191197
open.some(
@@ -196,9 +202,8 @@ export const make = Effect.gen(function* () {
196202
) {
197203
return true;
198204
}
199-
// Closed requests can reopen on the host.
200-
const interval = open.length > 0 ? IDLE_SYNC_INTERVAL_MS : SLOW_SYNC_INTERVAL_MS;
201-
return last === undefined || nowMs - last >= interval;
205+
if (open.length === 0) return slowDue;
206+
return last === undefined || nowMs - last >= IDLE_SYNC_INTERVAL_MS;
202207
};
203208

204209
const logSkipped =
@@ -225,6 +230,7 @@ export const make = Effect.gen(function* () {
225230

226231
for (const key of lastSyncedAt.keys()) if (!groups.has(key)) lastSyncedAt.delete(key);
227232
for (const key of retryStacks) if (!groups.has(key)) retryStacks.delete(key);
233+
for (const key of missing) if (!groups.has(key)) missing.delete(key);
228234
for (const key of requested.keys()) if (!groups.has(key)) requested.delete(key);
229235

230236
// Layers auto-linked this sweep, so two links of one thread that share a
@@ -303,7 +309,19 @@ export const make = Effect.gen(function* () {
303309
};
304310
const generation = requested.get(key);
305311
if (generation !== undefined) yield* pullRequests.invalidate({ reference: ref });
306-
const summary = yield* pullRequests.summary(ref, { recoverTransientFailure: false });
312+
const summary = yield* pullRequests.summary(ref, { recoverTransientFailure: false }).pipe(
313+
Effect.tapError((error) =>
314+
error._tag === "PullRequestOperationError" && error.reason === "not-found"
315+
? // The host answered, so the request is done and the cadence clock ticks.
316+
Effect.sync(() => {
317+
missing.add(key);
318+
lastSyncedAt.set(key, nowMs);
319+
if (requested.get(key) === generation) requested.delete(key);
320+
})
321+
: Effect.void,
322+
),
323+
);
324+
missing.delete(key);
307325
const fields = snapshotFieldsOf(summary);
308326
const needsStack =
309327
generation !== undefined ||
@@ -457,10 +475,11 @@ export const make = Effect.gen(function* () {
457475
yield* forkParked(
458476
Stream.runForEach(events, (event) => {
459477
switch (event.type) {
478+
// Another link's sync is no reason to ask again for one the host cannot find.
460479
case "thread.pull-request-synced":
461480
return Effect.forEach(
462481
visibleThreadPullRequests(event.payload.pullRequests ?? []).filter(
463-
(link) => link.snapshot === null,
482+
(link) => link.snapshot === null && !missing.has(threadPullRequestKeyOf(link)),
464483
),
465484
requestSync,
466485
{ discard: true },

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.