Skip to content

Commit 17eae24

Browse files
fix(server): activity on a thread unseen since restart refreshes linked-thread readers
Event history is not replayed at startup, so a thread linked before a restart was unknown to the detector until it emitted a full thread event, and its run and message activity never refreshed the order. Activity on a thread unseen since startup now counts as a possible reorder, under the same 10s limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1545bd3 commit 17eae24

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎apps/server/src/pullRequest/linkedThreads.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ it("signals when activity reorders the threads linked to a pull request", () =>
298298
url: "https://github.com/acme/web/pull/7",
299299
source: "agent",
300300
};
301-
const thread = (id: string, second: number) =>
301+
const thread = (id: string, second: number, pullRequests: ReadonlyArray<unknown> = [link]) =>
302302
({
303303
type: "thread.pull-request-synced",
304304
threadId: ThreadId.make(id),
@@ -307,7 +307,7 @@ it("signals when activity reorders the threads linked to a pull request", () =>
307307
projectId: ProjectId.make("project-a"),
308308
title: id,
309309
lineage: { rootThreadId: ThreadId.make(id) },
310-
pullRequests: [link],
310+
pullRequests,
311311
archivedAt: null,
312312
settledOverride: null,
313313
settledAt: null,
@@ -331,9 +331,13 @@ it("signals when activity reorders the threads linked to a pull request", () =>
331331
activity("a", 4),
332332
activity("b", 5),
333333
activity("b", 5),
334+
// Seen since startup without links, so its activity can't reorder an answer.
335+
thread("unlinked", 5, []),
334336
activity("unlinked", 6),
337+
// Not seen since startup, so it may be linked from before the restart.
338+
activity("persisted", 6),
335339
].map(changed),
336-
).toEqual(["reordered", "reordered", "reordered", null, null]);
340+
).toEqual(["reordered", "reordered", "reordered", null, "changed", null, "reordered"]);
337341

338342
// Other threads linked to the pull request may have had no event since the restart.
339343
const afterRestart = makeLinkedThreadsChangeDetector();

‎apps/server/src/pullRequest/linkedThreads.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ function linkedThreadsView(
9898

9999
/**
100100
* Tells how a domain event changed `pullRequests.linkedThreads` answers, so readers can refresh on
101-
* change instead of polling. `reordered` means a linked thread's activity moved, which can reorder
102-
* its answers. A thread's first event after a restart counts as a change, since its earlier links
103-
* are unknown.
101+
* change instead of polling. `reordered` means activity on a linked thread, or on one whose links
102+
* are unknown since a restart, which can reorder answers. A thread's first full event after a
103+
* restart counts as a change, since its earlier links are unknown.
104104
*/
105105
export function makeLinkedThreadsChangeDetector() {
106106
const views = new Map<ThreadId, string | null>();
@@ -115,8 +115,10 @@ export function makeLinkedThreadsChangeDetector() {
115115
return true;
116116
};
117117
return (event: OrchestrationV2DomainEvent): "changed" | "reordered" | null => {
118-
// The projection stamps every non-thread event as the thread's activity.
118+
// The projection stamps every non-thread event as the thread's activity. A thread not seen
119+
// since startup may be linked already, since history is not replayed.
119120
if (!event.type.startsWith("thread.")) {
121+
if (!views.has(event.threadId)) return "reordered";
120122
return active(event.threadId, event.occurredAt) ? "reordered" : null;
121123
}
122124
if (!("lineage" in event.payload)) return null;

0 commit comments

Comments
 (0)