Fix premature sequence advancement and missing archived-threads invalidation on snapshot recovery

- Add filterNewEvents() to recovery coordinator to filter events without advancing latestSequence
- Defer markEventBatchApplied() in applyEventBatch() until after the snapshot-recovery check passes, preventing latestSequence from advancing when events are not actually applied
- Invalidate archived-threads query in runSnapshotRecovery() so the ArchivedThreadsPanel reflects snapshot state immediately
This commit is contained in:
Cursor Agent committed 2026-04-01 21:18:51 +00:00
1 parent 097c3a35c8
commit 51aaa5d579
2 files changed
+12 -3

No files matched your search

+6 -2
View File
@@ -62,10 +62,14 @@ export function createOrchestrationRecoveryCoordinator() {
return "apply";
},
markEventBatchApplied<T extends SequencedEvent>(events: ReadonlyArray<T>): ReadonlyArray<T> {
const nextEvents = events
filterNewEvents<T extends SequencedEvent>(events: ReadonlyArray<T>): ReadonlyArray<T> {
return 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 [];
}
+6 -1
View File
@@ -313,7 +313,7 @@ function EventRouter() {
const applyEventBatch = (
events: ReadonlyArray<OrchestrationEvent>,
): "applied" | "snapshot-recovery-needed" => {
const nextEvents = recovery.markEventBatchApplied(events);
const nextEvents = recovery.filterNewEvents(events);
if (nextEvents.length === 0) {
return "applied";
}
@@ -327,6 +327,8 @@ function EventRouter() {
return "snapshot-recovery-needed";
}
recovery.markEventBatchApplied(nextEvents);
const batchEffects = deriveOrchestrationBatchEffects(nextEvents);
const needsProjectUiSync = nextEvents.some(
(event) =>
@@ -417,6 +419,9 @@ function EventRouter() {
if (!disposed) {
syncServerReadModel(snapshot);
reconcileSnapshotDerivedState();
void queryClient.invalidateQueries({
queryKey: orchestrationQueryKeys.archivedThreads(),
});
if (recovery.completeSnapshotRecovery(snapshot.snapshotSequence)) {
void recoverFromSequenceGap();
}