Skip to content

Commit 23fe779

Browse files
committed
fix(server): settled threads read pull request status once on settle, then stop
1 parent 5324e7d commit 23fe779

3 files changed

Lines changed: 32 additions & 46 deletions

File tree

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts‎

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ describe("PullRequestSyncReactor", () => {
12531253
),
12541254
);
12551255

1256-
it.effect("reads a settled thread's unfinished links hourly, and at once when unsettled", () =>
1256+
it.effect("reads a settled thread's links once when it settles, then until unsettled", () =>
12571257
Effect.scoped(
12581258
Effect.gen(function* () {
12591259
yield* TestClock.setTime(Date.parse(NOW));
@@ -1262,44 +1262,20 @@ describe("PullRequestSyncReactor", () => {
12621262
makeThread("settled", {
12631263
settledOverride: "settled",
12641264
settledAt: "2026-08-21T00:00:00.000Z",
1265-
pullRequests: [
1266-
makeLink(5, { state: "open", updatedAt: NOW }),
1267-
makeLink(6, { state: "closed" }),
1268-
makeLink(7, { state: "merged", mergedAt: "2026-08-20T00:00:00.000Z" }),
1269-
],
1270-
}),
1271-
makeThread("active", {
1272-
pullRequests: [
1273-
makeLink(5, { state: "merged", mergedAt: "2026-08-20T00:00:00.000Z" }),
1274-
],
1265+
pullRequests: [makeLink(5, { state: "open" }), makeLink(6, { state: "closed" })],
12751266
}),
12761267
]),
12771268
});
1278-
const readNumbers = Effect.map(Ref.getAndSet(fixture.summaryCalls, []), (calls) =>
1279-
calls.map((call) => call.number).toSorted(),
1280-
);
12811269

12821270
yield* Effect.gen(function* () {
12831271
const reactor = yield* startAndSweep(fixture);
1284-
assert.deepStrictEqual(yield* readNumbers, [5, 6]);
1285-
for (let index = 0; index < 59; index += 1) yield* sweepAgain(fixture, reactor);
1286-
assert.deepStrictEqual(yield* readNumbers, []);
1287-
yield* sweepAgain(fixture, reactor);
1288-
assert.deepStrictEqual(yield* readNumbers, [5, 6]);
1272+
assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []);
12891273

1290-
yield* Ref.update(fixture.snapshots, (snapshot) => ({
1291-
...snapshot,
1292-
threads: snapshot.threads.map((thread) => ({
1293-
...thread,
1294-
settledOverride: null,
1295-
settledAt: null,
1296-
})),
1297-
}));
12981274
const threadId = ThreadId.make("settled");
12991275
const at = DateTime.makeUnsafe(NOW);
13001276
yield* Queue.offer(fixture.domainEvents, {
1301-
type: "thread.unsettled",
1302-
id: EventId.make("event:unsettled"),
1277+
type: "thread.settled",
1278+
id: EventId.make("event:settled"),
13031279
threadId,
13041280
occurredAt: at,
13051281
payload: {
@@ -1315,25 +1291,40 @@ describe("PullRequestSyncReactor", () => {
13151291
branch: null,
13161292
worktreePath: null,
13171293
activeProviderThreadId: null,
1318-
lineage: {
1319-
parentThreadId: null,
1320-
relationshipToParent: null,
1321-
rootThreadId: threadId,
1322-
},
1294+
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
13231295
forkedFrom: null,
13241296
createdAt: at,
13251297
updatedAt: at,
13261298
archivedAt: null,
1327-
settledOverride: null,
1328-
settledAt: null,
1299+
settledOverride: "settled",
1300+
settledAt: at,
13291301
lastVisitedAt: null,
13301302
deletedAt: null,
13311303
},
13321304
});
13331305
yield* Queue.take(fixture.snapshotReads);
13341306
yield* Queue.take(fixture.snapshotReads);
13351307
yield* reactor.drain;
1336-
assert.deepStrictEqual(yield* readNumbers, [5, 6]);
1308+
assert.deepStrictEqual(
1309+
(yield* Ref.getAndSet(fixture.summaryCalls, [])).map((call) => call.number).toSorted(),
1310+
[5, 6],
1311+
);
1312+
for (let index = 0; index < 15; index += 1) yield* sweepAgain(fixture, reactor);
1313+
assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []);
1314+
1315+
yield* Ref.update(fixture.snapshots, (snapshot) => ({
1316+
...snapshot,
1317+
threads: snapshot.threads.map((thread) => ({
1318+
...thread,
1319+
settledOverride: null,
1320+
settledAt: null,
1321+
})),
1322+
}));
1323+
yield* sweepAgain(fixture, reactor);
1324+
assert.deepStrictEqual(
1325+
(yield* Ref.get(fixture.summaryCalls)).map((call) => call.number).toSorted(),
1326+
[5, 6],
1327+
);
13371328
}).pipe(Effect.provide(fixture.layer));
13381329
}),
13391330
),

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.ts‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ const QUIET_SYNC_INTERVAL_MS = 5 * 60 * 1_000;
4747
// A pull request closed this long ago is rarely reopened, so the sweep stops reading it, as it
4848
// does merged ones. A reader that sees it open, or a requested refresh, still reads it at once.
4949
const CLOSED_FINAL_AFTER_MS = 24 * 60 * 60 * 1_000;
50-
// Settled threads can hold hundreds of links nobody watches, so their unfinished ones are read
51-
// hourly; unsettling the thread reads them at once.
52-
const SETTLED_SYNC_INTERVAL_MS = 60 * 60 * 1_000;
5350

