Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -1379,14 +1379,19 @@ describe("PullRequestSyncReactor", () => {
makeLink(5, { state: "open" }),
makeLink(6, { state: "closed" }),
makeLink(7),
makeLink(8, { state: "merged", mergedAt: "2026-08-20T00:00:00.000Z" }),
],
}),
]),
});

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);
Expand Down Expand Up @@ -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) => ({
Expand All @@ -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));
}),
Expand Down
12 changes: 10 additions & 2 deletions apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,18 @@ export const make = Effect.gen(function* () {

const isDue = (key: string, entries: ReadonlyArray<LinkEntry>, 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.
Expand Down
31 changes: 31 additions & 0 deletions apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/orchestration-v2/ThreadEventAlerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type ThreadEventTrigger = "run-ended" | "settled" | "inbox" | "request" |

const KINDS_BY_TRIGGER: Record<ThreadEventTrigger, ReadonlyArray<ThreadEventKind>> = {
"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"],
Expand Down Expand Up @@ -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}`,
});
}
}
Expand Down
Loading