Skip to content

Widget: reveal streamed text at a reading pace, code blocks whole - #533

Merged
neuromechanist merged 6 commits into
developfrom
feature/issue-531-paced-streaming
Sep 29, 2026
Merged

neuromechanist merged 6 commits into
developfrom
feature/issue-531-paced-streaming

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Closes #531.

The problem

GPT-6 Luna at maximum effort reads as "not streaming" in the widget. Measured through the real graph on dev NWB: the server does stream (300 to 380 small content events), but Luna reasons silently for about 25 s of a 26 s turn and then emits over 1,000 characters per second, so a 1,500 character answer arrives in 1.4 s. The widget drew each chunk as it arrived, so the reader saw nothing, then everything.

What this does

The widget now shows the text a reply has delivered at a reading pace instead of the pace the model happens to emit it:

  • a floor of 300 characters per second, and faster when a backlog builds (each tick shows the backlog divided by 1.5 s, so a burst decays over a few seconds: about 3 s for 1,500 characters, about 5 s for 6,000);
  • a model that streams slower than the floor is shown as it arrives, at most one 80 ms tick late;
  • a reveal ends on a word boundary, never inside a [n] citation marker, and never inside a surrogate pair;
  • fenced code is not typed out: a block is shown whole once the reveal reaches it, and code still arriving inside a block is shown as it arrives (the same fence rule the markdown renderer uses);
  • prefers-reduced-motion gets every chunk on arrival, gathered into one redraw per tick;
  • a source is listed only once its [n] marker has been shown;
  • a reader typing in a message (a thumbs-down comment) keeps their caret, and one who has scrolled up is not pulled back down by the redraws;
  • a hidden tab or a page being left shows and saves the rest of the reply at once;
  • the end of a reply finishes the reveal instead of cutting it: done and a parked browser call wait for it (at most 4 s) before the canonical text replaces the streamed text; an error, a dropped connection and a thrown failure stop it at once and keep what arrived.

This is the widget only; nothing on the server changes, so it applies to every community and every model, Claude included. Replaying a Luna-shaped burst through the widget (1,496 characters delivered in about 0.9 s): 25% on screen at 0.96 s, 50% at 1.5 s, 100% at 3.6 s.

Testing

frontend/test-widget-paced-streaming.js (112 checks; added to test.yml and tests.yml):

  • the planner is pure, and checked on strings and as a property over 162 texts and six budgets (always terminates, never past the text, never ends inside a closed code block);
  • the controller runs on a fake clock (pace, catch-up, drain bound, flush, stop, unpaced);
  • the real stream handler runs in a happy-dom window on real timers, fed a burst, observed by what the message holds while the reply is arriving (progressive growth, every state a prefix, the code drawn once and complete, a slow stream not delayed, reduced motion, error, and a browser call).

Each behavior was broken once to see the tests notice (code paced like text, no reveal, no floor, a redraw per unpaced chunk, an uncaught redraw error, sources ahead of text, a rebuilt textarea, a scroll yank, no flush on page hide, a cut marker): each fails the relevant checks. All other widget suites (test-widget-*, test-streaming, test-markdown, test-citation-markers) pass unchanged, and the frontend parity and drift tests pass.

Not verified

Nothing here ran in a real browser against the real service; the timings above are from the real widget code in happy-dom. Worth a look on the dev demo (https://develop-demo.osc.earth) after the dev deploy, with an NWB question (Luna) and a NEMAR one.

Review

An independent review found no critical defect and these, all addressed with a test that fails without the fix:

  • Reduced motion lost the 100 ms render throttle (a full redraw of the conversation per chunk: 151 for a 150 chunk burst against 2 before): one redraw per tick now.
  • A redraw that threw inside a timer left the stream promise pending and the input disabled for good (the old code rejected at once): the controller catches it, releases waiters, and hands it back through check().
  • The source list appeared ahead of the text that cites it.
  • Redraws during a long reveal pulled a scrolled-up reader back down and rebuilt a message textarea under the reader's caret.
  • Wording: "about 1.5 s" was a time constant, not a bound; "no delay added" was one tick.
  • Test gaps (abnormal end, a reader failure mid-reveal, a browser-execution continuation, timers left running, a done text that differs from the streamed text) and two tight timing bounds.
  • A reveal could cut a [12] marker or an emoji in half in text with no spaces.
  • History was saved up to 4 s after done, so leaving the page in that window lost the reply.

Refs #531. Luna at max effort thinks silently, then emits over 1000 chars/s,
so a fine stream read as everything at once. The widget now paces the
delivered text (300 chars/s floor, catch-up within ~1.5 s), shows fenced code
whole, and skips pacing under prefers-reduced-motion. Tested with the new
frontend suite in the next commit.
Refs #531. 68 checks; broken three ways (code paced, no reveal, no floor) and
each is caught. Wired into test.yml and tests.yml.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-531-paced-stre-demo.osc.earth
Branch feature/issue-531-paced-streaming
Commit fb001dd

This preview will be updated automatically when you push new commits.

…eep the reader's place

Refs #531, review findings. Unpaced mode redrew per chunk (the 100 ms throttle
was gone): now one redraw per tick. A redraw that threw inside a timer left the
stream promise pending and the input disabled: the controller now catches it,
releases waiters and check() rethrows it. Also: sources appear with their
marker, no redraw over a focused textarea, no scroll yank for a reader who
scrolled up, a reveal never ends inside [n] or a surrogate pair, and a hidden
tab or page hide flushes the reveal so the reply is shown and saved.
…es, focus, scroll, page hide

Refs #531. 112 checks; each new behavior broken once and caught (the throwing
redraw by a crash with exit 1).
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.

1 participant