The best way to control Claude Code, Codex and more from any computer or phone
fix(server): wake PR watches when remaining CI checks finish (#23904)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 22, 2026 at 21:58 UTC
09bb9f157b3548043e9e241f34fe3a600a55a57b
6 files changed
+228
apps/server/src/orchestration-v2/Orchestrator.ts
+3
@@ -3400,6 +3400,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3400
passedChecks: existing.endedWatch.passedChecks,
3401
conflicting: existing.endedWatch.conflicting,
3402
}),
3403
+ ...(existing.endedWatch?.owedChecks !== undefined && {
3404
+ owedChecks: existing.endedWatch.owedChecks,
3405
+ }),
3406
...(existing.endedWatch?.checksAwaitedSince !== undefined && {
3407
checksAwaitedSince: existing.endedWatch.checksAwaitedSince,
3408
}),
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+1
@@ -171,6 +171,7 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
171
left.failedChecks.join("\n") === right.failedChecks.join("\n") &&
172
left.passed === right.passed &&
173
left.passedChecks.join("\n") === right.passedChecks.join("\n") &&
174
+ (left.owedChecks ?? []).join("\n") === (right.owedChecks ?? []).join("\n") &&
175
left.remarksThrough === right.remarksThrough &&
176
left.remarkIds.join("\n") === right.remarkIds.join("\n") &&
177
left.conflicting === right.conflicting &&
apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+79
@@ -134,6 +134,85 @@ describe("evaluatePullRequestWatch", () => {
134
]);
135
});
136
137
+ // regression: #23712 required checks woke the agent early and the rest finishing never did
138
+ it("wakes again when the other checks finish after the required ones passed", () => {
139
+ const required = (name: string, status: PullRequestCheck["status"]) => ({
140
+ ...check(name, status),
141
+ required: true,
142
+ });
143
+ const early = detail({
144
+ checks: [required("test", "success"), check("e2e", "pending")],
145
+ });
146
+ const first = evaluatePullRequestWatch(watch(), early, noRemarks);
147
+ assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: true }]);
148
+
149
+ const done = detail({
150
+ checks: [required("test", "success"), check("e2e", "success")],
151
+ });
152
+ const final = evaluatePullRequestWatch(first.next, done, noRemarks);
153
+ assert.deepEqual(
154
+ final.changes.map((change) => change.kind),
155
+ ["checks-passed"],
156
+ );
157
+ assert.deepEqual(evaluatePullRequestWatch(final.next, done, noRemarks).changes, []);
158
+ // A later advisory job running and passing is not more news.
159
+ const botPending = detail({ checks: [...done.checks, check("bot", "pending")] });
160
+ const churn = evaluatePullRequestWatch(final.next, botPending, noRemarks);
161
+ assert.deepEqual(churn.changes, []);
162
+ const botDone = detail({ checks: [...done.checks, check("bot", "success")] });
163
+ assert.deepEqual(evaluatePullRequestWatch(churn.next, botDone, noRemarks).changes, []);
164
+
165
+ // A pending check that turns required on the next read still finishes with one wake.
166
+ const promoted = detail({
167
+ checks: [required("test", "success"), required("e2e", "success")],
168
+ });
169
+ const gated = evaluatePullRequestWatch(first.next, promoted, noRemarks);
170
+ assert.deepEqual(gated.changes, [{ kind: "checks-passed", count: 2, required: true }]);
171
+ assert.deepEqual(evaluatePullRequestWatch(gated.next, promoted, noRemarks).changes, []);
172
+
173
+ // Nothing else was pending when the required ones passed, so nothing more is owed.
174
+ const green = evaluatePullRequestWatch(watch(), done, noRemarks);
175
+ assert.deepEqual(green.changes, [{ kind: "checks-passed", count: 1, required: true }]);
176
+ assert.deepEqual(evaluatePullRequestWatch(green.next, botDone, noRemarks).changes, []);
177
+ });
178
+
179
+ it("reports an owed non-required failure once after the required notice", () => {
180
+ const required = { ...check("test", "success"), required: true };
181
+ const early = detail({ checks: [required, check("e2e", "pending")] });
182
+ const first = evaluatePullRequestWatch(watch(), early, noRemarks);
183
+ assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: true }]);
184
+ const failed = detail({ checks: [required, check("e2e", "failure")] });
185
+ const failure = evaluatePullRequestWatch(first.next, failed, noRemarks);
186
+ assert.deepEqual(failure.changes, [
187
+ { kind: "checks-failed", failed: [check("e2e", "failure")] },
188
+ ]);
189
+ const repeated = evaluatePullRequestWatch(failure.next, failed, noRemarks);
190
+ assert.deepEqual(repeated.changes, []);
191
+ const recovered = detail({ checks: [required, check("e2e", "success")] });
192
+ const final = evaluatePullRequestWatch(repeated.next, recovered, noRemarks);
193
+ assert.deepEqual(final.changes, [{ kind: "checks-passed", count: 2, required: false }]);
194
+ assert.deepEqual(evaluatePullRequestWatch(final.next, recovered, noRemarks).changes, []);
195
+ });
196
+
197
+ it("clears old-head owed checks when a new head is pushed", () => {
198
+ const required = { ...check("test", "success"), required: true };
199
+ const early = detail({ checks: [required, check("e2e", "pending")] });
200
+ const first = evaluatePullRequestWatch(watch(), early, noRemarks);
201
+ assert.deepEqual(first.next.owedChecks, ["e2e"]);
202
+ const unreadHead = detail({ headSha: "bbbbbbbbbb", checks: [] });
203
+ const unread = evaluatePullRequestWatch(first.next, unreadHead, noRemarks);
204
+ assert.deepEqual(unread.changes, []);
205
+ assert.deepEqual(unread.next.owedChecks, []);
206
+ const pushed = detail({ ...unreadHead, checks: [required] });
207
+ const newHead = evaluatePullRequestWatch(unread.next, pushed, noRemarks);
208
+ assert.deepEqual(newHead.changes, [{ kind: "checks-passed", count: 1, required: true }]);
209
+ assert.deepEqual(newHead.next.owedChecks, []);
210
+ const lateResult = detail({ ...pushed, checks: [required, check("e2e", "success")] });
211
+ const final = evaluatePullRequestWatch(newHead.next, lateResult, noRemarks);
212
+ assert.deepEqual(final.changes, []);
213
+ assert.deepEqual(evaluatePullRequestWatch(final.next, lateResult, noRemarks).changes, []);
214
+ });
215
+
216
// regression: #16208 PR watches burned GitHub's rate limit and gave up
217
it("does not report passed again for a new passed check where none is required", () => {
218
const first = evaluatePullRequestWatch(
apps/server/src/orchestration-v2/pullRequestWatch.ts
+22
@@ -51,6 +51,7 @@ export function evaluatePullRequestWatch(
51
let failedChecks = headMoved ? [] : watch.failedChecks;
52
let passed = headMoved ? false : watch.passed;
53
let passedChecks = headMoved ? [] : watch.passedChecks;
54
+ let owedChecks = headMoved ? [] : (watch.owedChecks ?? []);
55
if (detail.checks.length > 0) {
56
const failed = detail.checks.filter(isFailedCheck);
57
const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name));
@@ -65,8 +66,28 @@ export function evaluatePullRequestWatch(
66
// A required job created and finished between two passes is never seen pending. Without
67
// required checks, any check counts, and advisory bots keep adding passed ones: no wake.
68
const gateGrew = required.length > 0 && gateNames.some((name) => !told.includes(name));
69
+ // Other checks still pending when required ones passed are owed one wake when all settle.
70
+ // Only those are owed, so later advisory churn never wakes. One turned required is gate news.
71
+ const owed =
72
+ passedNow && passed
73
+ ? detail.checks
74
+ .filter((check) => check.required !== true && owedChecks.includes(check.name))
75
+ .map((check) => check.name)
76
+ : [];
77
+ const settled =
78
+ failed.length === 0 && detail.checks.every((check) => check.status !== "pending");
79
+ owedChecks = owed;
80
if (passedNow && (!passed || gateGrew)) {
81
changes.push({ kind: "checks-passed", count: gate.length, required: required.length > 0 });
82
+ owedChecks =
83
+ required.length > 0
84
+ ? detail.checks
85
+ .filter((check) => check.required !== true && check.status === "pending")
86
+ .map((check) => check.name)
87
+ : [];
88
+ } else if (settled && owed.length > 0) {
89
+ changes.push({ kind: "checks-passed", count: detail.checks.length, required: false });
90
+ owedChecks = [];
91
}
92
passed = passedNow;
93
passedChecks = passedNow ? gateNames : [];
@@ -127,6 +148,7 @@ export function evaluatePullRequestWatch(
148
failedChecks,
149
passed,
150
passedChecks,
151
+ owedChecks,
152
remarksThrough,
153
remarkIds,
154
conflicting,
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+121
@@ -2622,6 +2622,127 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
2622
}),
2623
);
2624
2625
+ it.effect("finishes owed checks once after pending sweeps, a restart, and a re-watch", () =>
2626
+ Effect.gen(function* () {
2627
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
2628
+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2629
+ const threadId = ThreadId.make("runtime-pull-request-watch-owed");
2630
+ const projectId = ProjectId.make("pr-watch-owed-project");
2631
+ yield* seedProject({
2632
+ projectId,
2633
+ title: "Watch owed",
2634
+ workspaceRoot: "/workspace/watch-owed",
2635
+ defaultModelSelection: null,
2636
+ createdAt: "2026-10-01T00:00:00.000Z",
2637
+ });
2638
+ yield* orchestrator.dispatch({
2639
+ type: "thread.create",
2640
+ createdBy: "user",
2641
+ creationSource: "web",
2642
+ commandId: CommandId.make("pr-watch-owed-create"),
2643
+ threadId,
2644
+ projectId,
2645
+ title: "Watch owed",
2646
+ modelSelection,
2647
+ runtimeMode: "full-access",
2648
+ interactionMode: "default",
2649
+ branch: null,
2650
+ worktreePath: null,
2651
+ });
2652
+ const watch = (on: boolean, id: string) =>
2653
+ orchestrator.dispatch({
2654
+ type: "thread.pull-request.watch",
2655
+ commandId: CommandId.make(`pr-watch-owed-${id}`),
2656
+ threadId,
2657
+ host: "github.com",
2658
+ repository: "pingdotgg/t3code",
2659
+ number: 12,
2660
+ watching: on,
2661
+ link: { url: "https://github.com/pingdotgg/t3code/pull/12", source: "agent" },
2662
+ });
2663
+ yield* watch(true, "start");
2664
+
2665
+ let remainingStatus: "pending" | "success" = "pending";
2666
+ const host = Layer.mergeAll(
2667
+ NodeServices.layer,
2668
+ Layer.mock(PullRequestService.PullRequestService)({
2669
+ detail: () =>
2670
+ Effect.sync(() => ({
2671
+ ...watchedPullRequestDetail({
2672
+ projectId,
2673
+ number: 12,
2674
+ at: "2026-10-02T12:00:00.000Z",
2675
+ }),
2676
+ headSha: "ad70160aaa",
2677
+ checks: ["lint", "test"].map((name) => ({
2678
+ name,
2679
+ status: name === "test" ? remainingStatus : ("success" as const),
2680
+ description: null,
2681
+ url: null,
2682
+ required: name === "lint",
2683
+ })),
2684
+ })),
2685
+ activity: () =>
2686
+ Effect.succeed({
2687
+ comments: [],
2688
+ commentCount: 0,
2689
+ commentsTruncated: false,
2690
+ reviewThreads: [],
2691
+ commits: [],
2692
+ }),
2693
+ }),
2694
+ );
2695
+ const summaries = Effect.map(
2696
+ orchestrator.getThreadRecords(threadId, ["messages"]),
2697
+ ({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []),
2698
+ );
2699
+
2700
+ const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2701
+ yield* reactor.sweep;
2702
+ yield* worker.drain();
2703
+ yield* TestClock.adjust("10 minutes");
2704
+ yield* reactor.sweep;
2705
+ yield* worker.drain();
2706
+ assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2707
+
2708
+ assert.deepEqual(
2709
+ (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks,
2710
+ ["test"],
2711
+ );
2712
+ // The fresh reactor reloads the nonempty obligation from the persisted watch.
2713
+ const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2714
+ yield* restarted.sweep;
2715
+ yield* worker.drain();
2716
+ assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2717
+
2718
+ // A new watch on the same pull request knows what the last one told.
2719
+ yield* watch(false, "stop");
2720
+ yield* watch(true, "again");
2721
+ yield* restarted.sweep;
2722
+ yield* worker.drain();
2723
+ assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2724
+
2725
+ assert.deepEqual(
2726
+ (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks,
2727
+ ["test"],
2728
+ );
2729
+ remainingStatus = "success";
2730
+ yield* TestClock.adjust("10 minutes");
2731
+ yield* restarted.sweep;
2732
+ yield* worker.drain();
2733
+ assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]);
2734
+ yield* TestClock.adjust("10 minutes");
2735
+ yield* restarted.sweep;
2736
+ yield* worker.drain();
2737
+ assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]);
2738
+ assert.deepEqual(
2739
+ (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks,
2740
+ [],
2741
+ );
2742
+ yield* watch(false, "end");
2743
+ }),
2744
+ );
2745
+
2746
// regression: #21155 watching a pull request again repeated news the thread already got
2747
it.effect("a watch that ends on the comment limit keeps what its last pass saw", () =>
2748
Effect.gen(function* () {
packages/contracts/src/threadPullRequest.ts
+2
@@ -89,6 +89,8 @@ export const ThreadPullRequestWatch = Schema.Struct({
89
passedChecks: Schema.Array(TrimmedNonEmptyString).pipe(
90
Schema.withDecodingDefault(Effect.succeed([])),
91
),
92
+ /** Checks still pending when required ones passed early, owed one wake once all settle. */
93
+ owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
94
remarksThrough: IsoDateTime,
95
/** Remarks created exactly at `remarksThrough` that were reported, so a late one still counts. */
96
remarkIds: Schema.Array(TrimmedNonEmptyString),