History

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

Julius Marminge committed 3 months ago

Commit 7d42d311 parent e3883a943 files · +4239 −211Browse files

Showing the changes to apps/server/src/orchestration-v2/ShellStream.ts (1 of 43 files). Show all

Unified · Split

apps/server/src/orchestration-v2/ShellStream.ts+30−5
@@ -43,12 +43,20 @@ export function shellStreamItemFromEnrichmentRefresh(input: { · 42 unmodified lines
4343 readonly snapshot: OrchestrationV2ShellSnapshot;
4444 readonly changes: ReadonlyArray<{ readonly workspaceRoot: string }>;
4545 }): Extract<OrchestrationV2ShellStreamItem, { readonly kind: "snapshot" }> {
46+ const resolvedRepositoryIdentityRoots = [
47+ ...new Set(input.changes.map((change) => change.workspaceRoot)),
48+ ];
4649 return {
4750 kind: "snapshot",
48− snapshot: input.snapshot,
49− resolvedRepositoryIdentityRoots: [
50− ...new Set(input.changes.map((change) => change.workspaceRoot)),
51− ],
51+ snapshot: {
52+ ...input.snapshot,
53+ projects: input.snapshot.projects.filter((project) =>
54+ resolvedRepositoryIdentityRoots.includes(project.workspaceRoot),
55+ ),
56+ threads: [],
57+ archivedThreads: [],
58+ },
59+ resolvedRepositoryIdentityRoots,
5260 };
5361 }
5462
@@ -71,12 +79,29 @@ export function shellStreamItemsFromInitialSnapshot(input: { · 16 unmodified lines
7179 authoritative,
7280 {
7381 kind: "snapshot" as const,
74− snapshot: input.snapshot,
82+ snapshot: {
83+ ...input.snapshot,
84+ projects: input.snapshot.projects.filter((project) =>
85+ input.resolvedRepositoryIdentityRoots.includes(project.workspaceRoot),
86+ ),
87+ threads: [],
88+ archivedThreads: [],
89+ },
7590 resolvedRepositoryIdentityRoots: [...new Set(input.resolvedRepositoryIdentityRoots)],
7691 },
7792 ];
7893 }
7994
95+/** Resume after HTTP/cache hydration with metadata only, never another full shell body. */
96+export function shellStreamItemsFromResumeSnapshot(input: {
97+ readonly snapshot: OrchestrationV2ShellSnapshot;
98+ readonly resolvedRepositoryIdentityRoots: ReadonlyArray<string>;
99+}): ReadonlyArray<Extract<OrchestrationV2ShellStreamItem, { readonly kind: "snapshot" }>> {
100+ return shellStreamItemsFromInitialSnapshot(input).filter(
101+ (item) => item.resolvedRepositoryIdentityRoots !== undefined,
102+ );
103+}
104+
80105 /** Keep only the newest stored event per thread within a coalescing window. */
81106 export function coalesceStoredThreadEvents(
82107 events: ReadonlyArray<OrchestrationV2StoredEvent>,