Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): bound snapshot activity payload memory #9000

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/9000/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Client 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.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 68f8bf082e60eeeb7a82c7d3ab05565f69db9e31. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Project snapshot activity payloads in batches of 25 and fix fence-only preview fallback

  • getThreadDetailSnapshot now loads activity IDs first, then fetches full rows and projects payloads in batches of THREAD_DETAIL_ACTIVITY_PAYLOAD_BATCH_SIZE (25), reducing retention of large raw payloads during client snapshot reads
  • summarizeToolTextOutput rewritten 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 found
  • getThreadDetailByIdBounded gains an activityRead parameter selecting 'client' (projected, batched) or 'raw' (previous behavior); getThreadDetailById keeps 'raw' mode
  • Behavioral Change: client snapshot reads now return projected/summarized activity payloads instead of raw payloads; getThreadDetailById is unaffected
Macroscope summarized 68f8bf0.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.3 KiB13.3 KiB+9 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB0 B (0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.4 KiB+9 B (+0.1%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.6 KiB55.6 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.3 KiB13.3 KiB−1 B (−0.0%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB−4 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.4 KiB6.4 KiB+3 B (+0.0%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded56.4 KiB56.4 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: b17cc3d · PR result: 68f8bf0 · Source CI: success

      Scenario 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.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. 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).

Sign in to join this conversation.