Repository navigation
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a focused server-side performance optimization that skips expensive full JSON encoding only when timeline text already proves the existing payload budget is exceeded. It leaves projection data and pagination behavior unchanged and adds targeted boundary coverage. Notes:
You can add or adjust custom eligibility rules. Learn more. |
Dismissing prior approval to re-evaluate b6cd417
|
Note Written by Thanks for investigating snapshot serialization costs. Under our limited review capacity in Read this first, right now we are only taking focused bug fixes from outside contributors. This PR preserves snapshot behavior while reducing serialization work, and its synthetic measurements exclude transport and client rendering. Please keep #18916 updated and seek agreement in an Ideas discussion on a measured user-path fix before requesting reconsideration. |
Preparing a bounded snapshot of a thread with ten 1 MiB messages takes 21.2 ms, was 39.2 ms (46% faster), with 42% less CPU per 10 requests. Peak memory did not improve.
Problem
A bounded snapshot still serializes its complete projection to calculate
payloadBudgetExceededwhen control state fits the byte budget. Large retained messages can already prove overflow, but the server allocates and encodes the timeline anyway. Local timeline items appear twice in this projection before wire compaction.Change
Use text lengths as a conservative lower bound on encoded bytes. Count text in
visibleTurnItemsandturnItems, including both local copies. If the sum exceeds the budget, report overflow immediately. Otherwise retain the exact JSON byte calculation.Page selection, complete turns, cursors, response fields and validation stay unchanged. No dependencies or migrations.
Scope and approval
Closes #18916.
Focused follow-up to #17387's overflow calculation, independent of #18071's ancestor-query optimization. Related #16819 and #15794 address page-selection limits; this change preserves those limits and optimizes the final overflow check.
Replaces #17426, which was closed because its body did not name the model and harness. The code is unchanged; they are stated at the end.
Verification
A synthetic read-only SQLite comparison used Node 24.21.0 and Effect 4.0.1. The large-message case retains ten 1 MiB assistant messages. Timed work includes SQL, validated decoding, wire projection, bounding, schema encoding and JSON serialization. Startup, hashing, network transport and client rendering are outside request timing. Hashing remains included in batch CPU.
Changes of 3% or less are treated as no clear change in this comparison. This is a practical reporting threshold, not a statistical margin of error. A larger change must still exceed measured variability.
Peak RSS did not improve. Four ordinary controls stayed within the preset 5% latency/CPU regression limit; their differences do not establish a speedup.
Each case used four warmup pairs and 15 alternating measured pairs, with ten requests per arm per pair. The target's paired median saving was 17.92 ms; paired-delta median absolute deviation was 1.13 ms. RSS used three alternating pairs of fresh processes, each with ten warmup and 80 measured requests. All 2,440 responses matched exactly, including flags and cursors; fixtures were unchanged.
The measured baseline was
8ba4bdb1f6, including the independent #18071 optimization, plus this exact patch for the candidate. The final branch was rebased onto43f8a8de17with byte-identical affected source/tests. This does not measure performance against current main or establish a production/UI speedup.Real-client rendering was not measured. The full repository suite was not run locally; upstream CI passed on
b6cd4175db.68 tests passed on the final branch. New coverage checks exact budget boundaries for ASCII, JSON escapes, Unicode, unpaired surrogates, inherited/local rows, and combined duplicated text while preserving complete turns and cursors.
Focused test command
vp test run apps/server/src/orchestration-v2/threadHistoryPaging.test.ts apps/server/src/orchestration-v2/WireProjection.test.ts apps/server/src/orchestration-v2/ThreadStream.test.tsGPT-6.1 Sol, in Codex.