Skip to content

Commit edcdaeb

Browse files
vkpdeveloperclaude
andcommitted
fix(server): keep the check baseline until a read lists checks
An empty check list can be a failed check read, so it no longer ends the check baseline. Conflicts still take theirs from the first read, so a pull request without checks keeps reporting new conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 97dca56 commit edcdaeb

5 files changed

Lines changed: 65 additions & 22 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,16 +3392,19 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
33923392
passed: false,
33933393
passedChecks: [],
33943394
conflicting: false,
3395-
awaitingBaseline: true,
33963395
// Watching again must not repeat check or conflict news the last watch told.
3397-
...(existing.endedWatch && {
3398-
headSha: existing.endedWatch.headSha,
3399-
failedChecks: existing.endedWatch.failedChecks,
3400-
passed: existing.endedWatch.passed,
3401-
passedChecks: existing.endedWatch.passedChecks,
3402-
conflicting: existing.endedWatch.conflicting,
3403-
awaitingBaseline: existing.endedWatch.awaitingBaseline === true,
3404-
}),
3396+
...(existing.endedWatch
3397+
? {
3398+
headSha: existing.endedWatch.headSha,
3399+
failedChecks: existing.endedWatch.failedChecks,
3400+
passed: existing.endedWatch.passed,
3401+
passedChecks: existing.endedWatch.passedChecks,
3402+
conflicting: existing.endedWatch.conflicting,
3403+
...(existing.endedWatch.awaitingBaseline && {
3404+
awaitingBaseline: existing.endedWatch.awaitingBaseline,
3405+
}),
3406+
}
3407+
: { awaitingBaseline: "all" as const }),
34053408
remarksThrough: startedAt,
34063409
remarkIds: [],
34073410
wakes: 0,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
175175
left.remarkIds.join("\n") === right.remarkIds.join("\n") &&
176176
left.conflicting === right.conflicting &&
177177
left.wakes === right.wakes &&
178-
(left.awaitingBaseline === true) === (right.awaitingBaseline === true)
178+
left.awaitingBaseline === right.awaitingBaseline
179179
);
180180
}
181181

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const noRemarks: ReadonlyArray<PullRequestComment> = [];
6060
describe("evaluatePullRequestWatch", () => {
6161
it.each([false, true])("baselines already-passed checks (required: %s)", (required) => {
6262
const green = detail({ checks: [{ ...check("test", "success"), required }] });
63-
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), green, noRemarks);
63+
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, noRemarks);
6464
assert.deepEqual(baseline.changes, []);
6565
assert.equal(baseline.next.headSha, green.headSha);
6666
assert.isTrue(baseline.next.passed);
@@ -93,7 +93,11 @@ describe("evaluatePullRequestWatch", () => {
9393
checks: [check("lint", "failure"), check("test", "pending")],
9494
mergeability: "conflicting",
9595
});
96-
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), broken, noRemarks);
96+
const baseline = evaluatePullRequestWatch(
97+
watch({ awaitingBaseline: "all" }),
98+
broken,
99+
noRemarks,
100+
);
97101
assert.deepEqual(baseline.changes, []);
98102
assert.deepEqual(baseline.next.failedChecks, ["lint"]);
99103
assert.isFalse(baseline.next.passed);
@@ -125,7 +129,7 @@ describe("evaluatePullRequestWatch", () => {
125129
remark("reviewer", "2026-10-02T11:00:00Z"),
126130
remark("reviewer", "2026-10-02T12:06:00Z"),
127131
];
128-
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), green, comments);
132+
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, comments);
129133
assert.deepEqual(baseline.changes, [{ kind: "remarks", remarks: [comments[1]!] }]);
130134
assert.isTrue(baseline.next.passed);
131135
assert.isTrue(baseline.next.conflicting);
@@ -135,7 +139,11 @@ describe("evaluatePullRequestWatch", () => {
135139

136140
it("keeps reporting check changes when the host omits the head SHA", () => {
137141
const pending = detail({ headSha: undefined, checks: [check("test", "pending")] });
138-
const waiting = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), pending, noRemarks);
142+
const waiting = evaluatePullRequestWatch(
143+
watch({ awaitingBaseline: "all" }),
144+
pending,
145+
noRemarks,
146+
);
139147
assert.deepEqual(waiting.changes, []);
140148
const failed = evaluatePullRequestWatch(
141149
waiting.next,
@@ -157,7 +165,7 @@ describe("evaluatePullRequestWatch", () => {
157165

158166
it("reports a failure once the head SHA appears after a baseline without one", () => {
159167
const waiting = evaluatePullRequestWatch(
160-
watch({ awaitingBaseline: true }),
168+
watch({ awaitingBaseline: "all" }),
161169
detail({ headSha: undefined, checks: [check("test", "pending")] }),
162170
noRemarks,
163171
);
@@ -175,7 +183,7 @@ describe("evaluatePullRequestWatch", () => {
175183
it("keeps a baseline taken without a head SHA once the SHA appears", () => {
176184
const green = detail({ checks: [check("test", "success")] });
177185
const baseline = evaluatePullRequestWatch(
178-
watch({ awaitingBaseline: true }),
186+
watch({ awaitingBaseline: "all" }),
179187
{ ...green, headSha: undefined },
180188
noRemarks,
181189
);
@@ -195,6 +203,30 @@ describe("evaluatePullRequestWatch", () => {
195203
);
196204
});
197205

206+
it("takes the check baseline from the first read that lists checks", () => {
207+
const empty = evaluatePullRequestWatch(
208+
watch({ awaitingBaseline: "all" }),
209+
detail({ checks: [] }),
210+
noRemarks,
211+
);
212+
assert.deepEqual(empty.changes, []);
213+
assert.equal(empty.next.awaitingBaseline, "checks");
214+
215+
const failing = detail({ checks: [check("lint", "failure")], mergeability: "conflicting" });
216+
const listed = evaluatePullRequestWatch(empty.next, failing, noRemarks);
217+
// The conflict is new since the first read; the failure may predate the watch.
218+
assert.deepEqual(listed.changes, [{ kind: "conflicting" }]);
219+
assert.isUndefined(listed.next.awaitingBaseline);
220+
assert.deepEqual(
221+
evaluatePullRequestWatch(
222+
listed.next,
223+
{ ...failing, checks: [check("lint", "failure"), check("test", "failure")] },
224+
noRemarks,
225+
).changes,
226+
[{ kind: "checks-failed", failed: [check("test", "failure")] }],
227+
);
228+
});
229+
198230
it("reports each failure at once, even while another check never finishes", () => {
199231
const bot = check("CodeRabbit", "pending");
200232
const first = detail({ checks: [check("lint", "failure"), check("test", "pending"), bot] });

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function evaluatePullRequestWatch(
3939
// A read without a head says nothing about pushes, so it keeps the last known one.
4040
const headSha = detail.headSha ?? watch.headSha;
4141
// Remarks already have their baseline in startedAt.
42-
const baseline = watch.awaitingBaseline === true;
42+
const checksBaseline = watch.awaitingBaseline !== undefined;
4343
const headMoved = watch.headSha !== null && headSha !== watch.headSha;
4444

4545
// An empty list keeps the last state: a host can answer with one when its check read fails.
@@ -49,7 +49,7 @@ export function evaluatePullRequestWatch(
4949
if (detail.checks.length > 0) {
5050
const failed = detail.checks.filter(isFailedCheck);
5151
const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name));
52-
if (!baseline && newlyFailed.length > 0) {
52+
if (!checksBaseline && newlyFailed.length > 0) {
5353
changes.push({ kind: "checks-failed", failed: newlyFailed });
5454
}
5555
failedChecks = failed.map((check) => check.name);
@@ -62,7 +62,7 @@ export function evaluatePullRequestWatch(
6262
// A required job created and finished between two passes is never seen pending. Without
6363
// required checks, any check counts, and advisory bots keep adding passed ones: no wake.
6464
const gateGrew = required.length > 0 && gateNames.some((name) => !told.includes(name));
65-
if (!baseline && passedNow && (!passed || gateGrew)) {
65+
if (!checksBaseline && passedNow && (!passed || gateGrew)) {
6666
changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 });
6767
}
6868
passed = passedNow;
@@ -89,7 +89,11 @@ export function evaluatePullRequestWatch(
8989
...atLatest.map((remark) => remark.id),
9090
];
9191

92-
if (!baseline && detail.mergeability === "conflicting" && !watch.conflicting) {
92+
if (
93+
watch.awaitingBaseline !== "all" &&
94+
detail.mergeability === "conflicting" &&
95+
!watch.conflicting
96+
) {
9397
changes.push({ kind: "conflicting" });
9498
}
9599
// "unknown" is GitHub still computing after a push; only a clean answer clears a conflict.
@@ -111,6 +115,7 @@ export function evaluatePullRequestWatch(
111115
remarkIds,
112116
conflicting,
113117
wakes,
118+
...(checksBaseline && detail.checks.length === 0 && { awaitingBaseline: "checks" as const }),
114119
},
115120
exhausted: commentsOnly && wakes >= PULL_REQUEST_WATCH_WAKE_LIMIT,
116121
};

‎packages/contracts/src/threadPullRequest.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ export const ThreadPullRequestWatch = Schema.Struct({
9595
conflicting: Schema.Boolean,
9696
/** Comment-only wakes in a row. Watching stops at a limit, so bots cannot loop it. */
9797
wakes: NonNegativeInt,
98-
/** Not read yet: the first read records checks and conflicts already there without reporting them. */
99-
awaitingBaseline: Schema.optional(Schema.Boolean),
98+
/**
99+
* What is already on the pull request is recorded, not reported: conflicts on the first read, and
100+
* checks on the first read that lists any, since an empty list can be a failed check read.
101+
*/
102+
awaitingBaseline: Schema.optional(Schema.Literals(["all", "checks"])),
100103
});
101104
export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
102105

0 commit comments

Comments
 (0)