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]>