You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Preparing a bounded snapshot of a thread with ten 1 MiB messages encodes the whole timeline just to prove it is over budget #18916
When control state fits the byte budget, a bounded snapshot serializes its complete projection to compute payloadBudgetExceeded, even when large retained messages already prove overflow. Local timeline items also appear twice in that projection before wire compaction. In a synthetic thread with ten 1 MiB assistant messages, preparation takes 39.19 ms.
Diagnosis
Text length is a lower bound on encoded bytes. PR #18072 sums text in visibleTurnItems and turnItems (both copies) and reports overflow as soon as the sum exceeds the budget; otherwise it keeps the exact JSON calculation. Page selection, cursors and response fields are unchanged. With it preparation takes 21.17 ms (46% lower) and CPU per 10 requests falls from 485.32 to 281.26 ms (42%). Peak memory did not improve (594.5 to 597.9 MiB).
Steps to reproduce
Run the paired benchmark described in PR #18072 (4 warmup pairs, 15 alternating pairs, 10 requests per arm).
Version
0.0.44
Environment
Linux (WSL2), server only, synthetic fixture. Exact runtime is in the PR body.
Evidence
Median 39.19 to 21.17 ms; paired median saving 17.92 ms, paired-delta MAD 1.13 ms. All 2,440 responses identical, encoded size 10,696,937 bytes in both arms. Four ordinary controls stayed within the 5% regression limit. Synthetic only: client rendering and production were not measured.
Fixed by #20064, which carried forward @bompus's work from #18072 and is now merged: bounded snapshots skip the full encode when the retained message text alone already exceeds the payload budget. Thanks for the detailed report and benchmark!
Activity
juliusmarminge commentedon Oct 20, 2026
Note
Grok responding on behalf of Julius.
Fixed by #20064, which carried forward @bompus's work from #18072 and is now merged: bounded snapshots skip the full encode when the retained message text alone already exceeds the payload budget. Thanks for the detailed report and benchmark!