Skip to content
TypeScript

fix(server): avoid transient GitHub mergeability sync churn (#22022)

Alex Southwellad38be3edc8f
diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
index a0a284b5db5..7739efd021c 100644
--- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
@@ -813,6 +813,81 @@ describe("PullRequestSyncReactor", () => {
),
);
+ it.effect("keeps the known mergeability while the host recomputes it", () =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ yield* TestClock.setTime(Date.parse(NOW));
+ const answers = yield* Ref.make<ReadonlyArray<"unknown" | "mergeable">>([
+ "unknown",
+ "mergeable",
+ ]);
+ const fixture = yield* makeHarness({
+ snapshot: makeSnapshot([
+ makeThread("one", {
+ pullRequests: [makeLink(42, { mergeability: "conflicting" })],
+ }),
+ ]),
+ summary: (input) =>
+ Ref.modify(answers, ([next = "mergeable", ...rest]) => [
+ makeSummary(input, { mergeability: next }),
+ rest,
+ ]),
+ });
+
+ yield* Effect.gen(function* () {
+ const reactor = yield* startAndSweep(fixture);
+ assert.deepStrictEqual(yield* Ref.get(fixture.syncCommands), []);
+
+ // An unchanged old PR uses main's five-minute quiet polling cadence.
+ yield* TestClock.adjust("5 minutes");
+ yield* Queue.take(fixture.snapshotReads);
+ yield* reactor.drain;
+ assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
+
+ const commands = yield* Ref.get(fixture.syncCommands);
+ assert.deepStrictEqual(
+ commands.map((command) => command.snapshot.mergeability),
+ ["mergeable"],
+ );
+ }).pipe(Effect.provide(fixture.layer));
+ }),
+ ),
+ );
+
+ it.effect.each([
+ { provider: "github" as const, updatedAt: "2026-08-28T00:00:00.000Z" },
+ { provider: "forgejo" as const, updatedAt: "2026-08-27T00:00:00.000Z" },
+ ])("persists unknown mergeability for $provider at $updatedAt", ({ provider, updatedAt }) =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ yield* TestClock.setTime(Date.parse(NOW));
+ const fixture = yield* makeHarness({
+ snapshot: makeSnapshot([
+ makeThread("one", {
+ pullRequests: [makeLink(42, { mergeability: "mergeable" })],
+ }),
+ ]),
+ summary: (input) =>
+ Effect.succeed(
+ makeSummary(input, {
+ provider: SourceControlProviderKind.make(provider),
+ updatedAt,
+ mergeability: "unknown",
+ }),
+ ),
+ });
+ yield* Effect.gen(function* () {
+ yield* startAndSweep(fixture);
+ const commands = yield* Ref.get(fixture.syncCommands);
+ assert.deepStrictEqual(
+ commands.map((command) => command.snapshot.mergeability),
+ ["unknown"],
+ );
+ }).pipe(Effect.provide(fixture.layer));
+ }),
+ ),
+ );
+
it.effect("refreshes closed links through each project after reopening elsewhere", () =>
Effect.scoped(
Effect.gen(function* () {
diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
index 2c97b1867ef..2b3605e3a96 100644
--- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
@@ -214,6 +214,23 @@ function snapshotFieldsOf(summary: PullRequestSummary): SnapshotFields {
};
}
+// GitHub briefly returns unknown after base pushes; other hosts may mean a lasting condition.
+function withKnownMergeability(
+ previous: ThreadPullRequestSnapshot | null,
+ fields: SnapshotFields,
+ provider: PullRequestSummary["provider"],
+): SnapshotFields {
+ if (
+ provider !== "github" ||
+ fields.state !== "open" ||
+ fields.mergeability !== "unknown" ||
+ previous?.updatedAt !== fields.updatedAt
+ )
+ return fields;
+ const known = previous?.state === "open" ? previous.mergeability : undefined;
+ return known === undefined || known === "unknown" ? fields : { ...fields, mergeability: known };
+}
+
// Rotating ghe.com avatar tokens should not make otherwise identical snapshots differ.
function avatarIdentity(avatarUrl: string | null | undefined): string | null {
if (avatarUrl === null || avatarUrl === undefined) return null;
@@ -396,10 +413,12 @@ export const make = Effect.gen(function* () {
// cache lookup forked inside keeps those frames, so a plain span leaves the sweep collectable.
const syncEntry = Effect.fnUntraced(function* (
entry: LinkEntry,
- fields: SnapshotFields,
+ hostFields: SnapshotFields,
fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null,
+ provider: PullRequestSummary["provider"],
) {
const { thread, link } = entry;
+ const fields = withKnownMergeability(link.snapshot, hostFields, provider);
const nextStack = fetchedStack === null ? link.stack : fetchedStack.stack;
const changed =
link.snapshot === null ||
@@ -475,7 +494,10 @@ export const make = Effect.gen(function* () {
entries.some(
(entry) =>
entry.link.snapshot === null ||
- !snapshotFieldsEqual(entry.link.snapshot, fields) ||
+ !snapshotFieldsEqual(
+ entry.link.snapshot,
+ withKnownMergeability(entry.link.snapshot, fields, summary.provider),
+ ) ||
(summary.stack !== undefined &&
(entry.link.stack?.number ?? null) !== (summary.stack?.number ?? null)),
);
@@ -542,7 +564,7 @@ export const make = Effect.gen(function* () {
yield* Effect.forEach(
entries,
(entry) =>
- syncEntry(entry, fields, fetchedStack).pipe(
+ syncEntry(entry, fields, fetchedStack, summary.provider).pipe(
persistence.withPermits(1),
Effect.catchCause((cause) => {
if (!Cause.hasInterruptsOnly(cause)) retryStacks.add(key);