Skip to content

Commit a2b03aa

Browse files
PR Batch Testerclaude
andcommitted
fix(server): a new pull request watch no longer repeats what the last one reported
A watch's state lived only on the watch, so ending it (settle, unwatch, or the read limit) threw it away. Watching the same pull request again started blank and woke the thread with "checks passed" for a head it had already been told about. Keep the ended watch on the link and start the next watch from its check and conflict state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9c16146 commit a2b03aa

4 files changed

Lines changed: 125 additions & 6 deletions

File tree

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,10 @@ function withPullRequestWatch(
534534
link: ThreadPullRequestLink,
535535
watch: ThreadPullRequestWatch | undefined,
536536
): ThreadPullRequestLink {
537-
const { watch: _previous, ...rest } = link;
538-
return watch === undefined ? rest : { ...rest, watch };
537+
const { watch: previous, endedWatch, ...rest } = link;
538+
if (watch !== undefined) return { ...rest, watch };
539+
const ended = previous ?? endedWatch;
540+
return ended === undefined ? rest : { ...rest, endedWatch: ended };
539541
}
540542

541543
function legacyPullRequestLink(
@@ -544,6 +546,9 @@ function legacyPullRequestLink(
544546
now: DateTime.Utc,
545547
): ThreadPullRequestLink {
546548
const key = legacyThreadPullRequestKey(linked);
549+
const existing = threadPullRequestsOf(thread).find((link) =>
550+
threadPullRequestKeysEqual(link, key),
551+
);
547552
return withPullRequestWatch(
548553
{
549554
...key,
@@ -552,8 +557,9 @@ function legacyPullRequestLink(
552557
linkedAt: DateTime.formatIso(now),
553558
snapshot: null,
554559
stack: null,
560+
...(existing?.endedWatch && { endedWatch: existing.endedWatch }),
555561
},
556-
threadPullRequestsOf(thread).find((link) => threadPullRequestKeysEqual(link, key))?.watch,
562+
existing?.watch,
557563
);
558564
}
559565

@@ -3136,9 +3142,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
31363142
failedChecks: [],
31373143
passed: false,
31383144
passedChecks: [],
3145+
conflicting: false,
3146+
// Watching again must not repeat check or conflict news the last watch told.
3147+
...(existing.endedWatch && {
3148+
headSha: existing.endedWatch.headSha,
3149+
failedChecks: existing.endedWatch.failedChecks,
3150+
passed: existing.endedWatch.passed,
3151+
passedChecks: existing.endedWatch.passedChecks,
3152+
conflicting: existing.endedWatch.conflicting,
3153+
}),
31393154
remarksThrough: startedAt,
31403155
remarkIds: [],
3141-
conflicting: false,
31423156
wakes: 0,
31433157
});
31443158
if (watch === existing.watch && links === linked) return thread;

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

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,10 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
23302330
commandId: CommandId.make(`pr-watch-settle-${mode}`),
23312331
threadId,
23322332
});
2333-
const expected = before.pullRequests?.map(({ watch: _watch, ...link }) => link);
2333+
const expected = before.pullRequests?.map(({ watch, ...link }) => ({
2334+
...link,
2335+
endedWatch: watch,
2336+
}));
23342337
assert.deepEqual((yield* orchestrator.getThreadShell(threadId))?.pullRequests, expected);
23352338
assert.isTrue((yield* maintenance.rebuild).valid);
23362339
assert.deepEqual((yield* orchestrator.getThreadShell(threadId))?.pullRequests, expected);
@@ -2649,6 +2652,105 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
26492652
}),
26502653
);
26512654

