Skip to content

Commit 2ad9381

Browse files
fix(server): an open thread no longer keeps extra snapshots of streaming text
A client viewing a thread records thread.visited about every ten seconds. Each one ended the run of streaming snapshots in the event store, so a long reasoning item watched in the browser still left a full-text row per visit. Thread record events carry no run content and cannot change the order of messages or turn items, so they no longer end a run. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 04817a1 commit 2ad9381

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎apps/server/src/persistence/OrchestrationEventStore.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,46 @@ layer("OrchestrationEventStore", (it) => {
332332
}) satisfies OrchestrationV2DomainEvent;
333333
const storedTexts = sql<{ readonly text: string }>`
334334
SELECT json_extract(payload_json, '$.text') AS text FROM orchestration_events
335-
WHERE stream_id = ${threadId} ORDER BY sequence ASC
335+
WHERE stream_id = ${threadId} AND event_type = 'turn-item.updated'
336+
ORDER BY sequence ASC
336337
`.pipe(Effect.map((rows) => rows.map((row) => row.text)));
338+
const providerInstanceId = ProviderInstanceId.make("codex");
339+
// An open client records a visit every few seconds while the item streams.
340+
const visited = (index: number) =>
341+
({
342+
id: EventId.make(`event:long-stream:visited:${index}`),
343+
type: "thread.visited",
344+
threadId,
345+
occurredAt: now,
346+
payload: {
347+
id: threadId,
348+
projectId: ProjectId.make("project:long-stream"),
349+
title: "Thread",
350+
providerInstanceId,
351+
modelSelection: { instanceId: providerInstanceId, model: "gpt-5.4" },
352+
runtimeMode: "full-access",
353+
interactionMode: "default",
354+
branch: null,
355+
worktreePath: null,
356+
activeProviderThreadId: null,
357+
lineage: { rootThreadId: threadId, parentThreadId: null, relationshipToParent: null },
358+
forkedFrom: null,
359+
createdBy: "user",
360+
creationSource: "web",
361+
createdAt: now,
362+
updatedAt: now,
363+
archivedAt: null,
364+
settledOverride: null,
365+
settledAt: null,
366+
lastVisitedAt: now,
367+
deletedAt: null,
368+
},
369+
}) satisfies OrchestrationV2DomainEvent;
337370
const paragraph = `${"Checking the next case in detail. ".repeat(8)}\n\n`;
338371
let text = "";
339372
for (let index = 0; index < 300; index++) {
340373
text += paragraph;
374+
if (index % 20 === 0) yield* store.appendAgentEvents({ events: [visited(index)] });
341375
const [stored] = yield* store.appendAgentEvents({ events: [reasoning(index, text)] });
342376
// Live clients and the projections still get every snapshot.
343377
assert.deepEqual(stored?.event, reasoning(index, text));

‎apps/server/src/persistence/OrchestrationEventStore.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ const makeEventStore = Effect.gen(function* () {
549549
}
550550
const entityId = streamingTextEntityId(event);
551551
const snapshots = streamingSnapshots.get(event.threadId);
552-
streamingSnapshots.delete(event.threadId);
552+
// Thread record events, such as an open client's periodic thread.visited, carry no run
553+
// content and leave a run of snapshots unbroken.
554+
if (!event.type.startsWith("thread.")) streamingSnapshots.delete(event.threadId);
553555
if (entityId !== null && row !== undefined) {
554556
const previous = snapshots?.get(event.type);
555557
// Replay orders entities by first row, so only an unbroken run of one entity

0 commit comments

Comments
 (0)