Skip to content

Commit ece2bad

Browse files
fix(server): a transient unknown mergeability no longer overwrites a known one
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 087d860 commit ece2bad

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,37 @@ describe("PullRequestSyncReactor", () => {
787787
),
788788
);
789789

790+
it.effect("persists other changes read with unknown mergeability under the known one", () =>
791+
Effect.scoped(
792+
Effect.gen(function* () {
793+
yield* TestClock.setTime(Date.parse(NOW));
794+
const fixture = yield* makeHarness({
795+
snapshot: makeSnapshot([
796+
makeThread("one", {
797+
pullRequests: [makeLink(42, { updatedAt: NOW, mergeability: "conflicting" })],
798+
}),
799+
]),
800+
summary: (input) =>
801+
Effect.succeed(
802+
makeSummary(input, { updatedAt: NOW, title: "Renamed", mergeability: "unknown" }),
803+
),
804+
});
805+
806+
yield* Effect.gen(function* () {
807+
yield* startAndSweep(fixture);
808+
809+
assert.deepStrictEqual(
810+
(yield* Ref.get(fixture.syncCommands)).map(({ snapshot }) => [
811+
snapshot.title,
812+
snapshot.mergeability,
813+
]),
814+
[["Renamed", "conflicting"]],
815+
);
816+
}).pipe(Effect.provide(fixture.layer));
817+
}),
818+
),
819+
);
820+
790821
it.effect("refreshes closed links through each project after reopening elsewhere", () =>
791822
Effect.scoped(
792823
Effect.gen(function* () {

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ function snapshotFieldsOf(summary: PullRequestSummary): SnapshotFields {
7373
};
7474
}
7575

76+
// Hosts compute mergeability lazily and answer unknown while recomputing, so a fresh read must
77+
// not erase a known answer.
78+
function retainKnownMergeability(
79+
fields: SnapshotFields,
80+
previous: ThreadPullRequestSnapshot | null,
81+
): SnapshotFields {
82+
if (fields.mergeability !== "unknown") return fields;
83+
const known = previous?.mergeability;
84+
return known === undefined || known === "unknown" ? fields : { ...fields, mergeability: known };
85+
}
86+
7687
// Rotating ghe.com avatar tokens should not make otherwise identical snapshots differ.
7788
function avatarIdentity(avatarUrl: string | null | undefined): string | null {
7889
if (avatarUrl === null || avatarUrl === undefined) return null;
@@ -259,10 +270,11 @@ export const make = Effect.gen(function* () {
259270

260271
const syncEntry = Effect.fn("PullRequestSyncReactor.syncEntry")(function* (
261272
entry: LinkEntry,
262-
fields: SnapshotFields,
273+
readFields: SnapshotFields,
263274
fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null,
264275
) {
265276
const { thread, link } = entry;
277+
const fields = retainKnownMergeability(readFields, link.snapshot);
266278
const nextStack = fetchedStack === null ? link.stack : fetchedStack.stack;
267279
const changed =
268280
link.snapshot === null ||
@@ -343,7 +355,10 @@ export const make = Effect.gen(function* () {
343355
entries.some(
344356
(entry) =>
345357
entry.link.snapshot === null ||
346-
!snapshotFieldsEqual(entry.link.snapshot, fields) ||
358+
!snapshotFieldsEqual(
359+
entry.link.snapshot,
360+
retainKnownMergeability(fields, entry.link.snapshot),
361+
) ||
347362
(summary.stack !== undefined &&
348363
(entry.link.stack?.number ?? null) !== (summary.stack?.number ?? null)),
349364
);

0 commit comments

Comments
 (0)