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]>
The server windows thread detail to the most recent 500 activities and reports
`hasMoreActivities`. The web timeline now fetches older pages on demand via the
getThreadActivities RPC:
- client-runtime: loadThreadActivities command on orchestrationEnvironment.
- ChatView keeps per-thread older pages in local state, prepends them ahead of
the live window, and derives hasMore from the server flag (no client-side
window-size constant). A thread-keyed in-flight ref coalesces the duplicate
dispatches a fast scroll-to-top would otherwise fire, and a request-key guard
discards results after a thread switch.
- MessagesTimeline triggers a load on reaching the top
(maintainVisibleContentPosition anchors the viewport on prepend) with a
"Load older history" header and loading indicator.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>