Skip to content

Commit 8c33ab1

Browse files
fix(shared): settling on merge waits for the watch to wake the agent
A merged PR's watch held nothing, so with auto-settle on merge (the default) the thread settled milliseconds after the merge synced, before the watch read the merge. The watch then ended as "settled" and the agent never heard of it (osnoser1 on #25160, #29896). A merged PR's watch now holds until the watch reactor ends it, which it does in the same command that queues the wake. Test from factory/repro-29896. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cdb979e commit 8c33ab1

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ describe("derivePendingBackgroundWork kinds", () => {
411411
kind: "monitor",
412412
awaited: true,
413413
},
414+
{
415+
taskId: "pull-request-watch:github.com/acme/app#4",
416+
description: "Watching pull request #4",
417+
kind: "monitor",
418+
awaited: true,
419+
},
414420
{
415421
taskId: "pull-request-watch:github.com/acme/app#5",
416422
description: "Watching pull request #5",
@@ -431,6 +437,7 @@ describe("derivePendingBackgroundWork kinds", () => {
431437
}).map((task) => task.taskId),
432438
).toEqual([
433439
"pull-request-watch:github.com/acme/app#1",
440+
"pull-request-watch:github.com/acme/app#4",
434441
"pull-request-watch:github.com/acme/app#5",
435442
]);
436443
});
@@ -471,6 +478,20 @@ describe("derivePendingBackgroundWork kinds", () => {
471478
pullRequests: [{ ...link(1, {}), watch: { ...watch, checksPending: true } }],
472479
});
473480
expect(backgroundWorkHoldsCompletion(running)).toBe(true);
481+
482+
// Its watch has yet to wake the agent with the merge, so settling on merge waits for it.
483+
const merged = derivePendingBackgroundWork({
484+
latestRun: { id: "run-1" as never, ordinal: 1, status: "completed" },
485+
providerThreads: [],
486+
turnItems: [],
487+
pullRequests: [
488+
{
489+
...link(1, { state: "merged" }),
490+
watch: { ...watch, passed: true, checksPending: false },
491+
},
492+
],
493+
});
494+
expect(backgroundWorkHoldsCompletion(merged)).toBe(true);
474495
});
475496

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

‎packages/shared/src/orchestrationV2PendingBackgroundWork.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,7 @@ function pullRequestWatchTasks(
314314
pullRequests: ReadonlyArray<PendingBackgroundWorkPullRequest> | undefined,
315315
): Array<PendingBackgroundWorkTask> {
316316
return (pullRequests ?? []).flatMap((link) =>
317-
// A merged PR's watch ends at the next sweep, whose wake starts its own run, so it holds nothing.
318-
link.watch === undefined ||
319-
link.source === "stack-dismissed" ||
320-
link.snapshot?.state === "merged"
317+
link.watch === undefined || link.source === "stack-dismissed"
321318
? []
322319
: [
323320
{
@@ -327,7 +324,10 @@ function pullRequestWatchTasks(
327324
description: `Watching pull request #${link.number}`,
328325
kind: "monitor" as const,
329326
// Once every check finished, a person moves the PR next: the watch stays on but holds nothing.
330-
...(link.watch.checksPending === false ? {} : { awaited: true as const }),
327+
// A merged PR's watch holds until its read wakes the agent, so settling on merge waits.
328+
...(link.watch.checksPending === false && link.snapshot?.state !== "merged"
329+
? {}
330+
: { awaited: true as const }),
331331
},
332332
],
333333
);

0 commit comments

Comments
 (0)