perf(server): bound snapshot activity payload memory #9000
main fromrefs/pull/9000/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubClient thread snapshots limited activity history to 500 rows, but they still decoded every raw payload before client projection. One snapshot could therefore hold a full window of large tool outputs in memory at once.
The snapshot query now selects the same recent and pinned activity IDs, reads 25 payload rows at a time through the primary key, and projects each batch before the next read. Raw getThreadDetailById calls keep their current behavior.
The output preview scanner stops at the first meaningful line and copies the bounded preview so V8 can release the source string. In a synthetic 48 MiB fixture, retained heap fell from 49.05 MiB to 2.05 MiB. This is an isolated fixture result, not live app RAM data.
Verification:
- 29 focused query and payload tests
- Server typecheck
- Targeted lint and format checks
- Four focused HTTP and WebSocket snapshot tests
Made with GPT-5.6 Sol in Codex.
Note
Medium Risk Changes hot-path thread snapshot reads and payload shaping for all clients; behavior is heavily tested but mistakes could alter visible activity data or ordering.
Overview
Client thread snapshots no longer decode up to 500 full activity payloads at once. getThreadDetailSnapshot resolves the same recent and pinned activity IDs as before, loads payload_json in 25-row PK batches, and runs projectActivityPayload on each batch before the next read. Raw getThreadDetailById behavior is unchanged.
Tool output previews in summarizeToolTextOutput now scan line-by-line, return on the first meaningful non-fence line (still normalized and capped at 84 chars), and build the preview via Array.from(...).join("") so V8 is less likely to retain the full source string. Fence-only output still falls back to an N lines summary.
Integration tests seed large command/MCP payloads and assert snapshot projection matches projecting raw detail, including failed-command status and collection-level pruning after projectThreadDetailSnapshot.
Note
Project snapshot activity payloads in batches of 25 and fix fence-only preview fallback#
getThreadDetailSnapshotnow loads activity IDs first, then fetches full rows and projects payloads in batches ofTHREAD_DETAIL_ACTIVITY_PAYLOAD_BATCH_SIZE(25), reducing retention of large raw payloads during client snapshot readssummarizeToolTextOutputrewritten as a streaming scan: it skips lines that are only code-fence markers (```) and falls back to a line count (e.g. "2 lines") when no meaningful non-fence line is foundgetThreadDetailByIdBoundedgains anactivityReadparameter selecting'client'(projected, batched) or'raw'(previous behavior);getThreadDetailByIdkeeps'raw'mode- Behavioral Change: client snapshot reads now return projected/summarized activity payloads instead of raw payloads;
getThreadDetailByIdis unaffected
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — The change substantially rewires production thread snapshot reads, replacing a single payload query with ID selection and sequential batched payload projection across HTTP and WebSocket paths. Regression coverage is present, but the runtime and database-access changes are broad enough to merit human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
b17cc3d· PR result:68f8bf0· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.