2655+
it.effect("wakes once for a state it reported, across a restart and a new watch", () =>
2656+
Effect.gen(function* () {
2657+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2658+
const threadId = ThreadId.make("runtime-pull-request-watch-told");
2659+
const projectId = ProjectId.make("pr-watch-told-project");
2660+
yield* seedProject({
2661+
projectId,
2662+
title: "Watch told",
2663+
workspaceRoot: "/workspace/watch-told",
2664+
defaultModelSelection: null,
2665+
createdAt: "2026-10-01T00:00:00.000Z",
2666+
});
2667+
yield* orchestrator.dispatch({
2668+
type: "thread.create",
2669+
createdBy: "user",
2670+
creationSource: "web",
2671+
commandId: CommandId.make("pr-watch-told-create"),
2672+
threadId,
2673+
projectId,
2674+
title: "Watch told",
2675+
modelSelection,
2676+
runtimeMode: "full-access",
2677+
interactionMode: "default",
2678+
branch: null,
2679+
worktreePath: null,
2680+
});
2681+
const watch = (on: boolean, id: string) =>
2682+
orchestrator.dispatch({
2683+
type: "thread.pull-request.watch",
2684+
commandId: CommandId.make(`pr-watch-told-${id}`),
2685+
threadId,
2686+
host: "github.com",
2687+
repository: "pingdotgg/t3code",
2688+
number: 12,
2689+
watching: on,
2690+
link: { url: "https://github.com/pingdotgg/t3code/pull/12", source: "agent" },
2691+
});
2692+
yield* watch(true, "start");
2693+
2694+
let headSha = "ad70160aaa";
2695+
const host = Layer.mergeAll(
2696+
NodeServices.layer,
2697+
Layer.mock(PullRequestService.PullRequestService)({
2698+
detail: () =>
2699+
Effect.sync(() => ({
2700+
...watchedPullRequestDetail({
2701+
projectId,
2702+
number: 12,
2703+
at: "2026-10-02T12:00:00.000Z",
2704+
}),
2705+
headSha,
2706+
checks: ["lint", "test"].map((name) => ({
2707+
name,
2708+
status: "success" as const,
2709+
description: null,
2710+
url: null,
2711+
required: true,
2712+
})),
2713+
})),
2714+
activity: () =>
2715+
Effect.succeed({
2716+
comments: [],
2717+
commentCount: 0,
2718+
commentsTruncated: false,
2719+
reviewThreads: [],
2720+
commits: [],
2721+
}),
2722+
}),
2723+
);
2724+
const summaries = Effect.map(
2725+
orchestrator.getThreadRecords(threadId, ["messages"]),
2726+
({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []),
2727+
);
2728+
2729+
const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2730+
yield* reactor.sweep;
2731+
yield* TestClock.adjust("10 minutes");
2732+
yield* reactor.sweep;
2733+
assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2734+
2735+
// A restart keeps nothing in memory; the watch state is all it has.
2736+
const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2737+
yield* restarted.sweep;
2738+
assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2739+
2740+
// A new watch on the same pull request knows what the last one told.
2741+
yield* watch(false, "stop");
2742+
yield* watch(true, "again");
2743+
yield* restarted.sweep;
2744+
assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2745+
2746+
headSha = "bbbbbbbbbb";
2747+
yield* TestClock.adjust("10 minutes");
2748+
yield* restarted.sweep;
2749+
assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]);
2750+
yield* watch(false, "end");
2751+
}),
2752+
);
2753+
26522754
it.effect("reports how long an ended watch was quiet", () =>
26532755
Effect.gen(function* () {
26542756
const orchestrator = yield* Orchestrator.OrchestratorV2;

‎docs/user/source-control.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +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. Subagents cannot watch pull requests; the thread that delegated to them does. To start or stop
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
287288
it yourself, use the row menu in the **Linked pull requests** panel. In the thread details card, a
288289
watched pull request shows an eye; click it to stop watching.
289290

‎packages/contracts/src/threadPullRequest.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,7 @@ export const ThreadPullRequestLink = Schema.Struct({
106106
snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
107107
stack: Schema.NullOr(ThreadPullRequestStack),
108108
watch: Schema.optional(ThreadPullRequestWatch),
109+
/** The last watch as it ended. Watching again starts from it, so the thread is not told twice. */
110+
endedWatch: Schema.optional(ThreadPullRequestWatch),
109111
});
110112
export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;

0 commit comments

Comments
 (0)