Skip to content

fix(web): keep streaming updates independent of history length - #870

Merged
tt-a1i merged 3 commits into
mainfrom
cursor/streaming-update-cost-111c
Oct 16, 2026
Merged

tt-a1i merged 3 commits into
mainfrom
cursor/streaming-update-cost-111c

Conversation

@tt-a1i

@tt-a1i tt-a1i commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Fixes #837.

Streaming message_update events rebuilt transcript signatures for the whole persisted history and copied an unbounded thinking-timing map on every update. Turn attribution also scanned from the start of the row list for each timing row. The cost grew with history bytes and with the number of timing keys retained in a long-lived session. This follows the audit in #841 and does not replace the unchanged-history Markdown memo from #434.

Value

A live token no longer pays for history that did not change. Visible reasoning durations stay attached to the current live messages and to thinking entries still in the selected session, and completed timings that the snapshot has not adopted yet stay only up to the transcript reading window. A live user prompt that has no timestamp still collapses onto the one matching native prompt, and an entry appended to the same history array still appears.

Approach

  • reduceLiveTools returns the same array when a non-tool event or a settled turn does not change tool evidence, and the store skips the snapshot write in that case. Cursor order, recovery, and terminal state are unchanged.
  • Persisted disclosure signatures, legacy signatures, and prompt signatures are cached on the entries array. A hit requires the same length and the same first and last entry, so an in-place append rebuilds the projection. Unchanged streaming updates do not. Live reconciliation still uses the existing exact-identity, truncated-message, and optimistic-prompt rules. A live message with no timestamp matches one native payload by legacy signature, including a native message that has its own timestamp.
  • Turn attribution records the first prompt index in one pass instead of calling findIndex from the start of the rows for every timing row.
  • Thinking starts stay with the current live messages. Durations also stay for thinking entries in the selected session, keyed by message identity (message-${role}-${timestamp}) and by entry id. Completions not yet in that snapshot are kept in a pending list capped at WEB_MAX_ENTRIES * 4, the same reading window the transcript already uses. A later snapshot that still contains the entry keeps the duration; a window that no longer contains it drops the key.

Validation

Same machine, Bun 1.3.14, the #837 synthetic repro. Before is one run at 78dc574. After wall-clock figures are medians of five runs. The regression gate is the counts, not the milliseconds. No test retries and no widened timeouts.

Scenario Before After
1000 distinct thinking updates live messages 8, thinkingStarts 1000, 3000 notifications live messages 8, thinkingStarts 8, thinkingDurations 0, 2000 notifications
1000 updates with 0 / 1000 / 10000 preexisting timing keys 3.2 / 90 / 1078 ms, snapshot reference changed 3.2 / 2.2 / 4.0 ms, snapshot reference unchanged, 1 start key left
buildEntries × 100, 250 history messages (~0.53 MB) 78.3 ms, 50100 JSON.stringify calls, ~103.8M chars 2.7 ms, 200 JSON.stringify calls, 9400 chars
buildEntries × 100, 1000 history messages (~2.13 MB) 216.1 ms, 200100 JSON.stringify calls, ~415.4M chars 5.1 ms, 200 JSON.stringify calls, 9400 chars
Turn attribution, 150 / 300 / 750 / 999 rows 3725 / 14950 / 93625 / 166167 prompt searches 800 / 1600 / 4000 / 5328 index reads (5.33 per row), 0 findIndex calls

The 200 stringify calls are two serializations of the live message per call. They do not grow from 250 entries to 1000. The turn-read ratio stays flat while the old search counts grow with the square of the turn count. The 0-key store time stays at 3.2 ms; that sample is not a speedup.

Browser evidence

Separate from the Bun counts. One headless Chrome run (system Chrome, 1280×800, Vite dev) of the real Transcript on a synthetic page. Each history message is 1000 x characters in both content and a text part. Before is 78dc574. After is this working tree. Each sample is 20 streamed updates, each in its own task, then 12 input events that each apply one more update and wait for the next frame. React Profiler actualDuration, PerformanceObserver longtask, and input-to-frame time. A favicon 404 was the only page error. These samples did not get faster: a commit still rebuilds the history row tree, which dominates the signature work the Bun counts isolate.

Page Before After
250 entries 33 commits, actualDuration median 42.8 ms (max 110.3, sum 1632), 32 long tasks / 2632 ms (max 640), input-to-frame median 55 ms (max 120) 33 commits, median 44.1 ms (max 118.5, sum 1660), 32 long tasks / 2715 ms (max 652), input-to-frame median 63.2 ms (max 135)
1000 entries 33 commits, actualDuration median 166.9 ms (max 319.3, sum 6427), 32 long tasks / 9278 ms (max 1389), input-to-frame median 229.2 ms (max 375) 33 commits, median 177.3 ms (max 317.2, sum 6637), 32 long tasks / 9781 ms (max 1499), input-to-frame median 217.6 ms (max 377)

bun run check passed on this revision, including the committed web/dist bundle. bun run test ui passed locally after the reconciliation fix (99 files, 1529 tests). The added tests fail if a timestamp-free live copy of a timestamped prompt becomes a second row, or if a message pushed onto the same history array stays hidden. They do not use timers, retries, or wider timeouts.

CI for a47577c02897413dfa5eaa5f355ea7c159c6a34f completed with every check passing: https://github.com/openpi-dev/openpi/actions/runs/38914679573

Impact

  • User-visible behavior: streamed history no longer rebuilds signatures for unchanged entries. A timestamp-free live prompt still occupies the matching native row. Reasoning durations remain for visible thinking messages and for the reading-window bridge, and are removed when that entry leaves the selected session.
  • Model-visible context/tools: none.
  • Runtime/lifecycle: non-tool events no longer allocate a snapshot when live tools are unchanged. Thinking timing retention is bounded by the live window plus the reading window.
  • Persisted config/data: none.
  • Compatibility or risk: row identity for an exact complete assistant/tool result can still follow the live key. Truncated duplicates stay on the native id. Optimistic prompts still move onto the matching later native message.
Open in Web Open in Cursor 

cursoragent and others added 3 commits October 16, 2026 13:59
Reuse persisted transcript signatures, skip unchanged live-tool snapshots, attribute turns in one pass, and bound thinking timings to the visible window plus the reading-window bridge.

Co-authored-by: tt-a1i <[email protected]>
A live user without a timestamp must still match one timestamped native
payload, and an append on the same entries array must rebuild the
cached projection. Streaming updates that leave the array unchanged
keep the cache hit.

Co-authored-by: tt-a1i <[email protected]>
@tt-a1i
tt-a1i marked this pull request as ready for review October 16, 2026 14:25
@tt-a1i
tt-a1i merged commit c2aa6d3 into main Oct 16, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(web): 流式更新重复计算历史签名和轮次归属,thinking 时间表持续增长

2 participants