The best way to control Claude Code, Codex and more from any computer or phone
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 <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com>
Alex Southwell committed
Nov 1, 2026 at 20:53 UTC
ad38be3edc8f980d578b863eeac24075199e01c7
2 files changed
+100
-3
apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+75
@@ -813,6 +813,81 @@ describe("PullRequestSyncReactor", () => {
813
),
814
);
815
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
+
891
it.effect("refreshes closed links through each project after reopening elsewhere", () =>
892
Effect.scoped(
893
Effect.gen(function* () {
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+25
-3
@@ -214,6 +214,23 @@ function snapshotFieldsOf(summary: PullRequestSummary): SnapshotFields {
214
};
215
}
216
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
+
234
// Rotating ghe.com avatar tokens should not make otherwise identical snapshots differ.
235
function avatarIdentity(avatarUrl: string | null | undefined): string | null {
236
if (avatarUrl === null || avatarUrl === undefined) return null;
@@ -396,10 +413,12 @@ export const make = Effect.gen(function* () {
413
// cache lookup forked inside keeps those frames, so a plain span leaves the sweep collectable.
414
const syncEntry = Effect.fnUntraced(function* (
415
entry: LinkEntry,
399
- fields: SnapshotFields,
416
+ hostFields: SnapshotFields,
417
fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null,
418
+ provider: PullRequestSummary["provider"],
419
) {
420
const { thread, link } = entry;
421
+ const fields = withKnownMergeability(link.snapshot, hostFields, provider);
422
const nextStack = fetchedStack === null ? link.stack : fetchedStack.stack;
423
const changed =
424
link.snapshot === null ||
@@ -475,7 +494,10 @@ export const make = Effect.gen(function* () {
494
entries.some(
495
(entry) =>
496
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
+ ) ||
501
(summary.stack !== undefined &&
502
(entry.link.stack?.number ?? null) !== (summary.stack?.number ?? null)),
503
);
@@ -542,7 +564,7 @@ export const make = Effect.gen(function* () {
564
yield* Effect.forEach(
565
entries,
566
(entry) =>
545
- syncEntry(entry, fields, fetchedStack).pipe(
567
+ syncEntry(entry, fields, fetchedStack, summary.provider).pipe(
568
persistence.withPermits(1),
569
Effect.catchCause((cause) => {
570
if (!Cause.hasInterruptsOnly(cause)) retryStacks.add(key);