5451
const isChangeRequestCloseCommand = (command: string) =>
5552
sourceControlDefinitions.definitions.some(
@@ -362,11 +359,9 @@ export const make = Effect.gen(function* () {
362359
? snapshot.mergedAt != null
363360
: snapshot?.state === "closed" &&
364361
nowMs - Date.parse(snapshot.closedAt ?? "") >= CLOSED_FINAL_AFTER_MS;
362+
if (active.every(isFinal)) return false;
365363
const last = lastSyncedAt.get(key);
366364
const sinceLastMs = last === undefined ? Number.POSITIVE_INFINITY : nowMs - last;
367-
if (active.every(isFinal)) {
368-
return !entries.every(isFinal) && sinceLastMs >= SETTLED_SYNC_INTERVAL_MS;
369-
}
370365
const open = active.filter((entry) => entry.link.snapshot?.state === "open");
371366
if (open.length > 0) {
372367
const quiet = open.every((entry) => {
@@ -719,7 +714,8 @@ export const make = Effect.gen(function* () {
719714
ended.add(item.id);
720715
return Effect.andThen(linked, refreshUnmergedLinks(event.threadId));
721716
}
722-
case "thread.unsettled":
717+
// Settled threads are not swept, so read their links once to settle with fresh status.
718+
case "thread.settled":
723719
return refreshUnmergedLinks(event.threadId);
724720
case "run.updated":
725721
return isTerminalRunStatus(event.payload.status) && closeCommands.delete(event.threadId)

‎docs/user/source-control.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ Linking and unlinking are available in the web and desktop clients.
298298
The **Linked pull requests** panel lists every review and groups stacks. Unlink a review from its
299299
row menu. An unlinked stack layer stays out of later syncs. Open linked reviews refresh on the server;
300300
closed reviews refresh periodically so reopening one on the host is detected. Merged reviews refresh
301-
when requested. A settled thread's open and recently closed reviews refresh about once an hour, and
302-
they refresh at once when you unsettle it. With **Auto-settle merged threads** enabled, a thread can settle after every linked
301+
when requested. Settling a thread refreshes its open and closed reviews once; after that they stop refreshing until you unsettle it. With **Auto-settle merged threads** enabled, a thread can settle after every linked
303302
review is terminal. An open or unsynced link keeps it active.
304303

305304
Ask the agent to watch, monitor, or babysit a pull request and it calls `watch_pull_request`. While

0 commit comments

Comments
 (0)