Skip to content

Commit ad38be3

Browse files
saphidgithub-actions[bot]claude
authored
fix(server): avoid transient GitHub mergeability sync churn (#22022)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: SAPHID <[email protected]>
1 parent 3f105e0 commit ad38be3

2 files changed

Lines changed: 100 additions & 3 deletions

File tree

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,81 @@ describe("PullRequestSyncReactor", () => {
813813
),
814814
);
815815

816+
it.effect("keeps the known mergeability while the host recomputes it", () =>
817+
Effect.scoped(
818+
Effect.gen(function* () {
819+
yield* TestClock.setTime(Date.parse(NOW));
820+
const answers = yield* Ref.make<ReadonlyArray<"unknown" | "mergeable">>([
821+
"unknown",
822+
"mergeable",
823+
]);
824+
const fixture = yield* makeHarness({
825+
snapshot: makeSnapshot([
826+
makeThread("one", {
827+
pullRequests: [makeLink(42, { mergeability: "conflicting" })],
828+
}),
829+
]),
830+
summary: (input) =>
831+
Ref.modify(answers, ([next = "mergeable", ...rest]) => [
832+
makeSummary(input, { mergeability: next }),
833+
rest,
834+
]),
835+
});
836+
837+
yield* Effect.gen(function* () {
838+
const reactor = yield* startAndSweep(fixture);
839+
assert.deepStrictEqual(yield* Ref.get(fixture.syncCommands), []);
840+
841+
// An unchanged old PR uses main's five-minute quiet polling cadence.
842+
yield* TestClock.adjust("5 minutes");
843+
yield* Queue.take(fixture.snapshotReads);
844+
yield* reactor.drain;
845+
assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
846+
847+
const commands = yield* Ref.get(fixture.syncCommands);
848+
assert.deepStrictEqual(
849+
commands.map((command) => command.snapshot.mergeability),
850+
["mergeable"],
851+
);
852+
}).pipe(Effect.provide(fixture.layer));
853+
}),
854+
),
855+
);
856+
857+
it.effect.each([
858+
{ provider: "github" as const, updatedAt: "2026-08-28T00:00:00.000Z" },
859+
{ provider: "forgejo" as const, updatedAt: "2026-08-27T00:00:00.000Z" },
860+
])("persists unknown mergeability for $provider at $updatedAt", ({ provider, updatedAt }) =>
861+
Effect.scoped(
862+
Effect.gen(function* () {
863+
yield* TestClock.setTime(Date.parse(NOW));
864+
const fixture = yield* makeHarness({
865+
snapshot: makeSnapshot([
866+
makeThread("one", {
867+
pullRequests: [makeLink(42, { mergeability: "mergeable" })],
868+
}),
869+
]),
870+
summary: (input) =>
871+
Effect.succeed(
872+
makeSummary(input, {
873+
provider: SourceControlProviderKind.make(provider),
874+
updatedAt,
875+
mergeability: "unknown",
876+
}),
877+
),
878+
});
879+
yield* Effect.gen(function* () {
880+
yield* startAndSweep(fixture);
881+
const commands = yield* Ref.get(fixture.syncCommands);
882+
assert.deepStrictEqual(
883+
commands.map((command) => command.snapshot.mergeability),
884+
["unknown"],
885+
);
886+
}).pipe(Effect.provide(fixture.layer));
887+
}),
888+
),
889+
);
890+
816891
it.effect("refreshes closed links through each project after reopening elsewhere", () =>
817892
Effect.scoped(
818893
Effect.gen(function* () {

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ function snapshotFieldsOf(summary: PullRequestSummary): SnapshotFields {
214214
};
215215
}
216216

217+
// GitHub briefly returns unknown after base pushes; other hosts may mean a lasting condition.
218+
function withKnownMergeability(
219+
previous: ThreadPullRequestSnapshot | null,
220+
fields: SnapshotFields,
221+
provider: PullRequestSummary["provider"],
222+
): SnapshotFields {
223+
if (
224+
provider !== "github" ||
225+
fields.state !== "open" ||
226+
fields.mergeability !== "unknown" ||
227+
previous?.updatedAt !== fields.updatedAt
228+
)
229+
return fields;
230+
const known = previous?.state === "open" ? previous.mergeability : undefined;
231+
return known === undefined || known === "unknown" ? fields : { ...fields, mergeability: known };
232+
}
233+
217234
// Rotating ghe.com avatar tokens should not make otherwise identical snapshots differ.
218235
function avatarIdentity(avatarUrl: string | null | undefined): string | null {
219236
if (avatarUrl === null || avatarUrl === undefined) return null;
@@ -396,10 +413,12 @@ export const make = Effect.gen(function* () {
396413
// cache lookup forked inside keeps those frames, so a plain span leaves the sweep collectable.
397414
const syncEntry = Effect.fnUntraced(function* (
398415
entry: LinkEntry,
399-
fields: SnapshotFields,
416+
hostFields: SnapshotFields,
400417
fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null,
418+
provider: PullRequestSummary["provider"],
401419
) {
402420
const { thread, link } = entry;
421+
const fields = withKnownMergeability(link.snapshot, hostFields, provider);
403422
const nextStack = fetchedStack === null ? link.stack : fetchedStack.stack;
404423
const changed =
405424
link.snapshot === null ||
@@ -475,7 +494,10 @@ export const make = Effect.gen(function* () {
475494
entries.some(
476495
(entry) =>
477496
entry.link.snapshot === null ||
478-
!snapshotFieldsEqual(entry.link.snapshot, fields) ||
497+
!snapshotFieldsEqual(
498+
entry.link.snapshot,
499+
withKnownMergeability(entry.link.snapshot, fields, summary.provider),
500+
) ||
479501
(summary.stack !== undefined &&
480502
(entry.link.stack?.number ?? null) !== (summary.stack?.number ?? null)),
481503
);
@@ -542,7 +564,7 @@ export const make = Effect.gen(function* () {
542564
yield* Effect.forEach(
543565
entries,
544566
(entry) =>
545-
syncEntry(entry, fields, fetchedStack).pipe(
567+
syncEntry(entry, fields, fetchedStack, summary.provider).pipe(
546568
persistence.withPermits(1),
547569
Effect.catchCause((cause) => {
548570
if (!Cause.hasInterruptsOnly(cause)) retryStacks.add(key);

0 commit comments

Comments
 (0)