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:
2 files changed
+12
-3
No files matched your search
@@ -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 [];
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user