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]>
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]>
A busy SQLite database materialised hundreds of MB of activity payloads into the
Node heap and crashed the server. Bound the reads and add an on-demand
pagination path so deep history is still recoverable.
- /api/orchestration/snapshot and the `t3` CLI offline path called getSnapshot(),
loading every thread's full activity/message/checkpoint history even though
they only read `.projects`. Point both at getCommandReadModel() (same shape,
without the heavy per-thread tables).
- getThreadDetailById windows activities to the most recent 500 (it fetches
WINDOW+1 to detect truncation and sets `hasMoreActivities` so clients can
lazy-load). Live activities still stream in via the event subscription.
- New orchestration.getThreadActivities RPC pages older activities on demand:
cursor is {beforeSequence} for sequenced rows or {beforeCreatedAt,
beforeActivityId} for legacy unsequenced (NULL) rows, output {activities,
hasMore}. The sequenced query orders by `sequence DESC` with
`(sequence < ? OR sequence IS NULL)` so the (thread_id, sequence, created_at,
activity_id) index satisfies the ORDER BY instead of a filesort. Unsequenced
rows page by a (created_at, activity_id) cursor consistent with the window's
ordering.
Co-Authored-By: Claude Opus 4.8 <[email protected]>