fix: invalidate lazy-loaded older history when the live window reshapes

Address review (PR #3510, Cursor Bugbot):

- Reconnect / checkpoint revert can re-snapshot or filter the live activity
  window, but the prepended `olderActivities` weren't invalidated — leaving gaps
  or showing reverted history. Reset the lazy-load state when the live window's
  oldest activity id changes (it's stable while activities only append, so this
  doesn't fire during a normal turn), in addition to on thread switch. Web + mobile.
- Web only deduped a new older page against already-loaded older pages, not the
  live window (mobile already did both). Dedup against both so a boundary overlap
  can't produce duplicate ids / React keys.

Not changed — the "unsequenced cursor hides sequenced history" finding is a false
positive: NULL-sequence (legacy) rows always sort oldest in the window/cursor
ordering, so the oldest-loaded row is only unsequenced once every sequenced row
is already loaded; the unsequenced cursor can never strand sequenced rows.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
olafuraandClaude Opus 4.8 authored and Julius Marminge committed 2026-07-20 17:26:29 +02:00
1 parent 21ca57b213
commit bd934136c4
2 files changed
+22 -5

No files matched your search

@@ -113,14 +113,19 @@ export function useThreadComposerState() {
: null;
const activityRequestKeyRef = useRef(activityRequestKey);
activityRequestKeyRef.current = activityRequestKey;
const liveActivities = selectedThreadDetail?.activities ?? EMPTY_ACTIVITIES;
// The live window's oldest activity is stable while new activities only
// append; it changes when the window is re-snapshotted (reconnect) or rows are
// removed (checkpoint revert), either of which can make prepended older pages
// stale or gappy — so reset the lazy-load state when it (or the thread) changes.
const liveOldestActivityId = liveActivities[0]?.id ?? null;
useEffect(() => {
setOlderActivities([]);
setOlderLoaded(false);
setOlderHasMore(false);
setLoadingOlderActivities(false);
}, [activityRequestKey]);
const liveActivities = selectedThreadDetail?.activities ?? EMPTY_ACTIVITIES;
}, [activityRequestKey, liveOldestActivityId]);
const mergedActivities = useMemo(
() =>
olderActivities.length > 0 ? [...olderActivities, ...liveActivities] : liveActivities,
+14 -2
View File
@@ -1881,14 +1881,19 @@ function ChatViewContent(props: ChatViewProps) {
: null;
const activeThreadActivityRequestKeyRef = useRef(activeThreadActivityRequestKey);
activeThreadActivityRequestKeyRef.current = activeThreadActivityRequestKey;
const liveThreadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;
// The live window's oldest activity is stable while new activities only
// append; it changes when the window is re-snapshotted (reconnect) or rows are
// removed (checkpoint revert), either of which can make prepended older pages
// stale or gappy — so reset the lazy-load state when it (or the thread) changes.
const liveOldestActivityId = liveThreadActivities[0]?.id ?? null;
useEffect(() => {
setOlderActivities([]);
setOlderLoaded(false);
setOlderHasMore(false);
setLoadingOlderActivities(false);
}, [activeThreadActivityRequestKey]);
}, [activeThreadActivityRequestKey, liveOldestActivityId]);
const liveThreadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;
const threadActivities = useMemo(
() =>
olderActivities.length > 0
@@ -1937,7 +1942,13 @@ function ChatViewContent(props: ChatViewProps) {
}
const page = result.value;
setOlderActivities((prev) => {
// Dedup against both already-loaded older pages and the live window so
// an overlap at the window boundary can't leave duplicate ids (which
// would break timeline keys and work-log derivation).
const seen = new Set(prev.map((activity) => activity.id));
for (const activity of liveThreadActivities) {
seen.add(activity.id);
}
const fresh = page.activities.filter((activity) => !seen.has(activity.id));
return [...fresh, ...prev];
});
@@ -1957,6 +1968,7 @@ function ChatViewContent(props: ChatViewProps) {
activeThreadActivityRequestKey,
hasMoreOlderActivities,
threadActivities,
liveThreadActivities,
loadThreadActivities,
]);