diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts index 6ab0191649490..f8a8b762f4b17 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts @@ -205,6 +205,26 @@ describe("evaluatePullRequestWatch", () => { assert.deepEqual(evaluatePullRequestWatch(final.next, recovered, noRemarks).changes, []); }); + it("reports once when the checks still running at a failure finish", () => { + const lint = check("lint", "failure"); + const running = detail({ checks: [lint, check("test", "pending"), check("e2e", "pending")] }); + const failure = evaluatePullRequestWatch(watch(), running, noRemarks); + assert.deepEqual(failure.changes, [{ kind: "checks-failed", failed: [lint] }]); + const partial = detail({ checks: [lint, check("test", "success"), check("e2e", "pending")] }); + const waiting = evaluatePullRequestWatch(failure.next, partial, noRemarks); + assert.deepEqual(waiting.changes, []); + const finished = detail({ checks: [lint, check("test", "success"), check("e2e", "success")] }); + const settled = evaluatePullRequestWatch(waiting.next, finished, noRemarks); + assert.deepEqual(settled.changes, [{ kind: "checks-finished", count: 3, failed: [lint] }]); + assert.deepEqual(evaluatePullRequestWatch(settled.next, finished, noRemarks).changes, []); + + const e2e = check("e2e", "failure"); + const lastFailed = detail({ checks: [lint, check("test", "success"), e2e] }); + const failedLast = evaluatePullRequestWatch(waiting.next, lastFailed, noRemarks); + assert.deepEqual(failedLast.changes, [{ kind: "checks-failed", failed: [e2e] }]); + assert.deepEqual(evaluatePullRequestWatch(failedLast.next, lastFailed, noRemarks).changes, []); + }); + it("clears old-head owed checks when a new head is pushed", () => { const required = { ...check("test", "success"), required: true }; const early = detail({ checks: [required, check("e2e", "pending")] }); diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.ts b/apps/server/src/orchestration-v2/pullRequestWatch.ts index f4c0000847236..8a1fcbbc60958 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.ts @@ -17,6 +17,11 @@ const SNIPPET_LENGTH = 200; export type PullRequestWatchChange = | { readonly kind: "checks-failed"; readonly failed: ReadonlyArray } | { readonly kind: "checks-passed"; readonly count: number; readonly required: boolean } + | { + readonly kind: "checks-finished"; + readonly count: number; + readonly failed: ReadonlyArray; + } | { readonly kind: "remarks"; readonly remarks: ReadonlyArray } | { readonly kind: "no-checks"; readonly minutes: number } | { readonly kind: "conflicting" }; @@ -73,6 +78,10 @@ export function evaluatePullRequestWatch( : []; const settled = failed.length === 0 && detail.checks.every((check) => check.status !== "pending"); + const pending = detail.checks + .filter((check) => check.status === "pending") + .map((check) => check.name); + const owedAtFailure = owedChecks; owedChecks = owed; if (passedNow && (!passed || gateGrew)) { changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 }); @@ -85,6 +94,13 @@ export function evaluatePullRequestWatch( } else if (settled && owed.length > 0) { changes.push({ kind: "checks-passed", count: detail.checks.length, required: false }); owedChecks = []; + } else if (!passedNow && failed.length > 0) { + // A failure wake ends the turn while other checks run, so their finish is owed one wake. + owedChecks = + newlyFailed.length > 0 ? pending : owedAtFailure.filter((name) => pending.includes(name)); + if (newlyFailed.length === 0 && owedAtFailure.length > 0 && owedChecks.length === 0) { + changes.push({ kind: "checks-finished", count: detail.checks.length, failed }); + } } passed = passedNow; passedChecks = passedNow ? gateNames : []; @@ -176,24 +192,25 @@ function listed(items: ReadonlyArray, line: (item: T) => string): Array + ` - ${check.name}${check.status === "failure" ? "" : ` (${check.status})`}${check.url ? ` ${check.url}` : ""}`; + function changeLines( change: PullRequestWatchChange, context: { readonly baseBranch: string; readonly commit: string }, ): Array { switch (change.kind) { case "checks-failed": - return [ - `- Checks failed${context.commit}:`, - ...listed( - change.failed, - (check) => - ` - ${check.name}${check.status === "failure" ? "" : ` (${check.status})`}${check.url ? ` ${check.url}` : ""}`, - ), - ]; + return [`- Checks failed${context.commit}:`, ...listed(change.failed, checkLine)]; case "checks-passed": return [ `- All ${change.count} ${change.required ? "required " : ""}${change.count === 1 ? "check" : "checks"} passed${context.commit}.`, ]; + case "checks-finished": + return [ + `- All ${change.count} ${change.count === 1 ? "check" : "checks"} finished${context.commit}, and ${change.failed.length} failed:`, + ...listed(change.failed, checkLine), + ]; case "remarks": return [ `- ${change.remarks.length} new ${change.remarks.length === 1 ? "comment" : "comments"}:`, @@ -216,6 +233,7 @@ function changeLines( const SUMMARY: Record = { "checks-failed": "checks failed", "checks-passed": "checks passed", + "checks-finished": "checks finished", remarks: "new comments", "no-checks": "no checks reported", conflicting: "merge conflict", @@ -242,7 +260,10 @@ export function pullRequestWatchMessage(input: { : "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.", ].join("\n"); const failed = changes.some( - (change) => change.kind === "checks-failed" || change.kind === "conflicting", + (change) => + change.kind === "checks-failed" || + change.kind === "checks-finished" || + change.kind === "conflicting", ); const summary = changes.map((change) => SUMMARY[change.kind]); if (exhausted) summary.push("stopped watching"); diff --git a/docs/user/source-control.md b/docs/user/source-control.md index 9eb2751f9315f..f0207c9d79dde 100644 --- a/docs/user/source-control.md +++ b/docs/user/source-control.md @@ -296,8 +296,8 @@ review is terminal. An open or unsynced link keeps it active. Ask the agent to watch, monitor, or babysit a pull request and it calls `watch_pull_request`. While the thread is active, the server checks the pull request every two minutes and wakes the agent when a -check fails, the required checks pass, someone else comments or reviews, or the branch starts to -conflict. Threads in a project that watch the same pull request share one check. On GitHub, a check +check fails, the required checks pass, the checks still running after a failure finish, someone else +comments or reviews, or the branch starts to conflict. Threads in a project that watch the same pull request share one check. On GitHub, a check first asks whether anything changed and reads the pull request only when it did, which keeps watching inside GitHub's rate limit. Comments from your own account do not wake it. Watching ends when the pull request merges or closes, after 10 wakes in a row that bring only comments, after 8 diff --git a/packages/contracts/src/threadPullRequest.ts b/packages/contracts/src/threadPullRequest.ts index 3daee9ce197e2..534d6ae62d6a6 100644 --- a/packages/contracts/src/threadPullRequest.ts +++ b/packages/contracts/src/threadPullRequest.ts @@ -87,7 +87,7 @@ export const ThreadPullRequestWatch = Schema.Struct({ passedChecks: Schema.Array(TrimmedNonEmptyString).pipe( Schema.withDecodingDefault(Effect.succeed([])), ), - /** Checks still pending when required ones passed early, owed one wake once all settle. */ + /** Checks still pending when required ones passed early or a failure was told, owed one wake once they settle. */ owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)), remarksThrough: IsoDateTime, /** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */