Skip to content

Commit ff41395

Browse files
Rhinomcdclaude
andcommitted
fix(server): PR watches wake when checks finish after an early failure
With no required checks, the watch only sends checks-passed once every check passes. A check that fails early, such as a cancelled advisory analysis, woke the agent while the rest were still running, and nothing woke it again when they finished. The gate checks still running at a failure are now owed one checks-finished wake. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 50c1c5d commit ff41395

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,30 @@ describe("evaluatePullRequestWatch", () => {
204204
assert.deepEqual(evaluatePullRequestWatch(final.next, recovered, noRemarks).changes, []);
205205
});
206206

207+
it("wakes once when the other checks finish after one failed where none is required", () => {
208+
const sonar = check("sonar", "cancelled");
209+
const early = detail({ checks: [sonar, check("unit", "pending"), check("e2e", "pending")] });
210+
const first = evaluatePullRequestWatch(watch(), early, noRemarks);
211+
assert.deepEqual(first.changes, [{ kind: "checks-failed", failed: [sonar] }]);
212+
213+
const partway = detail({ checks: [sonar, check("unit", "success"), check("e2e", "pending")] });
214+
const waiting = evaluatePullRequestWatch(first.next, partway, noRemarks);
215+
assert.deepEqual(waiting.changes, []);
216+
217+
const done = detail({ checks: [sonar, check("unit", "success"), check("e2e", "success")] });
218+
const final = evaluatePullRequestWatch(waiting.next, done, noRemarks);
219+
assert.deepEqual(final.changes, [{ kind: "checks-finished", failing: [sonar] }]);
220+
assert.deepEqual(evaluatePullRequestWatch(final.next, done, noRemarks).changes, []);
221+
222+
// A later failure is its own wake and leaves nothing more owed.
223+
const broke = detail({ checks: [sonar, check("unit", "success"), check("e2e", "failure")] });
224+
const failure = evaluatePullRequestWatch(waiting.next, broke, noRemarks);
225+
assert.deepEqual(failure.changes, [
226+
{ kind: "checks-failed", failed: [check("e2e", "failure")] },
227+
]);
228+
assert.deepEqual(evaluatePullRequestWatch(failure.next, broke, noRemarks).changes, []);
229+
});
230+
207231
it("clears old-head owed checks when a new head is pushed", () => {
208232
const required = { ...check("test", "success"), required: true };
209233
const early = detail({ checks: [required, check("e2e", "pending")] });

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const SNIPPET_LENGTH = 200;
1717
export type PullRequestWatchChange =
1818
| { readonly kind: "checks-failed"; readonly failed: ReadonlyArray<PullRequestCheck> }
1919
| { readonly kind: "checks-passed"; readonly count: number; readonly required: boolean }
20+
| { readonly kind: "checks-finished"; readonly failing: ReadonlyArray<PullRequestCheck> }
2021
| { readonly kind: "remarks"; readonly remarks: ReadonlyArray<PullRequestComment> }
2122
| { readonly kind: "no-checks"; readonly minutes: number }
2223
| { readonly kind: "conflicting" };
@@ -50,6 +51,7 @@ export function evaluatePullRequestWatch(
5051
let passedChecks = headMoved ? [] : watch.passedChecks;
5152
let owedChecks = headMoved ? [] : (watch.owedChecks ?? []);
5253
if (detail.checks.length > 0) {
54+
const owedBefore = owedChecks;
5355
const failed = detail.checks.filter(isFailedCheck);
5456
const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name));
5557
if (newlyFailed.length > 0) changes.push({ kind: "checks-failed", failed: newlyFailed });
@@ -84,6 +86,18 @@ export function evaluatePullRequestWatch(
8486
} else if (settled && owed.length > 0) {
8587
changes.push({ kind: "checks-passed", count: detail.checks.length, required: false });
8688
owedChecks = [];
89+
} else if (!passedNow && failed.length > 0) {
90+
// Gate checks still running when one failed are owed one wake when they finish, since
91+
// the gate can no longer pass and so never sends the checks-passed wake.
92+
const running = gate.filter((check) => check.status === "pending").map((check) => check.name);
93+
owedChecks =
94+
newlyFailed.length > 0 ? running : owedBefore.filter((name) => running.includes(name));
95+
if (newlyFailed.length === 0 && owedBefore.length > 0 && owedChecks.length === 0) {
96+
changes.push({
97+
kind: "checks-finished",
98+
failing: failed.filter((check) => gateNames.includes(check.name)),
99+
});
100+
}
87101
}
88102
passed = passedNow;
89103
passedChecks = passedNow ? gateNames : [];
@@ -197,6 +211,14 @@ function changeLines(
197211
return ` - ${remark.author?.login ?? "someone"}${where}: ${said}${remark.url ? ` ${remark.url}` : ""}`;
198212
}),
199213
];
214+
case "checks-finished":
215+
return [
216+
`- The checks still running when one failed have finished${context.commit}. Still failing:`,
217+
...listed(
218+
change.failing,
219+
(check) => ` - ${check.name}${check.url ? ` ${check.url}` : ""}`,
220+
),
221+
];
200222
case "no-checks":
201223
return [
202224
`- No checks have reported${context.commit} after ${change.minutes} minutes. None may be configured to run on this change.`,
@@ -209,6 +231,7 @@ function changeLines(
209231
const SUMMARY: Record<PullRequestWatchChange["kind"], string> = {
210232
"checks-failed": "checks failed",
211233
"checks-passed": "checks passed",
234+
"checks-finished": "checks finished",
212235
remarks: "new comments",
213236
"no-checks": "no checks reported",
214237
conflicting: "merge conflict",
@@ -235,7 +258,10 @@ export function pullRequestWatchMessage(input: {
235258
: "Look into each item and act on it as your task requires. This PR stays linked and watched, so do not link, watch, or list it again. End your turn when you are done, and T3 Code wakes you on the next change. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox.",
236259
].join("\n");
237260
const failed = changes.some(
238-
(change) => change.kind === "checks-failed" || change.kind === "conflicting",
261+
(change) =>
262+
change.kind === "checks-failed" ||
263+
change.kind === "checks-finished" ||
264+
change.kind === "conflicting",
239265
);
240266
const summary = changes.map((change) => SUMMARY[change.kind]);
241267
if (exhausted) summary.push("stopped watching");

‎packages/contracts/src/threadPullRequest.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const ThreadPullRequestWatch = Schema.Struct({
8787
passedChecks: Schema.Array(TrimmedNonEmptyString).pipe(
8888
Schema.withDecodingDefault(Effect.succeed([])),
8989
),
90-
/** Checks still pending when required ones passed early, owed one wake once all settle. */
90+
/** Checks still pending when required ones passed early or a gate check failed, owed one wake once they settle. */
9191
owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
9292
remarksThrough: IsoDateTime,
9393
/** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */

0 commit comments

Comments
 (0)