Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): bound thread activity hydration #6153

Mergedt3-code-bot[bot](GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/6153/headmerged by juliusmarminge View on GitHub

What Changed

  • limit full and windowed thread detail reads to the newest 500 activities before payload decoding
  • preserve unresolved approval and user-input request activities outside the recent window
  • add regression coverage for bounded reads and request lifecycle edge cases

Why

Large threads can contain hundreds of megabytes of activity payloads. Hydrating every row at once can exhaust the backend's V8 heap. This keeps SQL hydration aligned with the projector's existing 500-activity invariant while retaining actionable requests.

Fixes #5351

Verification

  • pnpm exec vp test run apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts (21 passed)
  • pnpm exec vp run --filter t3 typecheck
  • pnpm exec vp fmt --check apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts
  • git diff --check

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • UI screenshots are not applicable
  • Animation or interaction video is not applicable

Built by OpenAI Codex in the T3 Code harness.


Note

Medium Risk Changes thread detail API semantics for threads with >500 activities and alters which approval/user-input activities appear; logic is complex but scoped to read paths with new regression tests.

Overview Thread detail activity hydration is capped at 500 rows in ProjectionSnapshotQuery, matching the in-memory projector’s retained window so large threads no longer decode unbounded payload_json and risk V8 heap exhaustion.

Full-thread and windowed activity queries now select the newest 500 activities (by sequence, created_at, activity_id) inside SQL before JSON decoding. A new listPinnedThreadActivityRowsByThread query always pulls in blocking work: pending approval.requested rows tied to projection_pending_approvals, and open user-input.requested rows when the thread still has pending user input (using lifecycle heuristics so resolved/closed prompts stay out). getThreadDetailByIdBounded merges capped + pinned activities, dedupes by activityId, and re-sorts.

Regression tests cover 501+ tool activities (expect activity-0002…activity-0501), windowed snapshots with the same cap, and pinned vs excluded request lifecycle edge cases.

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

Note

Bound thread activity hydration to 500 most recent entries in ProjectionSnapshotQuery

  • listThreadActivityRowsByThread and listThreadActivityRowsByThreadWindow now cap results to the 500 most recent activities using a DESC-ordered subquery with LIMIT 500, then re-order ASC for output.
  • A new listPinnedThreadActivityRowsByThread query identifies unresolved approval and user-input request activities via CTEs against projection_pending_approvals and thread counters, ensuring they appear in thread detail even if older than the 500-activity window.
  • getThreadDetailByIdBounded merges the 500 most recent activities with pinned unresolved request activities, deduplicates by activityId, and sorts the combined set ascending by sequence, createdAt, and activityId.
  • Behavioral Change: thread detail activity lists are now capped at 500 entries by default; lists can exceed 500 only when unresolved request activities are pinned outside the window.
Macroscope summarized d866815.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire11.3 KiB11.3 KiB−6 B (−0.1%)15.1 KiB✅
      CodexThread snapshot wire5.5 KiB5.5 KiB+5 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire5.9 KiB5.9 KiB−11 B (−0.2%)7.8 KiB✅
      CodexLive turn WebSocket decoded49.7 KiB49.7 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages16160 (0.0%)21✅
      ClaudeTotal thread wire11.3 KiB11.3 KiB+3 B (+0.0%)15.1 KiB✅
      ClaudeThread snapshot wire5.5 KiB5.5 KiB−7 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire5.8 KiB5.9 KiB+10 B (+0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded50.6 KiB50.6 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages16160 (0.0%)21✅

      Baseline: f5fce74 · PR result: d866815 · 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: 94.6 KiB
      • Claude decoded thread snapshot: 95.4 KiB

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

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ffd0a41f4223db7c7de743c2f9844c3406589dd2. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved d866815

      This fix bounds thread activity hydration queries to 500 rows, preventing unbounded data reads while preserving pending approval/user-input activities. The changes are well-scoped to the projection query layer with comprehensive test coverage.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. @t3dotgg @juliusmarminge

      This is a big UX and Perf gain, recommend elevating.

      Field data from a production install that hit #5351's failure mode, in case it helps validate scope: projection_thread_activities reached 142k rows / ~380 MB of payload_json; the worst single thread held 36k activities (149 MB, mostly tool.completed payloads averaging ~10 KB). Before this bound, hydrating that thread stalled the backend long enough that the desktop's readiness probes failed and the environment link flapped — surfacing as the "network connectivity" misdiagnosis the issue describes.

      One latent path this PR doesn't cover — flagging for follow-up rather than scope creep: getSnapshot still hydrates via listThreadActivityRows(undefined) (all threads × all activities, payloads included, no LIMIT). It appears to have no production caller today, but it's the same hazard one refactor away; might be worth bounding identically or dropping from the interface.

      The read bound doesn't slow the underlying growth (#5550 — ours hit 1.4 GB in about a week of heavy agent use), but that's clearly a separate track.

      This is the primary issue of start up looping and what causes big delays in getting the boot up phase to lock and stop erroring.

    6. juliusmarminge merged this71c6f82

    7. juliusmarminge closed this

Sign in to join this conversation.