Skip to content

Commit b597b18

Browse files
perf(server): read quiet pull requests every five minutes
Every server re-read every open linked pull request on each one-minute sweep, and most of them sit untouched for days. An open pull request nobody has updated for 30 minutes is now read every five minutes; requested refreshes, watches and `gh pr merge` still read it at once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1154190 commit b597b18

2 files changed

Lines changed: 54 additions & 5 deletions

File tree

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ describe("PullRequestSyncReactor", () => {
643643
yield* TestClock.setTime(Date.parse(NOW));
644644
const fixture = yield* makeHarness({
645645
snapshot: makeSnapshot([makeThread("one", { pullRequests: [makeLink(42)] })]),
646+
summary: (input) => Effect.succeed(makeSummary(input, { updatedAt: NOW })),
646647
});
647648

648649
yield* Effect.gen(function* () {
@@ -855,6 +856,39 @@ describe("PullRequestSyncReactor", () => {
855856
),
856857
);
857858

859+
it.effect("reads a quiet open pull request every five minutes until it changes", () =>
860+
Effect.scoped(
861+
Effect.gen(function* () {
862+
yield* TestClock.setTime(Date.parse(NOW));
863+
const updatedAt = yield* Ref.make("2026-08-27T00:00:00.000Z");
864+
const fixture = yield* makeHarness({
865+
snapshot: makeSnapshot([makeThread("quiet", { pullRequests: [makeLink(5)] })]),
866+
summary: (input) =>
867+
Ref.get(updatedAt).pipe(Effect.map((updatedAt) => makeSummary(input, { updatedAt }))),
868+
});
869+
yield* Effect.gen(function* () {
870+
const reactor = yield* startAndSweep(fixture);
871+
const applySyncs = Effect.flatMap(Ref.get(fixture.syncCommands), (commands) =>
872+
Ref.update(fixture.snapshots, (snapshot) => applySync(snapshot, commands)),
873+
);
874+
yield* applySyncs;
875+
const reads = Ref.get(fixture.summaryCalls).pipe(Effect.map((calls) => calls.length));
876+
assert.strictEqual(yield* reads, 1);
877+
for (let index = 0; index < 4; index += 1) yield* sweepAgain(fixture, reactor);
878+
assert.strictEqual(yield* reads, 1);
879+
880+
// Someone comments: the five-minute read sees it, and the next sweep reads it again.
881+
yield* Ref.set(updatedAt, "2026-08-28T12:04:00.000Z");
882+
yield* sweepAgain(fixture, reactor);
883+
assert.strictEqual(yield* reads, 2);
884+
yield* applySyncs;
885+
yield* sweepAgain(fixture, reactor);
886+
assert.strictEqual(yield* reads, 3);
887+
}).pipe(Effect.provide(fixture.layer));
888+
}),
889+
),
890+
);
891+
858892
it.effect("preserves a refresh requested while an older host read is in flight", () =>
859893
Effect.scoped(
860894
Effect.gen(function* () {
@@ -1116,13 +1150,15 @@ describe("PullRequestSyncReactor", () => {
11161150
yield* TestClock.setTime(Date.parse(NOW));
11171151
const fixture = yield* makeHarness({
11181152
snapshot: makeSnapshot([
1119-
makeThread("first", { pullRequests: [makeLink(7, { state: "open" })] }),
1120-
makeThread("second", { pullRequests: [makeLink(8, { state: "open" })] }),
1153+
makeThread("first", { pullRequests: [makeLink(7, { state: "open", updatedAt: NOW })] }),
1154+
makeThread("second", {
1155+
pullRequests: [makeLink(8, { state: "open", updatedAt: NOW })],
1156+
}),
11211157
makeThread("third", {
11221158
pullRequests: [
11231159
makeLink(
11241160
9,
1125-
{ state: "open" },
1161+
{ state: "open", updatedAt: NOW },
11261162
{ host: "forge.example", url: "https://forge.example/owner/repository/pulls/9" },
11271163
),
11281164
],

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ import * as ProjectionStore from "./ProjectionStore.ts";
3737
import { isTerminalRunStatus } from "./ThreadManagementService.ts";
3838

3939
const SLOW_SYNC_INTERVAL_MS = 15 * 60 * 1_000;
40+
// Every server polls every open linked pull request, and most of them sit untouched for days.
41+
// One nobody has updated for QUIET_AFTER_MS is read on the quiet cadence instead of each sweep;
42+
// requested refreshes, watches and `gh pr merge` still read it at once.
43+
const QUIET_AFTER_MS = 30 * 60 * 1_000;
44+
const QUIET_SYNC_INTERVAL_MS = 5 * 60 * 1_000;
4045
const PULL_REQUEST_CLOSE_COMMAND = /\b(?:gh\s+pr|glab\s+mr)\s+(?:merge|close)\b/u;
4146

4247
const isPullRequestProviderError = Schema.is(PullRequestProviderError);
@@ -177,9 +182,17 @@ export const make = Effect.gen(function* () {
177182
) {
178183
return false;
179184
}
180-
if (active.some((entry) => entry.link.snapshot?.state === "open")) return true;
181185
const last = lastSyncedAt.get(key);
182-
return last === undefined || nowMs - last >= SLOW_SYNC_INTERVAL_MS;
186+
const sinceLastMs = last === undefined ? Number.POSITIVE_INFINITY : nowMs - last;
187+
const open = active.filter((entry) => entry.link.snapshot?.state === "open");
188+
if (open.length > 0) {
189+
const quiet = open.every((entry) => {
190+
const updatedAt = entry.link.snapshot?.updatedAt;
191+
return updatedAt != null && nowMs - Date.parse(updatedAt) >= QUIET_AFTER_MS;
192+
});
193+
return !quiet || sinceLastMs >= QUIET_SYNC_INTERVAL_MS;
194+
}
195+
return sinceLastMs >= SLOW_SYNC_INTERVAL_MS;
183196
};
184197

185198
const logSkipped =

0 commit comments

Comments
 (0)