diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts index bb0b3380c38c4..f5d1cc89a59ca 100644 --- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts +++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts @@ -1367,7 +1367,7 @@ describe("PullRequestSyncReactor", () => { }), ); - it.effect("reads a settled thread's links once when it settles, then until unsettled", () => + it.effect("refreshes open links on settled threads on the slow cadence until terminal", () => Effect.gen(function* () { yield* TestClock.setTime(Date.parse(NOW)); const fixture = yield* makeHarness({ @@ -1379,6 +1379,7 @@ describe("PullRequestSyncReactor", () => { makeLink(5, { state: "open" }), makeLink(6, { state: "closed" }), makeLink(7), + makeLink(8, { state: "merged", mergedAt: "2026-08-20T00:00:00.000Z" }), ], }), ]), @@ -1386,7 +1387,11 @@ describe("PullRequestSyncReactor", () => { yield* Effect.gen(function* () { const reactor = yield* startAndSweep(fixture); - assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []); + // Open (#5) and unsynced (#7) links on settled thread are swept; closed (#6) and merged (#8) are not. + assert.deepStrictEqual( + (yield* Ref.getAndSet(fixture.summaryCalls, [])).map((call) => call.number).toSorted(), + [5, 7], + ); const threadId = ThreadId.make("settled"); const at = DateTime.makeUnsafe(NOW); @@ -1426,9 +1431,17 @@ describe("PullRequestSyncReactor", () => { (yield* Ref.getAndSet(fixture.summaryCalls, [])).map((call) => call.number).toSorted(), [5, 6], ); - for (let index = 0; index < 15; index += 1) yield* sweepAgain(fixture, reactor); + // Before SLOW_SYNC_INTERVAL_MS (15m), open link #5 is not re-swept. + for (let index = 0; index < 14; index += 1) yield* sweepAgain(fixture, reactor); assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []); + // At 15m, open (#5) and unsynced (#7) links are refreshed on the slow cadence; closed (#6) and merged (#8) stay quiet. + yield* sweepAgain(fixture, reactor); + assert.deepStrictEqual( + (yield* Ref.getAndSet(fixture.summaryCalls, [])).map((call) => call.number).toSorted(), + [5, 7], + ); + yield* Ref.update(fixture.snapshots, (snapshot) => ({ ...snapshot, threads: snapshot.threads.map((thread) => ({ @@ -1438,9 +1451,10 @@ describe("PullRequestSyncReactor", () => { })), })); yield* sweepAgain(fixture, reactor); + // After unsettling, #6 (closed, 15m since last read) and #7 (unsynced) are due; #5 was just refreshed 1m ago and is in quiet cooldown. assert.deepStrictEqual( (yield* Ref.get(fixture.summaryCalls)).map((call) => call.number).toSorted(), - [5, 6, 7], + [6, 7], ); }).pipe(Effect.provide(fixture.layer)); }), diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts index 96f0be4e59dc6..52af7f388f69d 100644 --- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts @@ -377,10 +377,18 @@ export const make = Effect.gen(function* () { const isDue = (key: string, entries: ReadonlyArray, nowMs: number): boolean => { if (requested.has(key)) return true; - const active = entries.filter((entry) => isUnsettled(entry.thread)); - if (active.length === 0) return false; const last = lastSyncedAt.get(key); const sinceLastMs = last === undefined ? Number.POSITIVE_INFINITY : nowMs - last; + const active = entries.filter((entry) => isUnsettled(entry.thread)); + if (active.length === 0) { + // Settled threads still refresh open/unsynced pull requests on the slow cadence so PRs + // merged or closed after settlement reach a terminal snapshot instead of staying "open". + const hasOpenSettled = entries.some( + (entry) => entry.link.snapshot === null || entry.link.snapshot.state === "open", + ); + if (!hasOpenSettled) return false; + return sinceLastMs >= SLOW_SYNC_INTERVAL_MS; + } if (missing.has(key)) return sinceLastMs >= SLOW_SYNC_INTERVAL_MS; if (retryStacks.has(key) || active.some((entry) => entry.link.snapshot === null)) return true; // Merged snapshots without mergedAt cannot settle threads; reread slowly until supplied. diff --git a/apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts b/apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts index 0b49669114a5c..dddfa5c6cd3fc 100644 --- a/apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts +++ b/apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts @@ -127,6 +127,37 @@ it("lane-ended stays quiet for a failure the model alert already reported as a u assert.deepEqual(findings, []); }); +it("lane-ended with open pull requests dedupes by open-PR set across runs, and clears on settle", () => { + const run1 = judge( + shellWith({ status: "completed", latestRunId: "run:1", pullRequests: [openPullRequest] } as never), + "run-ended", + ); + const run2 = judge( + shellWith({ status: "completed", latestRunId: "run:2", pullRequests: [openPullRequest] } as never), + "run-ended", + ); + const finding1 = run1.findings.find((finding) => finding.kind === "lane-ended"); + const finding2 = run2.findings.find((finding) => finding.kind === "lane-ended"); + assert.ok(finding1 && finding2); + assert.strictEqual(finding1.signature, finding2.signature); + assert.ok(finding1.signature.startsWith("open-prs:")); + + const settled = judge( + shellWith({ + status: "completed", + latestRunId: "run:2", + settledOverride: "settled", + pullRequests: [openPullRequest], + } as never), + "settled", + ); + assert.ok(settled.evaluated.includes("lane-ended")); + assert.deepEqual( + settled.findings.filter((finding) => finding.kind === "lane-ended"), + [], + ); +}); + it("promise-without-wake: flags the Fleet lane's real message when nothing is tracked", () => { const { findings } = judge( shellWith({ latestVisibleMessage: assistantSays(FLEET_PROMISE) } as never), diff --git a/apps/server/src/orchestration-v2/ThreadEventAlerts.ts b/apps/server/src/orchestration-v2/ThreadEventAlerts.ts index ecf01ad685a43..f2f4af3308a62 100644 --- a/apps/server/src/orchestration-v2/ThreadEventAlerts.ts +++ b/apps/server/src/orchestration-v2/ThreadEventAlerts.ts @@ -47,7 +47,7 @@ export type ThreadEventTrigger = "run-ended" | "settled" | "inbox" | "request" | const KINDS_BY_TRIGGER: Record> = { "run-ended": ["lane-ended", "promise-without-wake"], - settled: ["promise-without-wake"], + settled: ["lane-ended", "promise-without-wake"], inbox: ["needs-person"], request: ["needs-person"], sweep: ["stuck"], @@ -212,10 +212,14 @@ export function judgeThread(input: { prs.length > 0 && !hasWakeHandle(shell, remoteTaskCount, nowMs) ) { + const openPrSignature = prs + .map((link) => `${link.host ?? "github.com"}/${link.repository}#${link.number}`) + .toSorted() + .join(","); findings.push({ kind: "lane-ended", detail: `its last run completed with ${prs.length} open pull request${prs.length === 1 ? "" : "s"} and nothing tracked that will wake it`, - signature: shell.latestRunId, + signature: `open-prs:${openPrSignature}`, }); } }