Skip to content

Commit 2a73827

Browse files
t3dotggclaude
andauthored
fix(server): threads settle right away when a watched PR merges (#26395)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 80fcb7f commit 2a73827

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,26 @@ describe("derivePendingBackgroundWork kinds", () => {
374374
};
375375
const link = (
376376
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+
},
378382
) => ({
379383
host: "github.com",
380384
repository: "acme/app",
381385
number,
382386
url: `https://github.com/acme/app/pull/${number}`,
383387
source: extra.source ?? "agent",
388+
snapshot: extra.state === undefined ? null : { state: extra.state },
384389
...(extra.watched === false ? {} : { watch }),
385390
});
386391
const pullRequests = [
387392
link(1, {}),
388393
link(2, { watched: false }),
389394
link(3, { source: "stack-dismissed" }),
395+
link(4, { state: "merged" }),
396+
link(5, { state: "closed" }),
390397
];
391398

392399
it("keeps a settled run waiting on each visible watch, as an awaited monitor", () => {
@@ -403,6 +410,12 @@ describe("derivePendingBackgroundWork kinds", () => {
403410
kind: "monitor",
404411
awaited: true,
405412
},
413+
{
414+
taskId: "pull-request-watch:github.com/acme/app#5",
415+
description: "Watching pull request #5",
416+
kind: "monitor",
417+
awaited: true,
418+
},
406419
]);
407420
expect(backgroundWorkHoldsCompletion(tasks)).toBe(true);
408421
});
@@ -415,7 +428,10 @@ describe("derivePendingBackgroundWork kinds", () => {
415428
turnItems: [],
416429
pullRequests,
417430
}).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+
]);
419435
});
420436

421437
it("lists no watch while a run is active", () => {

‎packages/shared/src/orchestrationV2PendingBackgroundWork.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ type PendingBackgroundWorkRun = Pick<OrchestrationV2Run, "id" | "ordinal" | "sta
112112
type PendingBackgroundWorkPullRequest = Pick<
113113
ThreadPullRequestLink,
114114
"host" | "repository" | "number" | "url" | "source" | "watch"
115-
>;
115+
> & {
116+
readonly snapshot: Pick<NonNullable<ThreadPullRequestLink["snapshot"]>, "state"> | null;
117+
};
116118

117119
type PendingBackgroundWorkProviderThread = Pick<
118120
OrchestrationV2ProviderThread,
@@ -291,7 +293,10 @@ function pullRequestWatchTasks(
291293
pullRequests: ReadonlyArray<PendingBackgroundWorkPullRequest> | undefined,
292294
): Array<PendingBackgroundWorkTask> {
293295
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"
295300
? []
296301
: [
297302
{

0 commit comments

Comments
 (0)