Skip to content

Commit 1c6549f

Browse files
PR Batch Testerclaude
andcommitted
fix(server): keep a watch's last pass when it ends on the comment limit
Ending on the comment limit dropped that pass's state, so the kept watch could still say checks passed after they went pending, and a later green result would not wake. Save the pass before ending. Watching a dismissed stack layer again now keeps its ended watch too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a2b03aa commit 1c6549f

4 files changed

Lines changed: 207 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
31103110
const linked = threadPullRequestsOf(thread);
31113111
const visible = (link: ThreadPullRequestLink) =>
31123112
link.source !== "stack-dismissed" && threadPullRequestKeysEqual(link, key);
3113+
const dismissed = linked.find((link) => threadPullRequestKeysEqual(link, key));
31133114
const links =
31143115
command.type === "thread.pull-request.watch" &&
31153116
command.watching &&
@@ -3124,6 +3125,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
31243125
linkedAt: startedAt,
31253126
snapshot: null,
31263127
stack: null,
3128+
...(dismissed?.endedWatch && { endedWatch: dismissed.endedWatch }),
31273129
},
31283130
]
31293131
: linked;

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,18 @@ export const make = Effect.gen(function* () {
477477
yield* eachTarget(group, (target) => {
478478
const report = evaluatePullRequestWatch(target.watch, detail, remarks);
479479
if (report.changes.length > 0) {
480-
return record(
481-
target,
482-
report.exhausted ? null : report.next,
483-
pullRequestWatchMessage({
484-
number: target.link.number,
485-
url: target.link.url,
486-
baseBranch: detail.baseBranch,
487-
headSha: report.next.headSha,
488-
report,
489-
}),
480+
const wake = pullRequestWatchMessage({
481+
number: target.link.number,
482+
url: target.link.url,
483+
baseBranch: detail.baseBranch,
484+
headSha: report.next.headSha,
485+
report,
486+
});
487+
// Save what this pass saw before ending, so watching again starts from it.
488+
return (
489+
report.exhausted
490+
? record(target, report.next).pipe(Effect.andThen(record(target, null, wake)))
491+
: record(target, report.next, wake)
490492
).pipe(
491493
Effect.tap(() => woke(target)),
492494
Effect.tap(() => (report.exhausted ? ended(target, "comment-limit") : Effect.void)),

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

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import * as ProviderRuntimeRecoveryService from "./ProviderRuntimeRecoveryServic
6666
import * as ProjectionMaintenance from "./ProjectionMaintenance.ts";
6767
import * as ProjectionStore from "./ProjectionStore.ts";
6868
import * as PullRequestWatchReactor from "./PullRequestWatchReactor.ts";
69+
import { PULL_REQUEST_WATCH_WAKE_LIMIT } from "./pullRequestWatch.ts";
6970
import { PullRequestProviderError } from "@t3tools/source-control-core/server/PullRequestProvider";
7071
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
7172
import * as ProjectStore from "./ProjectStore.ts";
@@ -2751,6 +2752,196 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
27512752
}),
27522753
);
27532754

2755+
it.effect("a watch that ends on the comment limit keeps what its last pass saw", () =>
2756+
Effect.gen(function* () {
2757+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2758+
const threadId = ThreadId.make("runtime-pull-request-watch-limit");
2759+
const projectId = ProjectId.make("pr-watch-limit-project");
2760+
yield* seedProject({
2761+
projectId,
2762+
title: "Watch limit",
2763+
workspaceRoot: "/workspace/watch-limit",
2764+
defaultModelSelection: null,
2765+
createdAt: "2026-10-01T00:00:00.000Z",
2766+
});
2767+
yield* orchestrator.dispatch({
2768+
type: "thread.create",
2769+
createdBy: "user",
2770+
creationSource: "web",
2771+
commandId: CommandId.make("pr-watch-limit-create"),
2772+
threadId,
2773+
projectId,
2774+
title: "Watch limit",
2775+
modelSelection,
2776+
runtimeMode: "full-access",
2777+
interactionMode: "default",
2778+
branch: null,
2779+
worktreePath: null,
2780+
});
2781+
const key = { host: "github.com", repository: "pingdotgg/t3code", number: 13 };
2782+
const watch = (id: string) =>
2783+
orchestrator.dispatch({
2784+
type: "thread.pull-request.watch",
2785+
commandId: CommandId.make(`pr-watch-limit-${id}`),
2786+
threadId,
2787+
...key,
2788+
watching: true,
2789+
link: { url: "https://github.com/pingdotgg/t3code/pull/13", source: "agent" },
2790+
});
2791+
const watchOf = Effect.map(
2792+
orchestrator.getThreadShell(threadId),
2793+
(thread) => thread?.pullRequests?.[0],
2794+
);
2795+
yield* watch("start");
2796+
const started = (yield* watchOf)?.watch;
2797+
assert.isDefined(started);
2798+
if (started === undefined) return;
2799+
// Green checks were reported, and one more comment-only wake ends the watch.
2800+
yield* orchestrator.dispatch({
2801+
type: "thread.pull-request-watch.sync",
2802+
commandId: CommandId.make("pr-watch-limit-told"),
2803+
threadId,
2804+
...key,
2805+
startedAt: started.startedAt,
2806+
watch: {
2807+
...started,
2808+
headSha: "abc1234def",
2809+
passed: true,
2810+
passedChecks: ["lint"],
2811+
wakes: PULL_REQUEST_WATCH_WAKE_LIMIT - 1,
2812+
},
2813+
});
2814+
2815+
let status: "pending" | "success" = "pending";
2816+
const commentAt = DateTime.formatIso(
2817+
DateTime.add(DateTime.makeUnsafe(started.startedAt), { seconds: 1 }),
2818+
);
2819+
const host = Layer.mergeAll(
2820+
NodeServices.layer,
2821+
Layer.mock(PullRequestService.PullRequestService)({
2822+
detail: () =>
2823+
Effect.sync(() => ({
2824+
...watchedPullRequestDetail({ projectId, number: 13, at: commentAt }),
2825+
checks: [{ name: "lint", status, description: null, url: null, required: true }],
2826+
})),
2827+
activity: () =>
2828+
Effect.succeed({
2829+
comments: [
2830+
{
2831+
id: "reviewer-comment",
2832+
kind: "issue-comment" as const,
2833+
author: { login: "reviewer", name: null, avatarUrl: null },
2834+
body: "One more thing.",
2835+
createdAt: commentAt,
2836+
url: "https://github.com/pingdotgg/t3code/pull/13#comment",
2837+
path: null,
2838+
reviewState: null,
2839+
},
2840+
],
2841+
commentCount: 1,
2842+
commentsTruncated: false,
2843+
reviewThreads: [],
2844+
commits: [],
2845+
}),
2846+
}),
2847+
);
2848+
const summaries = Effect.map(
2849+
orchestrator.getThreadRecords(threadId, ["messages"]),
2850+
({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []),
2851+
);
2852+
const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2853+
yield* reactor.sweep;
2854+
const ended = yield* watchOf;
2855+
assert.isUndefined(ended?.watch);
2856+
assert.isFalse(ended?.endedWatch?.passed);
2857+
assert.deepEqual(yield* summaries, ["#13: new comments, stopped watching"]);
2858+
2859+
// The checks went pending after the last report, so passing again is news.
2860+
status = "success";
2861+
yield* TestClock.adjust("10 minutes");
2862+
yield* watch("again");
2863+
yield* reactor.sweep;
2864+
assert.deepEqual(yield* summaries, [
2865+
"#13: new comments, stopped watching",
2866+
"#13: checks passed",
2867+
]);
2868+
yield* orchestrator.dispatch({
2869+
type: "thread.pull-request.watch",
2870+
commandId: CommandId.make("pr-watch-limit-end"),
2871+
threadId,
2872+
...key,
2873+
watching: false,
2874+
});
2875+
}),
2876+
);
2877+
2878+
it.effect("watching a dismissed stack layer again keeps what its last watch told", () =>
2879+
Effect.gen(function* () {
2880+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2881+
const threadId = ThreadId.make("runtime-pull-request-watch-dismissed");
2882+
yield* orchestrator.dispatch({
2883+
type: "thread.create",
2884+
createdBy: "user",
2885+
creationSource: "web",
2886+
commandId: CommandId.make("pr-watch-dismissed-create"),
2887+
threadId,
2888+
projectId: ProjectId.make("pr-watch-dismissed-project"),
2889+
title: "Watch dismissed",
2890+
modelSelection,
2891+
runtimeMode: "full-access",
2892+
interactionMode: "default",
2893+
branch: null,
2894+
worktreePath: null,
2895+
});
2896+
const key = { host: "github.com", repository: "pingdotgg/t3code", number: 14 };
2897+
const url = "https://github.com/pingdotgg/t3code/pull/14";
2898+
const watchOf = Effect.map(
2899+
orchestrator.getThreadShell(threadId),
2900+
(thread) => thread?.pullRequests?.[0]?.watch,
2901+
);
2902+
yield* orchestrator.dispatch({
2903+
type: "thread.pull-request.link",
2904+
commandId: CommandId.make("pr-watch-dismissed-link"),
2905+
threadId,
2906+
...key,
2907+
url,
2908+
source: "stack",
2909+
});
2910+
const watching = (on: boolean, id: string) =>
2911+
orchestrator.dispatch({
2912+
type: "thread.pull-request.watch",
2913+
commandId: CommandId.make(`pr-watch-dismissed-${id}`),
2914+
threadId,
2915+
...key,
2916+
watching: on,
2917+
link: { url, source: "agent" },
2918+
});
2919+
yield* watching(true, "start");
2920+
const started = yield* watchOf;
2921+
assert.isDefined(started);
2922+
if (started === undefined) return;
2923+
yield* orchestrator.dispatch({
2924+
type: "thread.pull-request-watch.sync",
2925+
commandId: CommandId.make("pr-watch-dismissed-told"),
2926+
threadId,
2927+
...key,
2928+
startedAt: started.startedAt,
2929+
watch: { ...started, headSha: "abc1234def", passed: true, passedChecks: ["lint"] },
2930+
});
2931+
yield* orchestrator.dispatch({
2932+
type: "thread.pull-request.unlink",
2933+
commandId: CommandId.make("pr-watch-dismissed-unlink"),
2934+
threadId,
2935+
...key,
2936+
});
2937+
yield* watching(true, "again");
2938+
const again = yield* watchOf;
2939+
assert.equal(again?.headSha, "abc1234def");
2940+
assert.isTrue(again?.passed);
2941+
yield* watching(false, "end");
2942+
}),
2943+
);
2944+
27542945
it.effect("reports how long an ended watch was quiet", () =>
27552946
Effect.gen(function* () {
27562947
const orchestrator = yield* Orchestrator.OrchestratorV2;

‎docs/user/source-control.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ watching inside GitHub's rate limit. Comments from your own account do not wake
283283
when the pull request merges or closes, after 10 wakes in a row that bring only comments, after 8
284284
failed reads in a row, or when you press Stop on the thread. A rate limit only pauses watching.
285285
Settling or archiving a thread also ends all its watches. Unsettle the thread before starting a new
286-
watch. A new watch on the same pull request does not repeat check or conflict news an
287-
earlier watch already reported. Subagents cannot watch pull requests; the thread that delegated to them does. To start or stop
286+
watch. Watching a pull request again does not repeat check or conflict news its last
287+
watch already reported; unlinking the pull request clears that. Subagents cannot watch pull requests; the thread that delegated to them does. To start or stop
288288
it yourself, use the row menu in the **Linked pull requests** panel. In the thread details card, a
289289
watched pull request shows an eye; click it to stop watching.
290290

0 commit comments

Comments
 (0)