@devries-cameron20 / t3code Mirror · read-only / commits / b3c010909d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 19:30 UTC

fix(server): wake PR watches when no checks report (#23863)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 22, 2026 at 15:29 UTC b3c010909d6984ae128c70af0aad50e951737a63
7 files changed +312 -8
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?.checksAwaitedSince !== undefined && {
3404 + checksAwaitedSince: existing.endedWatch.checksAwaitedSince,
3405 + }),
3406 remarksThrough: startedAt,
3407 remarkIds: [],
3408 wakes: 0,
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+3 -2
@@ -174,7 +174,8 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
174 left.remarksThrough === right.remarksThrough &&
175 left.remarkIds.join("\n") === right.remarkIds.join("\n") &&
176 left.conflicting === right.conflicting &&
177 - left.wakes === right.wakes
177 + left.wakes === right.wakes &&
178 + left.checksAwaitedSince === right.checksAwaitedSince
179 );
180 }
181
@@ -539,7 +540,7 @@ export const make = Effect.gen(function* () {
540 remarks: fingerprint?.remarks ?? null,
541 });
542 yield* eachTarget(group, (target) => {
542 - const report = evaluatePullRequestWatch(target.watch, detail, remarks);
543 + const report = evaluatePullRequestWatch(target.watch, detail, remarks, now);
544 if (report.changes.length > 0) {
545 const wake = pullRequestWatchMessage({
546 number: target.link.number,
apps/server/src/orchestration-v2/pullRequestWatch.forgejoComments.test.ts
+8 -2
@@ -1,4 +1,4 @@
1 -import type { ThreadPullRequestWatch } from "@t3tools/contracts";
1 +import { SourceControlProviderKind, type ThreadPullRequestWatch } from "@t3tools/contracts";
2 import { assert, describe, it } from "@effect/vitest";
3 import * as Schema from "effect/Schema";
4 import {
@@ -6,7 +6,12 @@ import {
6 forgejoComment,
7 } from "@t3tools/source-control-forgejo/server/forgejoPullRequestJson";
8
9 -import { evaluatePullRequestWatch } from "./pullRequestWatch.ts";
9 +import { evaluatePullRequestWatch as evaluate } from "./pullRequestWatch.ts";
10 +
11 +// These cases read the head once or at one moment, so the no-checks notice never comes due.
12 +const evaluatePullRequestWatch = (
13 + ...args: Parameters<typeof evaluate> extends [...infer Head, number] ? Head : never
14 +) => evaluate(...args, 0);
15
16 const decodeForgejoComment = Schema.decodeSync(ForgejoComment);
17
@@ -25,6 +30,7 @@ describe("Forgejo comment watch boundary", () => {
30 wakes: 2,
31 } satisfies ThreadPullRequestWatch;
32 const finalDetail = {
33 + provider: SourceControlProviderKind.make("forgejo"),
34 headSha: seen.headSha,
35 checks: [],
36 mergeability: "mergeable",
apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+43 -3
@@ -1,11 +1,20 @@
1 -import type {
2 - PullRequestCheck,
1 +import {
2 + SourceControlProviderKind,
3 + type PullRequestCheck,
4 PullRequestComment,
5 ThreadPullRequestWatch,
6 } from "@t3tools/contracts";
7 import { assert, describe, it } from "@effect/vitest";
8
8 -import { PULL_REQUEST_WATCH_WAKE_LIMIT, evaluatePullRequestWatch } from "./pullRequestWatch.ts";
9 +import {
10 + PULL_REQUEST_WATCH_WAKE_LIMIT,
11 + evaluatePullRequestWatch as evaluate,
12 +} from "./pullRequestWatch.ts";
13 +
14 +// These cases read the head once or at one moment, so the no-checks notice never comes due.
15 +const evaluatePullRequestWatch = (
16 + ...args: Parameters<typeof evaluate> extends [...infer Head, number] ? Head : never
17 +) => evaluate(...args, 0);
18
19 const STARTED = "2026-10-02T12:00:00.000Z";
20
@@ -32,6 +41,7 @@ const check = (name: string, status: PullRequestCheck["status"]): PullRequestChe
41 type Detail = Parameters<typeof evaluatePullRequestWatch>[1];
42
43 const detail = (overrides: Partial<Detail> = {}): Detail => ({
44 + provider: SourceControlProviderKind.make("github"),
45 headSha: "aaaaaaaaaa",
46 checks: [check("lint", "success"), check("test", "pending")],
47 mergeability: "mergeable",
@@ -252,4 +262,34 @@ describe("evaluatePullRequestWatch", () => {
262 assert.isFalse(pushed.exhausted);
263 assert.equal(pushed.next.wakes, 1);
264 });
265 +
266 + const anHourLater = (
267 + first: ThreadPullRequestWatch,
268 + read: Detail,
269 + ): ReadonlyArray<ReadonlyArray<string>> => {
270 + const kinds: Array<ReadonlyArray<string>> = [];
271 + let current = first;
272 + for (let minute = 0; minute <= 60; minute += 10) {
273 + const { changes, next } = evaluate(current, read, noRemarks, minute * 60_000);
274 + kinds.push(changes.map((change) => change.kind));
275 + current = next;
276 + }
277 + return kinds;
278 + };
279 +
280 + it("does not tell a watch saved before the no-checks clock that its seen head has none", () => {
281 + // Such a watch may have seen this head's checks pending, which records nothing.
282 + const legacy = watch({ headSha: "aaaaaaaaaa" });
283 + assert.isTrue(anHourLater(legacy, detail({ checks: [] })).every((kinds) => kinds.length === 0));
284 + const pushed = anHourLater(legacy, detail({ headSha: "bbbbbbbbbb", checks: [] }));
285 + assert.deepEqual(pushed.flat(), ["no-checks"]);
286 + });
287 +
288 + it("never reports missing checks on a host whose checks it cannot read", () => {
289 + const azure = detail({
290 + provider: SourceControlProviderKind.make("azure-devops"),
291 + checks: [],
292 + });
293 + assert.isTrue(anHourLater(watch(), azure).every((kinds) => kinds.length === 0));
294 + });
295 });
apps/server/src/orchestration-v2/pullRequestWatch.ts
+32 -1
@@ -5,12 +5,15 @@ import type {
5 PullRequestDetail,
6 ThreadPullRequestWatch,
7 } from "@t3tools/contracts";
8 +import * as DateTime from "effect/DateTime";
9
10 /**
11 * Wakes in a row that bring only comments. Check, conflict, or push news resets the count, so
12 * this only stops a chatty bot looping an agent that is replying to it.
13 */
14 export const PULL_REQUEST_WATCH_WAKE_LIMIT = 10;
15 +/** How long a GitHub head may go without any check before the agent is told none reported. */
16 +const PULL_REQUEST_WATCH_NO_CHECKS_MS = 15 * 60_000;
17 const LISTED_ITEMS = 10;
18 const SNIPPET_LENGTH = 200;
19
@@ -18,6 +21,7 @@ export type PullRequestWatchChange =
21 | { readonly kind: "checks-failed"; readonly failed: ReadonlyArray<PullRequestCheck> }
22 | { readonly kind: "checks-passed"; readonly count: number; readonly required: boolean }
23 | { readonly kind: "remarks"; readonly remarks: ReadonlyArray<PullRequestComment> }
24 + | { readonly kind: "no-checks"; readonly minutes: number }
25 | { readonly kind: "conflicting" };
26
27 export interface PullRequestWatchReport {
@@ -32,8 +36,12 @@ const isFailedCheck = (check: PullRequestCheck) =>
36
37 export function evaluatePullRequestWatch(
38 watch: ThreadPullRequestWatch,
35 - detail: Pick<PullRequestDetail, "headSha" | "checks" | "mergeability" | "viewer" | "author">,
39 + detail: Pick<
40 + PullRequestDetail,
41 + "provider" | "headSha" | "checks" | "mergeability" | "viewer" | "author"
42 + >,
43 remarks: ReadonlyArray<PullRequestComment> | null,
44 + now: number,
45 ): PullRequestWatchReport {
46 const changes: Array<PullRequestWatchChange> = [];
47 const headSha = detail.headSha ?? null;
@@ -64,6 +72,23 @@ export function evaluatePullRequestWatch(
72 passedChecks = passedNow ? gateNames : [];
73 }
74
75 + // Only a head never read with checks waits for them: an empty read after checks were seen is
76 + // the failed read above. A watch saved before this field may have seen pending checks on its
77 + // head, so its clock starts only at the next push. Other hosts can lack a checks API (Azure
78 + // DevOps pipelines), where an empty list says nothing, so only GitHub waits.
79 + let checksAwaitedSince = watch.checksAwaitedSince;
80 + if (detail.provider === "github") {
81 + const awaitedBefore = headMoved
82 + ? DateTime.formatIso(DateTime.makeUnsafe(now))
83 + : (watch.checksAwaitedSince ?? null);
84 + checksAwaitedSince = detail.checks.length > 0 ? null : awaitedBefore;
85 + const awaitedMs = checksAwaitedSince === null ? 0 : now - Date.parse(checksAwaitedSince);
86 + if (awaitedMs >= PULL_REQUEST_WATCH_NO_CHECKS_MS) {
87 + changes.push({ kind: "no-checks", minutes: Math.round(awaitedMs / 60_000) });
88 + checksAwaitedSince = null;
89 + }
90 + }
91 +
92 const own = (detail.viewer ?? detail.author?.login)?.toLowerCase();
93 const through = Date.parse(watch.remarksThrough);
94 const activeAt = (remark: PullRequestComment) => remark.editedAt ?? remark.createdAt;
@@ -106,6 +131,7 @@ export function evaluatePullRequestWatch(
131 remarkIds,
132 conflicting,
133 wakes,
134 + checksAwaitedSince,
135 },
136 exhausted: commentsOnly && wakes >= PULL_REQUEST_WATCH_WAKE_LIMIT,
137 };
@@ -153,6 +179,10 @@ function changeLines(
179 return ` - ${remark.author?.login ?? "someone"}${where}: ${said}${remark.url ? ` ${remark.url}` : ""}`;
180 }),
181 ];
182 + case "no-checks":
183 + return [
184 + `- No checks have reported${context.commit} after ${change.minutes} minutes. None may be configured to run on this change.`,
185 + ];
186 case "conflicting":
187 return [`- The branch now conflicts with ${context.baseBranch}.`];
188 }
@@ -162,6 +192,7 @@ const SUMMARY: Record<PullRequestWatchChange["kind"], string> = {
192 "checks-failed": "checks failed",
193 "checks-passed": "checks passed",
194 remarks: "new comments",
195 + "no-checks": "no checks reported",
196 conflicting: "merge conflict",
197 };
198
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+218
@@ -2746,6 +2746,224 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
2746 }),
2747 );
2748
2749 + // regression: #23701 a head no check runs on never woke the watch
2750 + it.effect("wakes once when no checks report on the head, without saying they passed", () =>
2751 + Effect.gen(function* () {
2752 + const orchestrator = yield* Orchestrator.OrchestratorV2;
2753 + const threadId = ThreadId.make("runtime-pull-request-watch-no-checks");
2754 + const projectId = ProjectId.make("pr-watch-no-checks-project");
2755 + yield* seedProject({
2756 + projectId,
2757 + title: "Watch no checks",
2758 + workspaceRoot: "/workspace/watch-no-checks",
2759 + defaultModelSelection: null,
2760 + createdAt: "2026-10-01T00:00:00.000Z",
2761 + });
2762 + yield* orchestrator.dispatch({
2763 + type: "thread.create",
2764 + createdBy: "user",
2765 + creationSource: "web",
2766 + commandId: CommandId.make("pr-watch-no-checks-create"),
2767 + threadId,
2768 + projectId,
2769 + title: "Watch no checks",
2770 + modelSelection,
2771 + runtimeMode: "full-access",
2772 + interactionMode: "default",
2773 + branch: null,
2774 + worktreePath: null,
2775 + });
2776 + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 14 };
2777 + yield* orchestrator.dispatch({
2778 + type: "thread.pull-request.watch",
2779 + commandId: CommandId.make("pr-watch-no-checks-start"),
2780 + threadId,
2781 + ...key,
2782 + watching: true,
2783 + link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" },
2784 + });
2785 +
2786 + // A docs-only push that path filters keep every workflow off.
2787 + let headSha = "6074dd48ff";
2788 + let checks: PullRequestDetail["checks"] = [];
2789 + const host = Layer.mergeAll(
2790 + NodeServices.layer,
2791 + Layer.mock(PullRequestService.PullRequestService)({
2792 + detail: () =>
2793 + Effect.sync(() => ({
2794 + ...watchedPullRequestDetail({
2795 + projectId,
2796 + number: 14,
2797 + at: "2026-10-02T12:00:00.000Z",
2798 + }),
2799 + headSha,
2800 + checks,
2801 + })),
2802 + activity: () =>
2803 + Effect.succeed({
2804 + comments: [],
2805 + commentCount: 0,
2806 + commentsTruncated: false,
2807 + reviewThreads: [],
2808 + commits: [],
2809 + }),
2810 + }),
2811 + );
2812 + const wakes = Effect.map(
2813 + orchestrator.getThreadRecords(threadId, ["messages"]),
2814 + ({ messages }) =>
2815 + messages.filter(
2816 + (message) => message.notification !== undefined && message.notification !== null,
2817 + ),
2818 + );
2819 + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2820 + const anHourOfSweeps = Effect.gen(function* () {
2821 + for (let pass = 0; pass < 6; pass++) {
2822 + yield* reactor.sweep;
2823 + yield* TestClock.adjust("10 minutes");
2824 + }
2825 + yield* reactor.sweep;
2826 + });
2827 +
2828 + yield* anHourOfSweeps;
2829 + const told = yield* wakes;
2830 + assert.equal(told.length, 1, "one wake for a head with no checks");
2831 + assert.notMatch(told[0]!.text, /\bpass/i);
2832 + assert.notEqual(told[0]!.notification?.outcome, "completed");
2833 +
2834 + // An empty read on a head whose checks were seen is a failed read, not "no checks".
2835 + headSha = "7777777777";
2836 + checks = [{ name: "lint", status: "pending", description: null, url: null, required: true }];
2837 + // Without a fingerprint, a quiet pull request is read again only once the reread is due.
2838 + yield* TestClock.adjust("10 minutes");
2839 + yield* reactor.sweep;
2840 + checks = [];
2841 + yield* anHourOfSweeps;
2842 + assert.equal((yield* wakes).length, 1);
2843 +
2844 + yield* orchestrator.dispatch({
2845 + type: "thread.pull-request.watch",
2846 + commandId: CommandId.make("pr-watch-no-checks-end"),
2847 + threadId,
2848 + ...key,
2849 + watching: false,
2850 + });
2851 + }),
2852 + );
2853 +
2854 + it.effect("wakes for checks that complete after the no-checks notice on the same head", () =>
2855 + Effect.gen(function* () {
2856 + const orchestrator = yield* Orchestrator.OrchestratorV2;
2857 + const threadId = ThreadId.make("runtime-pull-request-watch-late-checks");
2858 + const projectId = ProjectId.make("pr-watch-late-checks-project");
2859 + yield* seedProject({
2860 + projectId,
2861 + title: "Watch late checks",
2862 + workspaceRoot: "/workspace/watch-late-checks",
2863 + defaultModelSelection: null,
2864 + createdAt: "2026-10-01T00:00:00.000Z",
2865 + });
2866 + yield* orchestrator.dispatch({
2867 + type: "thread.create",
2868 + createdBy: "user",
2869 + creationSource: "web",
2870 + commandId: CommandId.make("pr-watch-late-checks-create"),
2871 + threadId,
2872 + projectId,
2873 + title: "Watch late checks",
2874 + modelSelection,
2875 + runtimeMode: "full-access",
2876 + interactionMode: "default",
2877 + branch: null,
2878 + worktreePath: null,
2879 + });
2880 + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 14 };
2881 + yield* orchestrator.dispatch({
2882 + type: "thread.pull-request.watch",
2883 + commandId: CommandId.make("pr-watch-late-checks-start"),
2884 + threadId,
2885 + ...key,
2886 + watching: true,
2887 + link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" },
2888 + });
2889 +
2890 + const headSha = "6074dd48ff";
2891 + let checks: PullRequestDetail["checks"] = [];
2892 + const host = Layer.mergeAll(
2893 + NodeServices.layer,
2894 + Layer.mock(PullRequestService.PullRequestService)({
2895 + detail: () =>
2896 + Effect.sync(() => ({
2897 + ...watchedPullRequestDetail({
2898 + projectId,
2899 + number: 14,
2900 + at: "2026-10-02T12:00:00.000Z",
2901 + }),
2902 + headSha,
2903 + checks,
2904 + })),
2905 + activity: () =>
2906 + Effect.succeed({
2907 + comments: [],
2908 + commentCount: 0,
2909 + commentsTruncated: false,
2910 + reviewThreads: [],
2911 + commits: [],
2912 + }),
2913 + }),
2914 + );
2915 + const wakes = Effect.map(
2916 + orchestrator.getThreadRecords(threadId, ["messages"]),
2917 + ({ messages }) =>
2918 + messages.filter(
2919 + (message) => message.notification !== undefined && message.notification !== null,
2920 + ),
2921 + );
2922 + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2923 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2924 + const sweep = reactor.sweep.pipe(Effect.andThen(worker.drain()));
2925 + yield* sweep;
2926 + assert.lengthOf(yield* wakes, 0);
2927 + yield* TestClock.adjust("20 minutes");
2928 + yield* sweep;
2929 + const noChecks = yield* wakes;
2930 + assert.lengthOf(noChecks, 1);
2931 + assert.include(noChecks[0]!.text, "No checks have reported");
2932 + assert.equal(noChecks[0]!.notification?.outcome, "updated");
2933 +
2934 + checks = [{ name: "lint", status: "pending", description: null, url: null, required: true }];
2935 + yield* TestClock.adjust("10 minutes");
2936 + yield* sweep;
2937 + assert.lengthOf(yield* wakes, 1);
2938 +
2939 + checks = [{ name: "lint", status: "success", description: null, url: null, required: true }];
2940 + yield* TestClock.adjust("10 minutes");
2941 + yield* sweep;
2942 + const completed = yield* wakes;
2943 + assert.lengthOf(completed, 2);
2944 + assert.equal(completed[1]!.notification?.summary, "#14: checks passed");
2945 + assert.include(completed[1]!.text, "All 1 required check passed on 6074dd4.");
2946 + assert.equal(completed[1]!.notification?.outcome, "completed");
2947 +
2948 + yield* TestClock.adjust("1 hour");
2949 + yield* sweep;
2950 + const settled = yield* wakes;
2951 + assert.lengthOf(settled, 2);
2952 + assert.lengthOf(
2953 + settled.filter((message) => message.text.includes("No checks have reported")),
2954 + 1,
2955 + );
2956 + yield* orchestrator.dispatch({
2957 + type: "thread.pull-request.watch",
2958 + commandId: CommandId.make("pr-watch-late-checks-end"),
2959 + threadId,
2960 + ...key,
2961 + watching: false,
2962 + });
2963 + yield* worker.drain();
2964 + }),
2965 + );
2966 +
2967 // regression: #21155 watching a pull request again repeated news the thread already got
2968 it.effect("watching a dismissed stack layer again keeps what its last watch told", () =>
2969 Effect.gen(function* () {
packages/contracts/src/threadPullRequest.ts
+5
@@ -95,6 +95,11 @@ export const ThreadPullRequestWatch = Schema.Struct({
95 conflicting: Schema.Boolean,
96 /** Comment-only wakes in a row. Watching stops at a limit, so bots cannot loop it. */
97 wakes: NonNegativeInt,
98 + /**
99 + * When the head was first read without any check, until a check shows up or the agent is told
100 + * none did. Null once either happened; absent on watches saved before it existed.
101 + */
102 + checksAwaitedSince: Schema.optional(Schema.NullOr(IsoDateTime)),
103 });
104 export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
105