Skip to content
TypeScript

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

Theo Browne2a738273e74e
diff --git a/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts b/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
index 91c827ed815..1b5331c0d1b 100644
--- a/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
+++ b/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
@@ -374,19 +374,26 @@ describe("derivePendingBackgroundWork kinds", () => {
};
const link = (
number: number,
- extra: { source?: "agent" | "stack-dismissed"; watched?: boolean },
+ extra: {
+ source?: "agent" | "stack-dismissed";
+ watched?: boolean;
+ state?: "open" | "closed" | "merged";
+ },
) => ({
host: "github.com",
repository: "acme/app",
number,
url: `https://github.com/acme/app/pull/${number}`,
source: extra.source ?? "agent",
+ snapshot: extra.state === undefined ? null : { state: extra.state },
...(extra.watched === false ? {} : { watch }),
});
const pullRequests = [
link(1, {}),
link(2, { watched: false }),
link(3, { source: "stack-dismissed" }),
+ link(4, { state: "merged" }),
+ link(5, { state: "closed" }),
];
it("keeps a settled run waiting on each visible watch, as an awaited monitor", () => {
@@ -403,6 +410,12 @@ describe("derivePendingBackgroundWork kinds", () => {
kind: "monitor",
awaited: true,
},
+ {
+ taskId: "pull-request-watch:github.com/acme/app#5",
+ description: "Watching pull request #5",
+ kind: "monitor",
+ awaited: true,
+ },
]);
expect(backgroundWorkHoldsCompletion(tasks)).toBe(true);
});
@@ -415,7 +428,10 @@ describe("derivePendingBackgroundWork kinds", () => {
turnItems: [],
pullRequests,
}).map((task) => task.taskId),
- ).toEqual(["pull-request-watch:github.com/acme/app#1"]);
+ ).toEqual([
+ "pull-request-watch:github.com/acme/app#1",
+ "pull-request-watch:github.com/acme/app#5",
+ ]);
});
it("lists no watch while a run is active", () => {
diff --git a/packages/shared/src/orchestrationV2PendingBackgroundWork.ts b/packages/shared/src/orchestrationV2PendingBackgroundWork.ts
index 6768d9359ff..6dc635b5153 100644
--- a/packages/shared/src/orchestrationV2PendingBackgroundWork.ts
+++ b/packages/shared/src/orchestrationV2PendingBackgroundWork.ts
@@ -112,7 +112,9 @@ type PendingBackgroundWorkRun = Pick<OrchestrationV2Run, "id" | "ordinal" | "sta
type PendingBackgroundWorkPullRequest = Pick<
ThreadPullRequestLink,
"host" | "repository" | "number" | "url" | "source" | "watch"
->;
+> & {
+ readonly snapshot: Pick<NonNullable<ThreadPullRequestLink["snapshot"]>, "state"> | null;
+};
type PendingBackgroundWorkProviderThread = Pick<
OrchestrationV2ProviderThread,
@@ -291,7 +293,10 @@ function pullRequestWatchTasks(
pullRequests: ReadonlyArray<PendingBackgroundWorkPullRequest> | undefined,
): Array<PendingBackgroundWorkTask> {
return (pullRequests ?? []).flatMap((link) =>
- link.watch === undefined || link.source === "stack-dismissed"
+ // The watch reactor ends a merged PR's watch without waking the agent, so it holds nothing.
+ link.watch === undefined ||
+ link.source === "stack-dismissed" ||
+ link.snapshot?.state === "merged"
? []
: [
{