Repository navigation
fix(ui): keep a running chat's replay buffer small and capped - #5343
Conversation
|
Verdict: Approve with suggestions This keeps a running chat's replay buffer small: keepalives and padding are dropped, streamed answer text is merged, repeated "Model is processing" ticks collapse, and there's an 8 MB cap with a visible note when older progress is trimmed. The logic holds up, live subscribers still get every frame unchanged, and the tests reproduce the original growth.
Real-world evidenceN/A: no evidence bundle was produced for this run. The verdict rests on static review plus a local simulation of the buffer (shown below). pytest wasn't available on this runner, so the PR's own tests weren't re-run here. 🔍 Technical details🟡 Thinking tokens bypass the merge (
🟢 🟢 Byte accounting counts characters, not bytes Checked and fine
Strengths
|
Every SSE frame a turn emitted (each chunk padded to 512 bytes, a keepalive every 5 s) stayed in the run's replay buffer, so a long turn grew it without limit and each re-attach replayed all of it. The buffer now keeps only what a re-attaching client needs: keepalives and padding are dropped, consecutive chunks merge, and a 'working' status replaces the one before it. Replayed frames are padded again so the browser still flushes them at once. Past 8 MB the oldest progress is trimmed behind a note that says so.
Review follow-ups on the replay buffer: - Only the stream loop's periodic 'Model is processing' tick replaces the one before it. Other working statuses stay, so a re-attached chat shows the same rows as the live one. - Streaming text is kept as parts and joined only when replayed or when the next event closes it, instead of re-serialising the whole reply on every chunk; a reply bigger than the cap keeps its end.
Review hardening: a trim never drops the newest frame, and chunk text is sized as its JSON escape (non-ASCII text grows up to six times), so the cap holds for any language.
A thinking model streams thousands of thinking tokens, and each stayed its own replay frame, padded to 512 bytes on re-attach, so the buffer saved nothing for those turns. Consecutive thinking tokens now merge into one frame, as the chat already shows them as one step. Trimming the oldest text of an oversized reply no longer slows down past the cap.
fa404c0 to
6199bc8
Compare
Before: every SSE frame a chat turn sent stayed in that run's replay buffer: each text chunk padded to 512 bytes, plus a keepalive every 5 seconds. A long turn grew the buffer without limit, and every time the user switched back to the chat, the whole thing was replayed. After: the buffer keeps only what a re-attaching client needs to rebuild the reply, so a normal reply stays at tens of kilobytes. It's capped at 8 MB; past that the oldest progress is trimmed behind a note that says so.
Reproduced by
tests/unit/chat/ui/test_replay_buffer_bounds.py: on main, a 3,000-chunk reply keeps all 3,601 frames and nothing caps the size. Here it keeps about 600 merged frames and replays the identical answer text.Overlaps #5242 and #5337, which also edit
run_manager.py(Run.__init__,cancel()), in different lines.Test plan
pytest tests/unit/chat/ui: all passpython util/lint.py --black --isort --pylint --flake8 --test-lanes🔍 Technical details
Run._recorddrops non-data:frames (keepalives, padding comments), stores frames unpadded, merges consecutive{"type","content"}-only chunks, and replaces astatus: workingthat directly follows another. That matches how ChatView consolidates them.subscribe()pads replayed frames back to 512 bytes, the Chromium flush rule the producer already follows.