The lazy-load state machine (~160 lines each) was hand-copied in the web
ChatView and the mobile composer, and every review-round fix had to be
applied to both — half the review churn on this PR was the copies drifting.
One shared hook, `useOlderThreadActivities` in client-runtime, now owns all
of the hardened behavior: reshape-sentinel reset, generation guard,
synchronous in-flight coalescing, the advancing cursor (all-overlap pages
keep paging), dedup against the latest merged set, and hasMore-preserving
failure handling. Clients pass a `loadPage` transport wrapper and keep only
their platform scroll trigger and error surfacing.
The decision kernel (reshape detection, cursor selection, page dedup) is
exported as pure functions with unit tests; react becomes an optional peer
dependency of client-runtime, scoped to the new subpath.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Detect a live-window reshape from an order-independent oldest boundary
(`liveWindowOldestActivityId`: min by createdAt/id) instead of
`activities[0]`. The reducer sorts unsequenced rows to the end while the
server snapshot lists legacy unsequenced rows first, so the first live
append re-sorts the array and shifts index 0 — which previously looked
like a reshape and wrongly cleared the user's scrolled-up history.
Run the older-pages reset in useLayoutEffect so the cleared state commits
before paint; otherwise a thread switch renders one frame with the previous
thread's lazy-loaded pages still merged in, flashing stale work-log and
approval rows.
Applied to both web (ChatView) and mobile (use-thread-composer-state); the
shared sentinel helper lives in client-runtime with unit tests.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
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]>
Mobile consumed the windowed thread detail with no way to fetch older
activities, silently truncating history. Mirror the web lazy-load:
- useThreadComposerState: older-activity state + a thread-keyed in-flight ref
guard, a reset effect on thread switch, and loadThreadActivities with the same
union cursor. Older pages are deduped (against prior pages and the live window)
and prepended into the feed; initial hasMore comes from the server's
hasMoreActivities flag.
- ThreadFeed: onStartReached triggers the load, maintainVisibleContentPosition
anchors the viewport on prepend, and the header shows a spinner while loading.
- Forward the values through ThreadRouteScreen → ThreadDetailScreen.
Co-Authored-By: Claude Opus 4.8 <[email protected]>