@devries-cameron20 / t3code Mirror · read-only / commits / 8dec2ffef9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 00:30 UTC

perf(server): read quiet pull requests every five minutes (#22073)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 19, 2026 at 19:36 UTC 8dec2ffef970979613f63f6b68cf3219729ef895
2 files changed +54 -5
apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+39 -3
@@ -643,6 +643,7 @@ describe("PullRequestSyncReactor", () => {
643 yield* TestClock.setTime(Date.parse(NOW));
644 const fixture = yield* makeHarness({
645 snapshot: makeSnapshot([makeThread("one", { pullRequests: [makeLink(42)] })]),
646 + summary: (input) => Effect.succeed(makeSummary(input, { updatedAt: NOW })),
647 });
648
649 yield* Effect.gen(function* () {
@@ -855,6 +856,39 @@ describe("PullRequestSyncReactor", () => {
856 ),
857 );
858
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 +
892 it.effect("preserves a refresh requested while an older host read is in flight", () =>
893 Effect.scoped(
894 Effect.gen(function* () {
@@ -1116,13 +1150,15 @@ describe("PullRequestSyncReactor", () => {
1150 yield* TestClock.setTime(Date.parse(NOW));
1151 const fixture = yield* makeHarness({
1152 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 + }),
1157 makeThread("third", {
1158 pullRequests: [
1159 makeLink(
1160 9,
1125 - { state: "open" },
1161 + { state: "open", updatedAt: NOW },
1162 { host: "forge.example", url: "https://forge.example/owner/repository/pulls/9" },
1163 ),
1164 ],
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+15 -2
@@ -37,6 +37,11 @@ import * as ProjectionStore from "./ProjectionStore.ts";
37 import { isTerminalRunStatus } from "./ThreadManagementService.ts";
38
39 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;
45 const PULL_REQUEST_CLOSE_COMMAND = /\b(?:gh\s+pr|glab\s+mr)\s+(?:merge|close)\b/u;
46
47 const isPullRequestProviderError = Schema.is(PullRequestProviderError);
@@ -177,9 +182,17 @@ export const make = Effect.gen(function* () {
182 ) {
183 return false;
184 }
180 - if (active.some((entry) => entry.link.snapshot?.state === "open")) return true;
185 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;
196 };
197
198 const logSkipped =