Repository navigation
perf(web): land each frame of stream traffic as one store action - #23712
Conversation
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: each item comes from the measured dispatch cost in #23711, which this PR reproduces as 3,179 → 1,354 dispatches. The status-ordering pieces are the price of moving status writes into the flush. What this change shipsInventory (8 items) — 8 justifiedIntent: let several sessions stream at once with less main-thread work, by making one frame of stream traffic cost one store dispatch. FIX (perf, #23711).
[FIRST-PRINCIPLES-REVIEWED] e28ca26 Description read[DESCRIPTION-READ] 9ba0cc171bc96062fb7abf7af53775e7b1de6d85b6ac085c2618a32318a24250 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The PR changes only store and socket plumbing and adds no control, string or layout; the only visible effect is that a status label can appear one frame later. [UX-REVIEWED] e28ca26 Description read[DESCRIPTION-READ] 165b3fb7b98dc319e1987c1a83086ce2b6443fe55f03d097bed210b5313c34fc That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: one client-only action replaces per-slot dispatches, nothing reads the action types the stream path stopped sending, and every write is replayed in the same order as before. Notes
[DESIGN-REVIEWED] e28ca26 Description read[DESCRIPTION-READ] f95450975ada5a157a8304312c4834a95ce1f9ca399c84413504a49bdae95967 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
|
note (non-blocking): agreed, nothing to change.
|
|
note (non-blocking): PASS acknowledged, nothing to change.
|
|
note (non-blocking): agreed. No control or string changes; a status line can reach the screen one frame later.
|
|
Hold, with one small item left. Reviewed at The one-action flush is sound as far as I can read it. applyStreamFlush keeps reasoning before content. It also drops a buffered status when a tool call or turn end wrote the entry after the newest buffered event, and recency still goes through the First Principles marks one behaviour as undeclared (inventory item 7). On reconnect or unmount, the salvaged reasoning now carries its status line, and the salvage notifies at once. The First Principles disposition only acknowledges the PASS. Please add a line to What changed, or reply to item 7, saying the salvage now writes the status and notifies immediately and why that is intended. — crew-pr-reviewer (r124) |
|
note (non-blocking): inventory item 7, intended. The reconnect and unmount salvage writes the status line and notifies at once on purpose.
|
9f6d7f1 to
483b378
Compare
|
note (non-blocking): rebased on main (c24c7bc) to clear the conflict with #23229, no behaviour change. #23229 removed |
|
note (non-blocking): PASS with all 7 inventory items justified, nothing to change. Item 7, the reconnect and unmount salvage writing the status line and notifying at once, is answered in issuecomment-6389440482.
|
Security Scope Review (fork) — ✅ PASSWhich legitimate operations does adjudicated, zero confirmed regressions Scope-Verdict: PASS Reason: This change doesn't tighten anything. It refactors how the dashboard's websocket stream buffers land in the store: chunks, reasoning, TIGHTENING: none -- the diff adds no refusal and names no threat. The closest change is a store-side drop of a stale buffered status line, ADJUDICATED: 7 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix, windows, any. The diff makes no assumption about a path, separator, interpreter, executable name or environment variable. It is browser-side TypeScript running in requestAnimationFrame/Redux. As a control, the candidates cover the maintainers' daily commands for the touched area in each spelling:
No platform the diff assumes is left unprobed. [SCOPE-REVIEWED] 483b378Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. |
8296dc2 to
c79eeb7
Compare
issue (non-blocking): fixed in c79eeb7.
|
|
note (non-blocking): two groups of red checks on c79eeb7, neither from this diff. Bundle Size Gate fails on main too: the Sensitive Change Review, Dependency License Gate, Internal Content Scan, Opus 5.5 Review and Security Scope Review failed at about 00:01Z before judging anything: "Could not read the PR from the API (CalledProcessError); re-run this job", "could not run", and a scope job that never finished. A re-run of those jobs would clear them; the fork account cannot re-run them, so the rebase onto #23867 restarts them. |
c79eeb7 to
e28ca26
Compare
|
note (non-blocking): rebased on main onto #23867, which raised the This head restarts the Bundle Size Gate and the five lanes that stopped before judging c79eeb7 (Sensitive Change Review, Dependency License Gate, Internal Content Scan, Opus 5.5 Review, Security Scope Review). |
|
note (non-blocking): PASS, both notes hold as written and need no change here.
|
|
note (non-blocking): PASS acknowledged, nothing to change. The status-ordering pieces exist only to keep the line in arrival order once status writes move into the flush.
|
|
note (non-blocking): agreed. No control, string or layout changes; a status label can reach the screen one frame later.
|
iamwhatever
left a comment
There was a problem hiding this comment.
Approve. Reviewed at e28ca26b6306812ea85e9dbae64cf5b59dd2362b.
The r124 item is cleared: the First Principles disposition explains why the reconnect and unmount salvage writes the status line and notifies at once. applyStreamFlush keeps arrival order and drops a buffered status once something wrote the entry directly. The equal-refinement gap the GPT lane found is closed by supersedePendingStatus in onToolCall, with a test. I checked the Design rebuttal at this head: the other two direct status writers (onChatMessage and the turn-end idle write) flush the buffer first. Every AI lane on this head is PASS or has no findings, each note has a disposition, and CI is green, including the Bundle Size Gate after the rebase onto #23867.
— crew-pr-reviewer (r125)
Problem / Motivation
Goal: A frame of stream traffic costs the web app one store dispatch however many sessions stream, so several sessions running at once do less main-thread work.
The socket buffers chat chunks, reasoning, sub-agent text and sidebar recency, then lands them once per animation frame. It landed them with one dispatch per streaming session per kind, and on top of that each chunk or reasoning frame that changed a session's status line, and every
chat_statuslabel, dispatchedsetSlotStatusDetailthe moment it arrived. With 5 sessions streaming that is 3,179 dispatches in 30 s, 1,495 chunk flushes and 905 status writes among them.Why it matters
Every dispatch runs every reducer and notifies the store's subscribers, and each mounted
useAppSelectorre-runs on a notification. On the 5-session benchmark the dispatch path takes about 370 ms per 30 s on a desktop CPU and grows with every extra streaming session.Not a goal
What changed (motivation → approach → change)
The flush in
hooks/websocket/streamBuffers.tsnow lands everything the buffers hold as onestream/flushaction (website/src/store/streamFlush.ts), on one shared frame instead of three; the hold comment inlib/streamHold.tssays so. The chat slice applies each session's reasoning, then its text, then the status line those events imply, then sub-agent text. The dashboard slice applies the recency bumps through the same writetouchSlotActivityuses. A synchronous flush before a row lands only the buffer that row must follow, so a burst of rows still coalesces recency to the frame.The status line is now written by that reducer, so
chat_chunkandchat_thinkingno longer dispatch (hooks/websocket/chatStream.ts). Achat_statuslabel (hooks/useWebSocket.ts) is buffered with the session's chunks, because a label that arrives after a chunk must win over the chunk's "streaming", and a chunk after the label must win over the label. The buffer records the store's status entry when the newest event arrived. If anything wrote the entry directly since, such as a tool call or a turn end, that write is newer and the reducer leaves it. A tool-call refinement does not merge into a tool line that a buffered label or chunk has already replaced.stream/flushchat_statuslabelstream/flushstream/flushBackwards compatibility
Compatible: the action is client-only and new.
touchSlotActivity,setSlotStatusDetail,sseThinkingChunkandsseSubagentBatchChunkskeep their reducers and every other caller. A status label and the streaming or thinking transition reach the store at most one frame later than before, and in a hidden tab with the frame flush (the 50,000-character overflow flush or the next row).Removes nothing: no reducer, action creator, stored field or public function is deleted; the stream path stops dispatching three action types it used to.
Tests
website/src/test/useWebSocket.streamFlush.test.ts(new, 10 cases). One frame of chunks, reasoning, sub-agent text and recency for four sessions is one dispatch. A chunk dispatches no status of its own. Achat_statuslabel or a tool call after a chunk keeps its status, and a chunk after either moves the line to streaming. Reasoning and text give streaming in either order. A tool refinement after a buffered label does not merge into the replaced line. A tool refinement equal to the stored line still wins over reasoning buffered before it, although the store skips that equal write. With the reducer's arrival check removed, the label and tool cases fail; with the refinement guard removed, the refinement case fails.useWebSocket.frameTrace.test.ts(the routing and lifecycle traces),useWebSocket.streamBatch.test.ts,useWebSocket.thinkingStatusChurn.test.ts,useWebSocket.slotActivityCoalesce.test.ts,useWebSocket.endedTurnFlush.test.tsandUseWebSocketCoverage.activity.test.tsx. Their assertions on final state are unchanged; status assertions now run after the frame.tsc -p tsconfig.app.jsonpass, and eslint is clean on the changed files.Manual verification
Gateway-free render benchmark from the open benchmark branch
perf/perf-bench-ci, run from a scratch copy that is not part of this diff, with two local counters added: store notifications and time spent insidedispatch. 222 sessions, open sessionperf-longwith 100 rows, desktop 1440x900, react-dom profiling build, 30 s window. main 5d7a22d against this branch, the two builds interleaved, median of 3 runs each.In the 5-session run the remaining 1,354 dispatches are 487
stream/flush(300 frames, plus a flush ahead of each of the 150 tool rows and the segment rows), 190 unread marks, 160 tool statuses, and 150 each of tool activity, tool rows and tool results. Commits and renders are unchanged in every scenario. Script ms is noisy here: the host ran at a load average near 60, and the 1-session runs spread from 1,113 to 1,302 ms across both builds.Screenshots / video
Why no screenshot: the transcript, status line and sidebar render the same pixels; a status change can reach the screen one frame later.
Related Issues
Fixes #23711
Pattern harvest
Not generalizable: this merges one module's per-frame flushes into one action; other dispatch sites are per-message and have no frame buffer to merge.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)