Skip to content

Commit 393a39a

Browse files
fix(server): keep background thread updates out of the in-memory projection timestamp
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent ae8ecf6 commit 393a39a

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,70 @@ it.effect("memory projection keeps restart-cancelled work through a stale run.up
312312
restartCancelledWorkSurvivesStaleRunUpdate.pipe(Effect.provide(ProjectionStore.layerMemory)),
313313
);
314314

315+
// Clients read a failed thread's updatedAt as its failure edge, so background
316+
// writes must keep the orchestrator's timestamp in both stores.
317+
const backgroundThreadUpdatesKeepTimestamp = Effect.gen(function* () {
318+
const store = yield* ProjectionStore.ProjectionStoreV2;
319+
const createdAt = DateTime.makeUnsafe("2026-10-06T14:00:00.000Z");
320+
const threadId = ThreadId.make("thread:background-updates");
321+
const thread = {
322+
createdBy: "user" as const,
323+
creationSource: "web" as const,
324+
id: threadId,
325+
projectId: ProjectId.make("project:background-updates"),
326+
title: "Background updates",
327+
providerInstanceId,
328+
modelSelection,
329+
runtimeMode: "full-access" as const,
330+
interactionMode: "default" as const,
331+
branch: null,
332+
worktreePath: null,
333+
activeProviderThreadId: null,
334+
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
335+
forkedFrom: null,
336+
createdAt,
337+
updatedAt: createdAt,
338+
archivedAt: null,
339+
settledOverride: null,
340+
settledAt: null,
341+
lastVisitedAt: null,
342+
deletedAt: null,
343+
};
344+
yield* store.apply({
345+
id: EventId.make("event:background-updates:created"),
346+
type: "thread.created",
347+
threadId,
348+
occurredAt: createdAt,
349+
payload: thread,
350+
});
351+
yield* store.apply({
352+
id: EventId.make("event:background-updates:pull-request-synced"),
353+
type: "thread.pull-request-synced",
354+
threadId,
355+
occurredAt: DateTime.add(createdAt, { minutes: 45 }),
356+
payload: thread,
357+
});
358+
yield* store.apply({
359+
id: EventId.make("event:background-updates:active-reordered"),
360+
type: "thread.active-reordered",
361+
threadId,
362+
occurredAt: DateTime.add(createdAt, { minutes: 50 }),
363+
payload: { ...thread, activeOrderKey: "a" },
364+
});
365+
const projection = yield* store.getThreadProjection(threadId);
366+
assert.deepEqual(projection.thread.updatedAt, createdAt);
367+
assert.deepEqual(projection.updatedAt, createdAt);
368+
assert.deepEqual((yield* store.getThreadShell(threadId))?.updatedAt, createdAt);
369+
});
370+
371+
it.effect("memory projection keeps background thread updates out of updatedAt", () =>
372+
backgroundThreadUpdatesKeepTimestamp.pipe(Effect.provide(ProjectionStore.layerMemory)),
373+
);
374+
375+
it.effect("SQL projection keeps background thread updates out of updatedAt", () =>
376+
backgroundThreadUpdatesKeepTimestamp.pipe(Effect.provide(layerTest)),
377+
);
378+
315379
it.effect("memory recovery selection ignores unfinished items from rolled-back runs", () =>
316380
Effect.gen(function* () {
317381
const projectionStore = yield* ProjectionStore.ProjectionStoreV2;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,7 @@ export function applyToProjection(
661661
case "thread.pinned":
662662
case "thread.unpinned":
663663
case "thread.pin-reordered":
664-
case "thread.active-reordered":
665664
case "thread.metadata-updated":
666-
case "thread.pull-request-synced":
667665
case "thread.runtime-mode-updated":
668666
case "thread.interaction-mode-updated":
669667
case "thread.model-selection-updated":
@@ -672,6 +670,15 @@ export function applyToProjection(
672670
...base,
673671
thread: event.payload,
674672
};
673+
// Arranging and background PR refreshes are not activity: keep the
674+
// timestamp the orchestrator chose, as the SQL projection does.
675+
case "thread.active-reordered":
676+
case "thread.pull-request-synced":
677+
return {
678+
...base,
679+
thread: event.payload,
680+
updatedAt: event.payload.updatedAt,
681+
};
675682
// Visited tracking is read state, not activity: skip the updatedAt bump so
676683
// viewing a thread does not surface it as recently active.
677684
case "thread.visited":

0 commit comments

Comments
 (0)