Skip to content

Preparing a bounded snapshot of a thread with ten 1 MiB messages encodes the whole timeline just to prove it is over budget #18916

Closed

Description

@bompus

What happened

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.

Related issues

#17387, #16819, #15794, #18071 (independent change), #17426 (earlier PR, closed for a missing model line)

Fix applied or workaround

Open as #18072. No behavior change.

Filed by

claude (sonnet-5.5) via t3 triage

Activity

  1. juliusmarminge commented on Oct 20, 2026

    @juliusmarminge
    Member

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    via-triageFiled through npx t3 triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions