Compare commits

..
Author SHA1 Message Date
Cursor Agent 95dd2b671c Fix snapshot sync bypassing recovery coordinator and dead loading state
- Remove refreshActiveSnapshot from unarchiveThread: the EventRouter's
  recovery coordinator already handles thread.unarchived events via
  fallbackToSnapshotRecovery, which properly updates latestSequence.
  Calling syncServerReadModel directly left the coordinator stale,
  causing already-applied events to be re-processed and potentially
  corrupting streaming message content via double concatenation.

- Fix archived threads loading state: placeholderData always returned
  EMPTY_ARCHIVED_THREADS on first load, making isPending permanently
  false and the loading UI unreachable. Now only uses previous query
  data as placeholder, allowing isPending to be true on first fetch.
2026-04-01 17:43:11 +00:00
Julius Marmingeandcodex bbe5e14696 Move archived threads off the main read path
Co-authored-by: codex <[email protected]>
2026-04-01 10:27:57 -07:00
5 changed files with 11 additions and 43 deletions

No files matched your search

+6 -18
View File
@@ -99,24 +99,12 @@ const ReactorLayerLive = Layer.empty.pipe(
Layer.provideMerge(RuntimeReceiptBusLive),
);
const OrchestrationEventInfrastructureLayerLive = Layer.mergeAll(
OrchestrationEventStoreLive,
OrchestrationCommandReceiptRepositoryLive,
);
const OrchestrationProjectionPipelineLayerLive = OrchestrationProjectionPipelineLive.pipe(
Layer.provide(OrchestrationEventStoreLive),
);
const OrchestrationInfrastructureLayerLive = Layer.mergeAll(
OrchestrationProjectionSnapshotQueryLive,
OrchestrationEventInfrastructureLayerLive,
OrchestrationProjectionPipelineLayerLive,
);
const OrchestrationLayerLive = Layer.mergeAll(
OrchestrationInfrastructureLayerLive,
OrchestrationEngineLive.pipe(Layer.provide(OrchestrationInfrastructureLayerLive)),
const OrchestrationLayerLive = Layer.empty.pipe(
Layer.provideMerge(OrchestrationProjectionSnapshotQueryLive),
Layer.provideMerge(OrchestrationEngineLive),
Layer.provideMerge(OrchestrationProjectionPipelineLive),
Layer.provideMerge(OrchestrationEventStoreLive),
Layer.provideMerge(OrchestrationCommandReceiptRepositoryLive),
);
const CheckpointingLayerLive = Layer.empty.pipe(
+1 -10
View File
@@ -18,7 +18,6 @@ import { useSettings } from "./useSettings";
export function useThreadActions() {
const appSettings = useSettings();
const syncServerReadModel = useStore((store) => store.syncServerReadModel);
const clearComposerDraftForThread = useComposerDraftStore((store) => store.clearDraftThread);
const clearProjectDraftThreadById = useComposerDraftStore(
(store) => store.clearProjectDraftThreadById,
@@ -33,13 +32,6 @@ export function useThreadActions() {
const queryClient = useQueryClient();
const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ queryClient }));
const refreshActiveSnapshot = useCallback(async () => {
const api = readNativeApi();
if (!api) return;
const snapshot = await api.orchestration.getActiveSnapshot();
syncServerReadModel(snapshot);
}, [syncServerReadModel]);
const archiveThread = useCallback(
async (threadId: ThreadId) => {
const api = readNativeApi();
@@ -73,10 +65,9 @@ export function useThreadActions() {
commandId: newCommandId(),
threadId,
});
await refreshActiveSnapshot();
void queryClient.invalidateQueries({ queryKey: orchestrationQueryKeys.archivedThreads() });
},
[queryClient, refreshActiveSnapshot],
[queryClient],
);
const deleteThread = useCallback(
+1 -3
View File
@@ -1,4 +1,3 @@
import type { OrchestrationListArchivedThreadsResult } from "@t3tools/contracts";
import { queryOptions } from "@tanstack/react-query";
import { ensureNativeApi } from "~/nativeApi";
@@ -8,7 +7,6 @@ export const orchestrationQueryKeys = {
};
const DEFAULT_ARCHIVED_THREADS_STALE_TIME = 15_000;
const EMPTY_ARCHIVED_THREADS: OrchestrationListArchivedThreadsResult = [];
export function archivedThreadsQueryOptions() {
return queryOptions({
@@ -18,6 +16,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();
}