Compare commits

..
Author SHA1 Message Date
Cursor Agent 5407e0b61e fix: remove empty-array placeholderData so archived threads loading state is reachable
placeholderData with a fallback to an empty array caused TanStack Query v5
to start in 'success' status, making isPending always false. The loading UI
was dead code and users saw a misleading 'No archived threads' flash.

Now placeholderData only returns the previous value (undefined on first
load), so the query correctly starts in pending status.
2026-04-01 22:19:57 +00:00
Julius Marmingeandcodex 3b01bbe18f Move archived threads off the main read path
Co-authored-by: codex <[email protected]>
2026-04-01 15:08:04 -07:00
Julius Marmingeandcodex 823d69f621 perf(server): bootstrap engine from persisted projections (#1648)
Co-authored-by: codex <[email protected]>
2026-04-01 15:07:15 -07:00
Julius Marmingeandcodex 4963fccb05 perf(server): avoid thread-wide scans for message projection (#1647)
Co-authored-by: codex <[email protected]>
2026-04-01 14:48:39 -07:00
Julius Marmingeandcodex dd89d5ce1a perf(server): add targeted projection queries (#1646)
Co-authored-by: codex <[email protected]>
2026-04-01 14:41:03 -07:00
4 changed files with 19 additions and 28 deletions

No files matched your search

@@ -626,20 +626,25 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
const existingMessage = yield* projectionThreadMessageRepository.getByMessageId({
messageId: event.payload.messageId,
});
const nextText =
Option.isSome(existingMessage) && event.payload.streaming
? `${existingMessage.value.text}${event.payload.text}`
: Option.isSome(existingMessage) && event.payload.text.length === 0
? existingMessage.value.text
: event.payload.text;
const previousMessage = Option.getOrUndefined(existingMessage);
const nextText = Option.match(existingMessage, {
onNone: () => event.payload.text,
onSome: (message) => {
if (event.payload.streaming) {
return `${message.text}${event.payload.text}`;
}
if (event.payload.text.length === 0) {
return message.text;
}
return event.payload.text;
},
});
const nextAttachments =
event.payload.attachments !== undefined
? yield* materializeAttachmentsForProjection({
attachments: event.payload.attachments,
})
: Option.isSome(existingMessage)
? existingMessage.value.attachments
: undefined;
: previousMessage?.attachments;
yield* projectionThreadMessageRepository.upsert({
messageId: event.payload.messageId,
threadId: event.payload.threadId,
@@ -648,9 +653,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
text: nextText,
...(nextAttachments !== undefined ? { attachments: [...nextAttachments] } : {}),
isStreaming: event.payload.streaming,
createdAt: Option.isSome(existingMessage)
? existingMessage.value.createdAt
: event.payload.createdAt,
createdAt: previousMessage?.createdAt ?? event.payload.createdAt,
updatedAt: event.payload.updatedAt,
});
return;
+1 -4
View File
@@ -1,4 +1,3 @@
import type { OrchestrationListArchivedThreadsResult } from "@t3tools/contracts";
import { queryOptions } from "@tanstack/react-query";
import { ensureNativeApi } from "~/nativeApi";
@@ -8,8 +7,6 @@ export const orchestrationQueryKeys = {
};
const DEFAULT_ARCHIVED_THREADS_STALE_TIME = 15_000;
const EMPTY_ARCHIVED_THREADS: OrchestrationListArchivedThreadsResult = [];
export function archivedThreadsQueryOptions() {
return queryOptions({
queryKey: orchestrationQueryKeys.archivedThreads(),
@@ -18,6 +15,6 @@ export function archivedThreadsQueryOptions() {
return api.orchestration.listArchivedThreads();
},
staleTime: DEFAULT_ARCHIVED_THREADS_STALE_TIME,
placeholderData: (previous) => previous ?? EMPTY_ARCHIVED_THREADS,
placeholderData: (previous) => previous,
});
}
+2 -6
View File
@@ -62,14 +62,10 @@ export function createOrchestrationRecoveryCoordinator() {
return "apply";
},
filterNewEvents<T extends SequencedEvent>(events: ReadonlyArray<T>): ReadonlyArray<T> {
return events
markEventBatchApplied<T extends SequencedEvent>(events: ReadonlyArray<T>): ReadonlyArray<T> {
const nextEvents = events
.filter((event) => event.sequence > state.latestSequence)
.toSorted((left, right) => left.sequence - right.sequence);
},
markEventBatchApplied<T extends SequencedEvent>(events: ReadonlyArray<T>): ReadonlyArray<T> {
const nextEvents = this.filterNewEvents(events);
if (nextEvents.length === 0) {
return [];
}
+1 -6
View File
@@ -313,7 +313,7 @@ function EventRouter() {
const applyEventBatch = (
events: ReadonlyArray<OrchestrationEvent>,
): "applied" | "snapshot-recovery-needed" => {
const nextEvents = recovery.filterNewEvents(events);
const nextEvents = recovery.markEventBatchApplied(events);
if (nextEvents.length === 0) {
return "applied";
}
@@ -327,8 +327,6 @@ function EventRouter() {
return "snapshot-recovery-needed";
}
recovery.markEventBatchApplied(nextEvents);
const batchEffects = deriveOrchestrationBatchEffects(nextEvents);
const needsProjectUiSync = nextEvents.some(
(event) =>
@@ -419,9 +417,6 @@ function EventRouter() {
if (!disposed) {
syncServerReadModel(snapshot);
reconcileSnapshotDerivedState();
void queryClient.invalidateQueries({
queryKey: orchestrationQueryKeys.archivedThreads(),
});
if (recovery.completeSnapshotRecovery(snapshot.snapshotSequence)) {
void recoverFromSequenceGap();
}