Uh oh!
There was an error while loading. Please reload this page.
fix(server): bound thread activity hydration by bytes - #8387
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This changes existing full and windowed thread-detail responses by omitting older activities once serialized payloads exceed a 16 MiB hydration budget, while adding nontrivial SQL gating in both paths. The protection is focused and tested, but the runtime and response-semantic change merits human review. You can add or adjust custom eligibility rules. Learn more. |
What Changed
payload_jsoninto JavaScriptWhy
The 500-row cap added in #6153 bounds row count, but each
payload_jsoncan still contain megabytes of tool output. The server currently fetches and JSON-decodes those full payloads before #4622's client projection removes fields the clients do not read.On an affected image-heavy thread, the newest 500 activities contained 140.58 MiB of JSON. The patched query selected the newest 96 activities within 15.72 MiB. In an isolated read-only database benchmark, RSS after querying and JSON-decoding fell from 332.0 MiB to 58.9 MiB. The patched SQL completed in 29 ms on that dataset.
This limits transient server heap pressure without deleting stored history, changing the wire contract, or adding a migration. Pending approvals and user-input requests are still loaded through the existing pinned-activity query.
Related: #4595, #5351, #6153, #4622
Validation
pnpm exec vp fmt --check apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.tspnpm exec vp test run apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts(22 passed)cd apps/server && pnpm typecheckgit diff --checkChecklist
Model: GPT-5.6-Sol. Harness: Codex desktop.
Note
Medium Risk
Changes thread detail hydration semantics (fewer activities may appear on image-heavy threads) but leaves stored history and the API contract intact; pinned approval/user-input paths are unchanged.
Overview
Thread detail reads now cap hydrated activity
payload_jsonat 16 MiB in addition to the existing 500-row window, so megabyte tool outputs are not fully loaded and JSON-decoded in Node only to be trimmed later.ProjectionSnapshotQueryrewrites full-thread and windowed activity SQL to score recent rows from metadata (LENGTH(payload_json)), walk newest-first with a running byte total, always keep the newest activity, then fetch full payloads only for rows inside the budget. The same rule applies togetThreadDetailByIdand windowedgetThreadDetailSnapshotactivity queries.A new test seeds 18 ~1 MiB activities and asserts both detail paths return 15 activities (
large-activity-0004throughlarge-activity-0018).Reviewed by Cursor Bugbot for commit 2cd55f1. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Bound thread activity hydration by 16 MiB in
ProjectionSnapshotQueryquerieslistThreadActivityRowsByThreadandlistThreadActivityRowsByThreadWindowwith a CTE that computes cumulative serialized payload bytes and filters out older activities once the 16 MiB budget is exceeded.THREAD_DETAIL_ACTIVITY_BYTE_LIMIT(16 MiB) constant and a test seeding 18 large (~1 MiB) activities to verify only 15 are returned.listThreadActivityRowsByThreadandlistThreadActivityRowsByThreadWindownow return fewer activities when payloads are large; consumers expecting a fixed count may see reduced results.Macroscope summarized 2cd55f1.