Skip to content

Commit 41d7c50

Browse files
vkpdeveloperclaude
andcommitted
fix(server): track the watch baseline independently of the head SHA
A first read without a head SHA left the watch looking fresh, so the next read that brought a SHA was treated as the baseline and swallowed new check failures. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f515485 commit 41d7c50

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,13 +3392,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
33923392
passed: false,
33933393
passedChecks: [],
33943394
conflicting: false,
3395+
awaitingBaseline: true,
33953396
// Watching again must not repeat check or conflict news the last watch told.
33963397
...(existing.endedWatch && {
33973398
headSha: existing.endedWatch.headSha,
33983399
failedChecks: existing.endedWatch.failedChecks,
33993400
passed: existing.endedWatch.passed,
34003401
passedChecks: existing.endedWatch.passedChecks,
34013402
conflicting: existing.endedWatch.conflicting,
3403+
awaitingBaseline: existing.endedWatch.awaitingBaseline === true,
34023404
}),
34033405
remarksThrough: startedAt,
34043406
remarkIds: [],

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
174174
left.remarksThrough === right.remarksThrough &&
175175
left.remarkIds.join("\n") === right.remarkIds.join("\n") &&
176176
left.conflicting === right.conflicting &&
177-
left.wakes === right.wakes
177+
left.wakes === right.wakes &&
178+
(left.awaitingBaseline === true) === (right.awaitingBaseline === true)
178179
);
179180
}
180181

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const STARTED = "2026-10-02T12:00:00.000Z";
1111

1212
const watch = (overrides: Partial<ThreadPullRequestWatch> = {}): ThreadPullRequestWatch => ({
1313
startedAt: STARTED,
14-
headSha: "aaaaaaaaaa",
14+
headSha: null,
1515
failedChecks: [],
1616
passed: false,
1717
passedChecks: [],
@@ -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({ headSha: null }), green, noRemarks);
63+
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), green, noRemarks);
6464
assert.deepEqual(baseline.changes, []);
6565
assert.equal(baseline.next.headSha, green.headSha);
6666
assert.isTrue(baseline.next.passed);
@@ -93,7 +93,7 @@ describe("evaluatePullRequestWatch", () => {
9393
checks: [check("lint", "failure"), check("test", "pending")],
9494
mergeability: "conflicting",
9595
});
96-
const baseline = evaluatePullRequestWatch(watch({ headSha: null }), broken, noRemarks);
96+
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), broken, noRemarks);
9797
assert.deepEqual(baseline.changes, []);
9898
assert.deepEqual(baseline.next.failedChecks, ["lint"]);
9999
assert.isFalse(baseline.next.passed);
@@ -125,7 +125,7 @@ describe("evaluatePullRequestWatch", () => {
125125
remark("reviewer", "2026-10-02T11:00:00Z"),
126126
remark("reviewer", "2026-10-02T12:06:00Z"),
127127
];
128-
const baseline = evaluatePullRequestWatch(watch({ headSha: null }), green, comments);
128+
const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), green, comments);
129129
assert.deepEqual(baseline.changes, [{ kind: "remarks", remarks: [comments[1]!] }]);
130130
assert.isTrue(baseline.next.passed);
131131
assert.isTrue(baseline.next.conflicting);
@@ -135,7 +135,7 @@ describe("evaluatePullRequestWatch", () => {
135135

136136
it("keeps reporting check changes when the host omits the head SHA", () => {
137137
const pending = detail({ headSha: undefined, checks: [check("test", "pending")] });
138-
const waiting = evaluatePullRequestWatch(watch({ headSha: null }), pending, noRemarks);
138+
const waiting = evaluatePullRequestWatch(watch({ awaitingBaseline: true }), pending, noRemarks);
139139
assert.deepEqual(waiting.changes, []);
140140
const failed = evaluatePullRequestWatch(
141141
waiting.next,
@@ -155,6 +155,23 @@ describe("evaluatePullRequestWatch", () => {
155155
);
156156
});
157157

158+
it("reports a failure once the head SHA appears after a baseline without one", () => {
159+
const waiting = evaluatePullRequestWatch(
160+
watch({ awaitingBaseline: true }),
161+
detail({ headSha: undefined, checks: [check("test", "pending")] }),
162+
noRemarks,
163+
);
164+
assert.deepEqual(waiting.changes, []);
165+
const failed = evaluatePullRequestWatch(
166+
waiting.next,
167+
detail({ checks: [check("test", "failure")] }),
168+
noRemarks,
169+
);
170+
assert.deepEqual(failed.changes, [
171+
{ kind: "checks-failed", failed: [check("test", "failure")] },
172+
]);
173+
});
174+
158175
it("reports each failure at once, even while another check never finishes", () => {
159176
const bot = check("CodeRabbit", "pending");
160177
const first = detail({ checks: [check("lint", "failure"), check("test", "pending"), bot] });

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function evaluatePullRequestWatch(
3737
): PullRequestWatchReport {
3838
const changes: Array<PullRequestWatchChange> = [];
3939
const headSha = detail.headSha ?? null;
40-
// Only a read with a head can persist a fresh watch's baseline. Remarks use startedAt.
41-
const baseline = watch.headSha === null && headSha !== null;
40+
// Remarks already have their baseline in startedAt.
41+
const baseline = watch.awaitingBaseline === true;
4242
const headMoved = headSha !== watch.headSha;
4343

4444
// An empty list keeps the last state: a host can answer with one when its check read fails.

‎packages/contracts/src/threadPullRequest.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ 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),
98100
});
99101
export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
100102

0 commit comments

Comments
 (0)