@devries-cameron20 / t3code Mirror · read-only / commits / 2a738273e7
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, 13:15 UTC

fix(server): threads settle right away when a watched PR merges (#26395)

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

Theo Browne committed Oct 28, 2026 at 03:25 UTC 2a738273e74e2bc4637bb0977fa7818970760621
2 files changed +25 -4
packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
+18 -2
@@ -374,19 +374,26 @@ describe("derivePendingBackgroundWork kinds", () => {
374 };
375 const link = (
376 number: number,
377 - extra: { source?: "agent" | "stack-dismissed"; watched?: boolean },
377 + extra: {
378 + source?: "agent" | "stack-dismissed";
379 + watched?: boolean;
380 + state?: "open" | "closed" | "merged";
381 + },
382 ) => ({
383 host: "github.com",
384 repository: "acme/app",
385 number,
386 url: `https://github.com/acme/app/pull/${number}`,
387 source: extra.source ?? "agent",
388 + snapshot: extra.state === undefined ? null : { state: extra.state },
389 ...(extra.watched === false ? {} : { watch }),
390 });
391 const pullRequests = [
392 link(1, {}),
393 link(2, { watched: false }),
394 link(3, { source: "stack-dismissed" }),
395 + link(4, { state: "merged" }),
396 + link(5, { state: "closed" }),
397 ];
398
399 it("keeps a settled run waiting on each visible watch, as an awaited monitor", () => {
@@ -403,6 +410,12 @@ describe("derivePendingBackgroundWork kinds", () => {
410 kind: "monitor",
411 awaited: true,
412 },
413 + {
414 + taskId: "pull-request-watch:github.com/acme/app#5",
415 + description: "Watching pull request #5",
416 + kind: "monitor",
417 + awaited: true,
418 + },
419 ]);
420 expect(backgroundWorkHoldsCompletion(tasks)).toBe(true);
421 });
@@ -415,7 +428,10 @@ describe("derivePendingBackgroundWork kinds", () => {
428 turnItems: [],
429 pullRequests,
430 }).map((task) => task.taskId),
418 - ).toEqual(["pull-request-watch:github.com/acme/app#1"]);
431 + ).toEqual([
432 + "pull-request-watch:github.com/acme/app#1",
433 + "pull-request-watch:github.com/acme/app#5",
434 + ]);
435 });
436
437 it("lists no watch while a run is active", () => {
packages/shared/src/orchestrationV2PendingBackgroundWork.ts
+7 -2
@@ -112,7 +112,9 @@ type PendingBackgroundWorkRun = Pick<OrchestrationV2Run, "id" | "ordinal" | "sta
112 type PendingBackgroundWorkPullRequest = Pick<
113 ThreadPullRequestLink,
114 "host" | "repository" | "number" | "url" | "source" | "watch"
115 ->;
115 +> & {
116 + readonly snapshot: Pick<NonNullable<ThreadPullRequestLink["snapshot"]>, "state"> | null;
117 +};
118
119 type PendingBackgroundWorkProviderThread = Pick<
120 OrchestrationV2ProviderThread,
@@ -291,7 +293,10 @@ function pullRequestWatchTasks(
293 pullRequests: ReadonlyArray<PendingBackgroundWorkPullRequest> | undefined,
294 ): Array<PendingBackgroundWorkTask> {
295 return (pullRequests ?? []).flatMap((link) =>
294 - link.watch === undefined || link.source === "stack-dismissed"
296 + // The watch reactor ends a merged PR's watch without waking the agent, so it holds nothing.
297 + link.watch === undefined ||
298 + link.source === "stack-dismissed" ||
299 + link.snapshot?.state === "merged"
300 ? []
301 : [
302 {