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 23, 03:00 UTC
fix(server): watching a pull request again no longer repeats news the thread already got (#21155)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 19, 2026 at 01:21 UTC
24c71ebdd7f54318f9d058dba09d680030ce74d1
6 files changed
+341
-17
apps/server/src/orchestration-v2/Orchestrator.ts
+27
-5
@@ -535,8 +535,10 @@ function withPullRequestWatch(
535
link: ThreadPullRequestLink,
536
watch: ThreadPullRequestWatch | undefined,
537
): ThreadPullRequestLink {
538
- const { watch: _previous, ...rest } = link;
539
- return watch === undefined ? rest : { ...rest, watch };
538
+ const { watch: previous, endedWatch, ...rest } = link;
539
+ if (watch !== undefined) return { ...rest, watch };
540
+ const ended = previous ?? endedWatch;
541
+ return ended === undefined ? rest : { ...rest, endedWatch: ended };
542
}
543
544
function legacyPullRequestLink(
@@ -545,6 +547,9 @@ function legacyPullRequestLink(
547
now: DateTime.Utc,
548
): ThreadPullRequestLink {
549
const key = legacyThreadPullRequestKey(linked);
550
+ const existing = threadPullRequestsOf(thread).find((link) =>
551
+ threadPullRequestKeysEqual(link, key),
552
+ );
553
return withPullRequestWatch(
554
{
555
...key,
@@ -553,8 +558,9 @@ function legacyPullRequestLink(
558
linkedAt: DateTime.formatIso(now),
559
snapshot: null,
560
stack: null,
561
+ ...(existing?.endedWatch && { endedWatch: existing.endedWatch }),
562
},
557
- threadPullRequestsOf(thread).find((link) => threadPullRequestKeysEqual(link, key))?.watch,
563
+ existing?.watch,
564
);
565
}
566
@@ -3121,6 +3127,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3127
const linked = threadPullRequestsOf(thread);
3128
const visible = (link: ThreadPullRequestLink) =>
3129
link.source !== "stack-dismissed" && threadPullRequestKeysEqual(link, key);
3130
+ const dismissed = linked.find((link) => threadPullRequestKeysEqual(link, key));
3131
const links =
3132
command.type === "thread.pull-request.watch" &&
3133
command.watching &&
@@ -3135,6 +3142,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3142
linkedAt: startedAt,
3143
snapshot: null,
3144
stack: null,
3145
+ ...(dismissed?.endedWatch && { endedWatch: dismissed.endedWatch }),
3146
},
3147
]
3148
: linked;
@@ -3153,16 +3161,30 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3161
failedChecks: [],
3162
passed: false,
3163
passedChecks: [],
3164
+ conflicting: false,
3165
+ // Watching again must not repeat check or conflict news the last watch told.
3166
+ ...(existing.endedWatch && {
3167
+ headSha: existing.endedWatch.headSha,
3168
+ failedChecks: existing.endedWatch.failedChecks,
3169
+ passed: existing.endedWatch.passed,
3170
+ passedChecks: existing.endedWatch.passedChecks,
3171
+ conflicting: existing.endedWatch.conflicting,
3172
+ }),
3173
remarksThrough: startedAt,
3174
remarkIds: [],
3158
- conflicting: false,
3175
wakes: 0,
3176
});
3177
if (watch === existing.watch && links === linked) return thread;
3178
+ const final =
3179
+ command.type === "thread.pull-request-watch.sync" && watch === undefined
3180
+ ? command.endedWatch
3181
+ : undefined;
3182
return {
3183
...thread,
3184
pullRequests: links.map((link) =>
3165
- link === existing ? withPullRequestWatch(link, watch) : link,
3185
+ link === existing
3186
+ ? withPullRequestWatch(final ? { ...link, watch: final } : link, watch)
3187
+ : link,
3188
),
3189
updatedAt: command.type === "thread.pull-request.watch" ? now : thread.updatedAt,
3190
};
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+14
-10
@@ -259,6 +259,7 @@ export const make = Effect.gen(function* () {
259
target: WatchTarget,
260
next: ThreadPullRequestWatch | null,
261
wake?: { readonly text: string; readonly notification: OrchestrationV2Notification },
262
+ endedWatch?: ThreadPullRequestWatch,
263
) =>
264
Effect.gen(function* () {
265
const uuid = yield* crypto.randomUUIDv4();
@@ -269,6 +270,7 @@ export const make = Effect.gen(function* () {
270
...identityOf(target.link),
271
startedAt: target.watch.startedAt,
272
watch: next,
273
+ ...(endedWatch === undefined ? {} : { endedWatch }),
274
...(wake === undefined
275
? {}
276
: { wake: { ...wake, messageId: MessageId.make(`message:pr-watch:${uuid}`) } }),
@@ -477,16 +479,18 @@ export const make = Effect.gen(function* () {
479
yield* eachTarget(group, (target) => {
480
const report = evaluatePullRequestWatch(target.watch, detail, remarks);
481
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
- }),
482
+ const wake = pullRequestWatchMessage({
483
+ number: target.link.number,
484
+ url: target.link.url,
485
+ baseBranch: detail.baseBranch,
486
+ headSha: report.next.headSha,
487
+ report,
488
+ });
489
+ // An ending watch keeps what this pass saw, so watching again starts from it.
490
+ return (
491
+ report.exhausted
492
+ ? record(target, null, wake, report.next)
493
+ : record(target, report.next, wake)
494
).pipe(
495
Effect.tap(() => woke(target)),
496
Effect.tap(() => (report.exhausted ? ended(target, "comment-limit") : Effect.void)),
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+294
-1
@@ -66,6 +66,7 @@ import * as ProviderRuntimeRecoveryService from "./ProviderRuntimeRecoveryServic
66
import * as ProjectionMaintenance from "./ProjectionMaintenance.ts";
67
import * as ProjectionStore from "./ProjectionStore.ts";
68
import * as PullRequestWatchReactor from "./PullRequestWatchReactor.ts";
69
+import { PULL_REQUEST_WATCH_WAKE_LIMIT } from "./pullRequestWatch.ts";
70
import { PullRequestProviderError } from "@t3tools/source-control-core/server/PullRequestProvider";
71
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
72
import * as ProjectStore from "./ProjectStore.ts";
@@ -2330,7 +2331,10 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
2331
commandId: CommandId.make(`pr-watch-settle-${mode}`),
2332
threadId,
2333
});
2333
- const expected = before.pullRequests?.map(({ watch: _watch, ...link }) => link);
2334
+ const expected = before.pullRequests?.map(({ watch, ...link }) => ({
2335
+ ...link,
2336
+ endedWatch: watch,
2337
+ }));
2338
assert.deepEqual((yield* orchestrator.getThreadShell(threadId))?.pullRequests, expected);
2339
assert.isTrue((yield* maintenance.rebuild).valid);
2340
assert.deepEqual((yield* orchestrator.getThreadShell(threadId))?.pullRequests, expected);
@@ -2649,6 +2653,295 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
2653
}),
2654
);
2655
2656
+ it.effect("wakes once for a state it reported, across a restart and a new watch", () =>
2657
+ Effect.gen(function* () {
2658
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
2659
+ const threadId = ThreadId.make("runtime-pull-request-watch-told");
2660
+ const projectId = ProjectId.make("pr-watch-told-project");
2661
+ yield* seedProject({
2662
+ projectId,
2663
+ title: "Watch told",
2664
+ workspaceRoot: "/workspace/watch-told",
2665
+ defaultModelSelection: null,
2666
+ createdAt: "2026-10-01T00:00:00.000Z",
2667
+ });
2668
+ yield* orchestrator.dispatch({
2669
+ type: "thread.create",
2670
+ createdBy: "user",
2671
+ creationSource: "web",
2672
+ commandId: CommandId.make("pr-watch-told-create"),
2673
+ threadId,
2674
+ projectId,
2675
+ title: "Watch told",
2676
+ modelSelection,
2677
+ runtimeMode: "full-access",
2678
+ interactionMode: "default",
2679
+ branch: null,
2680
+ worktreePath: null,
2681
+ });
2682
+ const watch = (on: boolean, id: string) =>
2683
+ orchestrator.dispatch({
2684
+ type: "thread.pull-request.watch",
2685
+ commandId: CommandId.make(`pr-watch-told-${id}`),
2686
+ threadId,
2687
+ host: "github.com",
2688
+ repository: "pingdotgg/t3code",
2689
+ number: 12,
2690
+ watching: on,
2691
+ link: { url: "https://github.com/pingdotgg/t3code/pull/12", source: "agent" },
2692
+ });
2693
+ yield* watch(true, "start");
2694
+
2695
+ let headSha = "ad70160aaa";
2696
+ const host = Layer.mergeAll(
2697
+ NodeServices.layer,
2698
+ Layer.mock(PullRequestService.PullRequestService)({
2699
+ detail: () =>
2700
+ Effect.sync(() => ({
2701
+ ...watchedPullRequestDetail({
2702
+ projectId,
2703
+ number: 12,
2704
+ at: "2026-10-02T12:00:00.000Z",
2705
+ }),
2706
+ headSha,
2707
+ checks: ["lint", "test"].map((name) => ({
2708
+ name,
2709
+ status: "success" as const,
2710
+ description: null,
2711
+ url: null,
2712
+ required: true,
2713
+ })),
2714
+ })),
2715
+ activity: () =>
2716
+ Effect.succeed({
2717
+ comments: [],
2718
+ commentCount: 0,
2719
+ commentsTruncated: false,
2720
+ reviewThreads: [],
2721
+ commits: [],
2722
+ }),
2723
+ }),
2724
+ );
2725
+ const summaries = Effect.map(
2726
+ orchestrator.getThreadRecords(threadId, ["messages"]),
2727
+ ({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []),
2728
+ );
2729
+
2730
+ const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2731
+ yield* reactor.sweep;
2732
+ yield* TestClock.adjust("10 minutes");
2733
+ yield* reactor.sweep;
2734
+ assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2735
+
2736
+ // A restart keeps nothing in memory; the watch state is all it has.
2737
+ const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2738
+ yield* restarted.sweep;
2739
+ assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2740
+
2741
+ // A new watch on the same pull request knows what the last one told.
2742
+ yield* watch(false, "stop");
2743
+ yield* watch(true, "again");
2744
+ yield* restarted.sweep;
2745
+ assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2746
+
2747
+ headSha = "bbbbbbbbbb";
2748
+ yield* TestClock.adjust("10 minutes");
2749
+ yield* restarted.sweep;
2750
+ assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]);
2751
+ yield* watch(false, "end");
2752
+ }),
2753
+ );
2754
+
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
+
2945
it.effect("reports how long an ended watch was quiet", () =>
2946
Effect.gen(function* () {
2947
const orchestrator = yield* Orchestrator.OrchestratorV2;
docs/user/source-control.md
+2
-1
@@ -283,7 +283,8 @@ watching inside GitHub's rate limit. Comments from your own account do not wake
283
when the pull request merges or closes, after 10 wakes in a row that bring only comments, after 8
284
failed reads in a row, or when you press Stop on the thread. A rate limit only pauses watching.
285
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. 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
288
it yourself, use the row menu in the **Linked pull requests** panel. In the thread details card, a
289
watched pull request shows an eye; click it to stop watching.
290
packages/contracts/src/orchestrationV2.ts
+2
@@ -2994,6 +2994,8 @@ const OrchestrationV2InternalCommand = Schema.Union([
2994
...ThreadPullRequestKey.fields,
2995
startedAt: IsoDateTime,
2996
watch: Schema.NullOr(ThreadPullRequestWatch),
2997
+ /** With `watch: null`, the state the ended watch keeps instead of its last saved one. */
2998
+ endedWatch: Schema.optional(ThreadPullRequestWatch),
2999
wake: Schema.optional(
3000
Schema.Struct({
3001
messageId: MessageId,
packages/contracts/src/threadPullRequest.ts
+2
@@ -106,5 +106,7 @@ export const ThreadPullRequestLink = Schema.Struct({
106
snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
107
stack: Schema.NullOr(ThreadPullRequestStack),
108
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),
111
});
112
export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;