perf(server): build the thread list snapshot without decoding it twice (#13693)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-09-25 20:28:03 -07:00
1 parent 574b180902
commit b6eefc926a
1 file changed
+8 -22
@@ -12,7 +12,7 @@ import {
OrchestrationProposedPlanId,
OrchestrationReadModel,
OrchestrationThreadSearchSource,
OrchestrationShellSnapshot,
type OrchestrationShellSnapshot,
OrchestrationThread,
OrchestrationThreadDetailSnapshot,
ProjectScript,
@@ -82,7 +82,6 @@ import {
} from "../Services/ProjectionSnapshotQuery.ts";
const decodeReadModel = Schema.decodeUnknownEffect(OrchestrationReadModel);
const decodeShellSnapshot = Schema.decodeUnknownEffect(OrchestrationShellSnapshot);
const decodeThread = Schema.decodeUnknownEffect(OrchestrationThread);
const decodeImportedTranscriptsPayload = Schema.decodeUnknownOption(
Schema.fromJsonString(
@@ -2746,7 +2745,10 @@ pending_approval_requests AS (
);
const pullRequestsByThread = groupPullRequestRowsByThread(pullRequestRows);
const snapshot = {
// Built from schema-decoded rows, so no second decode here. The HTTP
// and RPC layers encode it against OrchestrationShellSnapshot on the
// way out, like the per-item shells from getThreadShellById.
return {
snapshotSequence: computeSnapshotSequence(stateRows),
projects: Arr.filterMap(projectRows, (row) =>
row.deletedAt === null
@@ -2800,15 +2802,7 @@ pending_approval_requests AS (
: Result.failVoid,
),
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
};
return yield* decodeShellSnapshot(snapshot).pipe(
Effect.mapError(
toPersistenceDecodeError(
"ProjectionSnapshotQuery.getShellSnapshot:decodeShellSnapshot",
),
),
);
} satisfies OrchestrationShellSnapshot;
}),
),
Effect.mapError((error) => {
@@ -2941,7 +2935,7 @@ pending_approval_requests AS (
sessionRows.map((row) => [row.threadId, mapSessionRow(row)] as const),
);
const snapshot = {
return {
snapshotSequence: computeSnapshotSequence(stateRows),
projects: Arr.filterMap(projectRows, (row) =>
row.deletedAt === null && activeProjectIds.has(row.projectId)
@@ -2991,15 +2985,7 @@ pending_approval_requests AS (
planProgress: threadPlanProgress.getThreadPlanProgress(row.threadId),
})),
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
};
return yield* decodeShellSnapshot(snapshot).pipe(
Effect.mapError(
toPersistenceDecodeError(
"ProjectionSnapshotQuery.getArchivedShellSnapshot:decodeShellSnapshot",
),
),
);
} satisfies OrchestrationShellSnapshot;
}),
),
Effect.mapError((error) => {