Skip to content

Commit c6d9cf3

Browse files
PR Batch Testerclaude
andcommitted
fix(server): side chats do not keep their parent's pages
Side chats are run forks that show only their own rows, so counting them as showers of the parent's pages kept those pages while the side chat lived. Deleting a parent also deletes its side chats in one plan, read before either commits, so the parent's pages were never cleaned up. The family query now treats a side chat as having no source history, the same rule inheritedRunFork applies to visible rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 14be78b commit c6d9cf3

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,11 @@ it.effect("SQL delete a fork family's pages once no live thread shows them", ()
14061406
const id = (name: string) => ThreadId.make(`thread:fork-pages:${family}:${name}`);
14071407
const runId = (thread: string, ordinal: number) =>
14081408
RunId.make(`run:fork-pages:${family}:${thread}:${ordinal}`);
1409-
const createThread = (name: string, forkedFrom?: { thread: string; ordinal: number }) =>
1409+
const createThread = (
1410+
name: string,
1411+
forkedFrom?: { thread: string; ordinal: number },
1412+
sideChat?: true,
1413+
) =>
14101414
store.apply({
14111415
id: EventId.make(`event:fork-pages:${family}:${name}`),
14121416
type: "thread.created",
@@ -1429,6 +1433,7 @@ it.effect("SQL delete a fork family's pages once no live thread shows them", ()
14291433
parentThreadId: forkedFrom === undefined ? null : id(forkedFrom.thread),
14301434
relationshipToParent: forkedFrom === undefined ? null : "fork",
14311435
rootThreadId: id("source"),
1436+
...(sideChat ? { sideChat } : {}),
14321437
},
14331438
forkedFrom:
14341439
forkedFrom === undefined
@@ -1532,7 +1537,8 @@ it.effect("SQL delete a fork family's pages once no live thread shows them", ()
15321537
});
15331538

15341539
// source: run 1 (page + MCP App), run 2 (page). fork: run 1 of source, then its own
1535-
// runs 1 and 2. nested: run 1 of fork.
1540+
// runs 1 and 2. nested: run 1 of fork. side: a side chat from run 1 of source, which
1541+
// shows only its own rows.
15361542
yield* createThread("source");
15371543
yield* createRun("source", 1);
15381544
yield* createRun("source", 2);
@@ -1545,6 +1551,7 @@ it.effect("SQL delete a fork family's pages once no live thread shows them", ()
15451551
const forkPage = yield* publish("fork", 1, "html_render");
15461552
const forkLater = yield* publish("fork", 2, "mcp_app");
15471553
yield* createThread("nested", { thread: "fork", ordinal: 1 });
1554+
yield* createThread("side", { thread: "source", ordinal: 1 }, true);
15481555
const pages = { sourcePage, sourceApp, sourceLater, forkPage, forkLater };
15491556
const deleteThread = (name: string) =>
15501557
Effect.gen(function* () {
@@ -1576,9 +1583,11 @@ it.effect("SQL delete a fork family's pages once no live thread shows them", ()
15761583
[...(yield* sourceFirst.deleteThread("nested"))],
15771584
[sourceFirst.pages.sourcePage, sourceFirst.pages.sourceApp, sourceFirst.pages.forkPage],
15781585
);
1586+
assert.sameMembers([...(yield* sourceFirst.deleteThread("side"))], []);
15791587

15801588
// Forks first: each thread's own pages go with the last thread that shows them.
15811589
const forksFirst = yield* createFamily("forks-first");
1590+
assert.sameMembers([...(yield* forksFirst.deleteThread("side"))], []);
15821591
assert.sameMembers([...(yield* forksFirst.deleteThread("nested"))], []);
15831592
assert.sameMembers(
15841593
[...(yield* forksFirst.deleteThread("fork"))],

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,10 @@ function sortMessagesByTurnItemOrder(
12081208
interface FamilyPageThread {
12091209
readonly id: ThreadId;
12101210
readonly deleted: boolean;
1211-
/** Ordinal of the source run a fork copied history through; null when that run is gone. */
1211+
/**
1212+
* Ordinal of the source run a fork copied history through; null when that run is gone.
1213+
* Null for side chats, which show only their own rows (`inheritedRunFork`).
1214+
*/
12121215
readonly forkedFrom: { readonly threadId: ThreadId; readonly runOrdinal: number | null } | null;
12131216
}
12141217

@@ -5408,6 +5411,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
54085411
FROM family
54095412
LEFT JOIN family AS source
54105413
ON json_extract(family.payload_json, '$.forkedFrom.type') = 'run'
5414+
AND json_extract(family.payload_json, '$.lineage.sideChat') IS NOT 1
54115415
AND source.thread_id = json_extract(family.payload_json, '$.forkedFrom.threadId')
54125416
LEFT JOIN orchestration_v2_projection_runs AS run
54135417
ON run.thread_id = source.thread_id

0 commit comments

Comments
 (0)