Skip to content

Commit 9b8ebd0

Browse files
committed
fix(server): busy PR watches still reread their detail every 2 hours
1 parent 5582155 commit 9b8ebd0

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ interface WatchGroup {
9191

9292
interface LastRead {
9393
readonly at: number;
94+
readonly detailAt: number;
9495
readonly checkedAt: number;
9596
readonly fingerprint: string;
9697
readonly inFlight: boolean;
@@ -186,7 +187,8 @@ function planRead(
186187
}
187188

188189
const notificationsCanGate = (last: LastRead, now: number) =>
189-
now - last.checkedAt >= FINGERPRINT_REREAD_MS && now - last.at < NOTIFIED_REREAD_CEILING_MS;
190+
now - last.checkedAt >= FINGERPRINT_REREAD_MS &&
191+
now - Math.min(last.at, last.detailAt) < NOTIFIED_REREAD_CEILING_MS;
190192

191193
const gatesReread = (
192194
group: WatchGroup,
@@ -594,6 +596,7 @@ export const make = Effect.gen(function* () {
594596
: last.at;
595597
lastReads.set(group.key, {
596598
at,
599+
detailAt: plan.detail || last === undefined ? now : last.detailAt,
597600
checkedAt: plan.activity || last === undefined ? at : moved === false ? now : last.checkedAt,
598601
fingerprint: group.fingerprint,
599602
inFlight:

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8930,7 +8930,7 @@ it.layer(layerQueueResumeDisabledInstanceTest)(
89308930

89318931
const watchCostScenarios = [
89328932
{ name: "quiet PR", saves: 48 },
8933-
{ name: "review comment edited", reviewCommentEdit: 40, saves: 48 },
8933+
{ name: "review comment edited", reviewCommentEdit: 40, saves: 32 },
89348934
{
89358935
name: "review comment edit missing from the inbox",
89368936
reviewCommentEdit: 40,
@@ -8939,6 +8939,13 @@ const watchCostScenarios = [
89398939
saves: 48,
89408940
},
89418941
{ name: "noisy inbox", inboxEveryMinute: true, saves: 45 },
8942+
{
8943+
name: "checks swap while the pull request keeps moving",
8944+
pullRequestInboxEveryMinute: true,
8945+
checksSwapAt: 10,
8946+
ceilingWake: 120,
8947+
saves: 0,
8948+
},
89428949
{ name: "notifications readable again", notificationsReadableFrom: 60, saves: 32 },
89438950
{ name: "unsubscribed author", viewerSubscription: "UNSUBSCRIBED", saves: 0 },
89448951
];
@@ -9004,6 +9011,9 @@ it.layer(Layer.fresh(layerTest))("pull request watch request cost", (it) => {
90049011
if (scenario.inboxEveryMinute) {
90059012
for (let minute = 0; at(minute) <= now; minute += 1) bump(900, at(minute) + 3_000);
90069013
}
9014+
if (scenario.pullRequestInboxEveryMinute) {
9015+
for (let minute = 0; at(minute) <= now; minute += 1) bump(number, at(minute) + 3_000);
9016+
}
90079017
return times;
90089018
};
90099019

@@ -9024,14 +9034,23 @@ it.layer(Layer.fresh(layerTest))("pull request watch request cost", (it) => {
90249034
};
90259035
}),
90269036
detail: () =>
9027-
Effect.sync(() => {
9037+
Effect.map(Clock.currentTimeMillis, (now) => {
90289038
cost.graphql += 1;
9039+
const check = (name: string, failed: boolean) => ({
9040+
name,
9041+
status: failed ? ("failure" as const) : ("success" as const),
9042+
description: null,
9043+
url: null,
9044+
});
9045+
const swapped =
9046+
scenario.checksSwapAt !== undefined && now >= at(scenario.checksSwapAt);
90299047
return {
90309048
...watchedPullRequestDetail({ projectId, number, at: iso(startedAt) }),
90319049
headSha: "abc1234def",
9032-
checks: [
9033-
{ name: "ci", status: "success" as const, description: null, url: null },
9034-
],
9050+
checks:
9051+
scenario.checksSwapAt === undefined
9052+
? [check("ci", false)]
9053+
: [check("lint", !swapped), check("test", swapped)],
90359054
};
90369055
}),
90379056
activity: () =>

0 commit comments

Comments
 (0)