TypeScript
fix(server): settled threads stop polling their pull requests (#16762)
Theo Browne453e596da7e9
diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.tsindex 98d37b0335e..8cc5808ed36 100644--- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts+++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts@@ -802,7 +802,7 @@ describe("PullRequestSyncReactor", () => {),);- it.effect("polls open pull requests on settled threads every fifteen minutes", () =>+ it.effect("leaves a settled thread's links unread until the thread is unsettled", () =>Effect.scoped(Effect.gen(function* () {yield* TestClock.setTime(Date.parse(NOW));@@ -811,29 +811,35 @@ describe("PullRequestSyncReactor", () => {makeThread("settled", {settledOverride: "settled",settledAt: "2026-08-21T00:00:00.000Z",- pullRequests: [makeLink(5, { state: "open" })],+ pullRequests: [makeLink(5, { state: "open" }), makeLink(6, { state: "closed" })],}),]),});yield* Effect.gen(function* () {const reactor = yield* startAndSweep(fixture);- assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);-- yield* sweepAgain(fixture, reactor);- assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);-- for (let index = 0; index < 13; index += 1) yield* sweepAgain(fixture, reactor);- assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);+ for (let index = 0; index < 15; index += 1) yield* sweepAgain(fixture, reactor);+ assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []);+ yield* Ref.update(fixture.snapshots, (snapshot) => ({+ ...snapshot,+ threads: snapshot.threads.map((thread) => ({+ ...thread,+ settledOverride: null,+ settledAt: null,+ })),+ }));yield* sweepAgain(fixture, reactor);- assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);+ assert.deepStrictEqual(+ (yield* Ref.get(fixture.summaryCalls)).map((call) => call.number).toSorted(),+ [5, 6],+ );}).pipe(Effect.provide(fixture.layer));}),),);- it.effect("auto-links missing native stack layers and leaves dismissed ones alone", () =>+ it.effect("auto-links missing native stack layers on active threads only", () =>Effect.scoped(Effect.gen(function* () {yield* TestClock.setTime(Date.parse(NOW));@@ -856,6 +862,11 @@ describe("PullRequestSyncReactor", () => {makeLink(41, { state: "merged" }, { source: "stack-dismissed" }),],}),+ makeThread("settled", {+ settledOverride: "settled",+ settledAt: "2026-08-21T00:00:00.000Z",+ pullRequests: [makeLink(42)],+ }),]),stack: () => Effect.succeed(stack),});@@ -865,8 +876,11 @@ describe("PullRequestSyncReactor", () => {const syncCommands = yield* Ref.get(fixture.syncCommands);assert.deepStrictEqual(- syncCommands.map((command) => [command.number, command.stack] as const),- [[42, { kind: "native", ...stack }]],+ syncCommands.map((command) => [command.threadId, command.stack] as const),+ [+ [ThreadId.make("one"), { kind: "native", ...stack }],+ [ThreadId.make("settled"), { kind: "native", ...stack }],+ ],);assert.deepStrictEqual((yield* Ref.get(fixture.linkCommands)).map(({ commandId: _, ...rest }) => rest),diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.tsindex c2862fa7f1c..5af4138bda9 100644--- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts+++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts@@ -172,10 +172,12 @@ export const make = Effect.gen(function* () {const isDue = (key: string, entries: ReadonlyArray<LinkEntry>, nowMs: number): boolean => {if (requested.has(key) || retryStacks.has(key)) return true;if (entries.some((entry) => entry.link.snapshot === null)) return true;- if (entries.every((entry) => entry.link.snapshot?.state === "merged")) return false;- if (entries.some((entry) => entry.link.snapshot?.state === "open" && isUnsettled(entry.thread)))- return true;- // Closed requests can reopen on the host, including after the thread settles.+ // Settled threads stop watching their pull requests. Unsettling one makes its links due on+ // the next sweep, since the cadence clock below kept running while it was settled.+ const active = entries.filter((entry) => isUnsettled(entry.thread));+ if (active.every((entry) => entry.link.snapshot?.state === "merged")) return false;+ if (active.some((entry) => entry.link.snapshot?.state === "open")) return true;+ // Closed requests can reopen on the host.const last = lastSyncedAt.get(key);return last === undefined || nowMs - last >= SLOW_SYNC_INTERVAL_MS;};@@ -222,8 +224,10 @@ export const make = Effect.gen(function* () {link.snapshot === null ||!snapshotFieldsEqual(link.snapshot, fields) ||!stacksEqual(link.stack, nextStack);- // Persist discovered siblings before a terminal snapshot can trigger settlement.- for (const layer of fetchedStack?.stack?.layers ?? []) {+ // Persist discovered siblings before a terminal snapshot can trigger settlement. A settled+ // thread that shares this pull request with an active one takes the fresh snapshot, but+ // gains no links.+ for (const layer of isUnsettled(thread) ? (fetchedStack?.stack?.layers ?? []) : []) {const layerKey = {host: normalizeThreadPullRequestKey(link).host,repository: link.repository,diff --git a/docs/user/source-control.md b/docs/user/source-control.mdindex 03c360ff3a1..344f4c97917 100644--- a/docs/user/source-control.md+++ b/docs/user/source-control.md@@ -195,7 +195,7 @@ Linking and unlinking are available in the web and desktop clients.The **Linked pull requests** panel lists every review and groups stacks. Unlink a review from itsrow menu. An unlinked stack layer stays out of later syncs. Open linked reviews refresh on the server;closed reviews refresh periodically so reopening one on the host is detected. Merged reviews refresh-when requested. With **Auto-settle merged threads** enabled, a thread can settle after every linked+when requested. A settled thread's reviews stop refreshing until you unsettle it. With **Auto-settle merged threads** enabled, a thread can settle after every linkedreview is terminal. An open or unsynced link keeps it active.Ask the agent to watch, monitor, or babysit a pull request and it calls `watch_pull_request`. While