feat(orchestration): bound thread history and resume payloads

- Add paginated thread history with bounded snapshots and replay limits
- Trim oversized wire payloads and support progressive mobile history loading
This commit is contained in:
Julius Marminge committed 2026-08-14 11:23:51 +02:00
1 parent c03c9926ad
commit 402fde73dd
43 files changed
+4239 -211

No files matched your search

@@ -5,6 +5,7 @@ import type {
OrchestrationV2StoredEvent,
OrchestrationV2ThreadShell,
} from "@t3tools/contracts";
import { ThreadId } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
@@ -16,6 +17,7 @@ import {
shellStreamItemFromEnrichmentRefresh,
shellStreamItemFromThreadShell,
shellStreamItemsFromInitialSnapshot,
shellStreamItemsFromResumeSnapshot,
} from "./ShellStream.ts";
function project(sequence: number, id: string): ApplicationStoredEvent {
@@ -198,6 +200,35 @@ describe("shellStreamItemFromEnrichmentRefresh", () => {
});
describe("shellStreamItemsFromInitialSnapshot", () => {
it("keeps thread rows out of the metadata-only enrichment frame", () => {
const snapshot = {
...emptyShellSnapshot,
projects: [
{ id: "project-a", workspaceRoot: "/workspace/a" },
{ id: "project-b", workspaceRoot: "/workspace/b" },
],
threads: [shellFixture({})],
archivedThreads: [shellFixture({ id: ThreadId.make("thread-archived"), archivedAt: null })],
} as unknown as OrchestrationV2ShellSnapshot;
const items = shellStreamItemsFromInitialSnapshot({
snapshot,
resolvedRepositoryIdentityRoots: ["/workspace/a"],
});
expect(items[0]).toEqual({ kind: "snapshot", snapshot });
expect(items[1]).toMatchObject({
kind: "snapshot",
snapshot: {
projects: [{ id: "project-a", workspaceRoot: "/workspace/a" }],
threads: [],
archivedThreads: [],
},
resolvedRepositoryIdentityRoots: ["/workspace/a"],
});
expect(JSON.stringify(items[1]).length).toBeLessThan(JSON.stringify(items[0]).length);
});
it("emits unmarked authoritative then same-sequence marked enrichment when roots resolved", () => {
const snapshot = {
...emptyShellSnapshot,
@@ -229,6 +260,20 @@ describe("shellStreamItemsFromInitialSnapshot", () => {
});
});
describe("shellStreamItemsFromResumeSnapshot", () => {
it("never repeats the authoritative shell snapshot", () => {
expect(
shellStreamItemsFromResumeSnapshot({
snapshot: {
...emptyShellSnapshot,
threads: [shellFixture({})],
},
resolvedRepositoryIdentityRoots: [],
}),
).toEqual([]);
});
});
describe("composeShellStreamWithEnrichment", () => {
it.effect(
"emits every initial item before enrichment even when enrichment is already ready",