Skip to content

Commit 873a9bc

Browse files
PR Batch Testerclaude
andcommitted
fix(server): PR watch tells real URL-less approvals from unread ones and keeps its head through headless reads
The watch took any action-required check without a URL for GitHub's "could not tell whether workflows await approval" stand-in, so a real check awaiting action that carried no URL never woke the agent and let the bot checks pass. The provider now marks that stand-in with a placeholder flag on the check, and only it leaves the gate as it was; a URL-less action-required check waits like any other, held while it is listed. A read that named no head counted as a push, so it cleared remembered approvals and the next read of the same head could report the bot checks passed. The watch now keeps the head it knew through such a read and resets only when a different head arrives. Refs #24575 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0fe122f commit 873a9bc

6 files changed

Lines changed: 74 additions & 9 deletions

File tree

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ describe("evaluatePullRequestWatch", () => {
203203

204204
it("keeps the last state when a host cannot tell whether workflows await approval", () => {
205205
const bot = check("bot", "success");
206-
const unknown = { ...check("Workflow approval status", "action-required"), url: null };
206+
const unknown = {
207+
...check("Workflow approval status", "action-required"),
208+
url: null,
209+
placeholder: true,
210+
};
207211
const unread = evaluatePullRequestWatch(watch(), detail({ checks: [bot, unknown] }), noRemarks);
208212
assert.deepEqual(unread.changes, []);
209213
assert.isFalse(unread.next.passed);
@@ -222,6 +226,59 @@ describe("evaluatePullRequestWatch", () => {
222226
);
223227
});
224228

229+
it("waits for an approval with no URL while the host lists it", () => {
230+
const bot = check("bot", "success");
231+
const green = evaluatePullRequestWatch(watch(), detail({ checks: [bot] }), noRemarks);
232+
assert.isTrue(green.next.passed);
233+
const approval = { ...check("contributor tests", "action-required"), url: null };
234+
const gated = evaluatePullRequestWatch(
235+
green.next,
236+
detail({ checks: [bot, approval] }),
237+
noRemarks,
238+
);
239+
assert.deepEqual(gated.changes, [{ kind: "checks-awaiting-approval", checks: [approval] }]);
240+
assert.isFalse(gated.next.passed);
241+
const still = evaluatePullRequestWatch(
242+
gated.next,
243+
detail({ checks: [bot, approval] }),
244+
noRemarks,
245+
);
246+
assert.deepEqual(still.changes, []);
247+
// Nothing else names it, so it is held only while listed, unlike a workflow run.
248+
const done = evaluatePullRequestWatch(
249+
still.next,
250+
detail({ checks: [bot, check("contributor tests", "success")] }),
251+
noRemarks,
252+
);
253+
assert.deepEqual(done.changes, [{ kind: "checks-passed", count: 2, required: false }]);
254+
assert.deepEqual(done.next.awaitingApproval, []);
255+
});
256+
257+
it("keeps the head and awaited approvals through a read that names no head", () => {
258+
const bot = check("bot", "success");
259+
const approval = { ...check("CI", "action-required"), url: run(1) };
260+
const unknown = {
261+
...check("Workflow approval status", "action-required"),
262+
url: null,
263+
placeholder: true,
264+
};
265+
const first = evaluatePullRequestWatch(watch(), detail({ checks: [bot, approval] }), noRemarks);
266+
const { headSha: _headSha, ...headless } = detail({ checks: [bot, unknown] });
267+
const blind = evaluatePullRequestWatch(first.next, headless, noRemarks);
268+
assert.deepEqual(blind.changes, []);
269+
assert.equal(blind.next.headSha, "aaaaaaaaaa");
270+
assert.deepEqual(blind.next.awaitingApproval, [run(1)]);
271+
const same = evaluatePullRequestWatch(blind.next, detail({ checks: [bot] }), noRemarks);
272+
assert.deepEqual(same.changes, []);
273+
assert.isFalse(same.next.passed);
274+
const pushed = evaluatePullRequestWatch(
275+
same.next,
276+
detail({ headSha: "bbbbbbbbbb", checks: [bot] }),
277+
noRemarks,
278+
);
279+
assert.deepEqual(pushed.changes, [{ kind: "checks-passed", count: 1, required: false }]);
280+
});
281+
225282
it("does not tell a watch saved before approvals were recorded about one it reported", () => {
226283
const approval = { ...check("CI", "action-required"), url: run(1) };
227284
const saved = watch({ headSha: "aaaaaaaaaa", failedChecks: ["CI"] });

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export function evaluatePullRequestWatch(
4848
now: number,
4949
): PullRequestWatchReport {
5050
const changes: Array<PullRequestWatchChange> = [];
51-
const headSha = detail.headSha ?? null;
51+
// A read that names no head is not a push: the watch keeps the head it knew.
52+
const headSha = detail.headSha ?? watch.headSha;
5253
const headMoved = headSha !== watch.headSha;
5354

5455
// An empty list keeps the last state: a host can answer with one when its check read fails.
@@ -58,15 +59,13 @@ export function evaluatePullRequestWatch(
5859
let owedChecks = headMoved ? [] : (watch.owedChecks ?? []);
5960
let awaitingApproval = headMoved ? [] : (watch.awaitingApproval ?? []);
6061
// "action-required" waits on someone, such as a maintainer approving a fork's workflows, so the
61-
// agent is told once and nothing passes meanwhile. One with no URL is a host that could not
62-
// tell, so that pass leaves the gate as it was.
62+
// agent is told once and nothing passes meanwhile. A placeholder is a host that could not tell,
63+
// so that pass leaves the gate as it was.
6364
const failed = detail.checks.filter(isFailedCheck);
6465
const awaiting = detail.checks.filter(
65-
(check) => check.status === "action-required" && check.url !== null,
66-
);
67-
const unread = detail.checks.some(
68-
(check) => check.status === "action-required" && check.url === null,
66+
(check) => check.status === "action-required" && check.placeholder !== true,
6967
);
68+
const unread = detail.checks.some((check) => check.placeholder === true);
7069
if (detail.checks.length > 0) {
7170
const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name));
7271
if (newlyFailed.length > 0) changes.push({ kind: "checks-failed", failed: newlyFailed });

‎packages/contracts/src/pullRequest.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export const PullRequestCheck = Schema.Struct({
113113
description: Schema.NullOr(Schema.String),
114114
url: Schema.NullOr(Schema.String),
115115
required: Schema.optional(Schema.Boolean),
116+
/**
117+
* Not a check: it stands for ones the host could not list, such as workflow runs awaiting
118+
* approval when that read fails, so nothing waits on it or counts it as passing.
119+
*/
120+
placeholder: Schema.optional(Schema.Boolean),
116121
});
117122
export type PullRequestCheck = typeof PullRequestCheck.Type;
118123

‎packages/contracts/src/threadPullRequest.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export const ThreadPullRequestWatch = Schema.Struct({
9393
owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
9494
/**
9595
* Checks waiting for someone to approve or act on them, the agent told once: a workflow run's
96-
* URL, kept until the run is seen going even through reads that miss it, or a check's name.
96+
* URL, kept through reads that miss it until one of its jobs finishes, or else a check's name,
97+
* kept only while a read lists it.
9798
*/
9899
awaitingApproval: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
99100
remarksThrough: IsoDateTime,

‎packages/source-control-github/src/server/GitHubPullRequestProvider.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ describe("gitHubViewerPermissions", () => {
218218
status: "action-required",
219219
description: "GitHub could not determine whether workflows are awaiting approval.",
220220
url: null,
221+
placeholder: true,
221222
});
222223
for (const fingerprint of ["broad", "restricted", "broad"]) {
223224
const scoped = yield* provider
@@ -481,6 +482,7 @@ it.effect("keeps an unsafe workflow approval scope visible as unknown", () =>
481482
status: "action-required",
482483
description: "GitHub could not determine whether workflows are awaiting approval.",
483484
url: null,
485+
placeholder: true,
484486
},
485487
]);
486488
}).pipe(

‎packages/source-control-github/src/server/GitHubPullRequestProvider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function withWorkflowApprovals(
176176
status: "action-required" as const,
177177
description: "GitHub could not determine whether workflows are awaiting approval.",
178178
url: null,
179+
placeholder: true,
179180
},
180181
]
181182
: []),

0 commit comments

Comments
 (0)