Skip to content

Show streamed reply text formatted before its line ends - #2252

Merged
fazxes merged 9 commits into
mainfrom
fazxes/show-streamed-words-formatted
Nov 24, 2026
Merged

fazxes merged 9 commits into
mainfrom
fazxes/show-streamed-words-formatted

Conversation

@fazxes

@fazxes fazxes commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Each word of a streamed reply shows within about one frame of arriving, already formatted: bold, code, links, lists, tables, and code blocks. Formatting marks such as ** and backticks, link syntax, and pipe rows do not show while their line is open. A stray marker that will stay in the text shows as it will commit.
  • The first word of a reply shows in 18.4 ms instead of 287.3 ms (median). A 60-word paragraph starts in 18.1 ms instead of 1,792.0 ms.
  • Each later word arrives with a lag of 17.5 ms instead of 80.4 ms (median, fresh reply).
  • A line that is complete is committed exactly as before, so committed output and scrollback do not change.
  • A tall open table or code block shows its newest rows while it streams. Its older rows enter scrollback when the block ends.
  • Ctrl+C on a partial line commits the held text once and leaves no tail.
  • Terminal fx ask shows the same live text. Piped and JSON output do not.

Design

Today a line stays hidden until it ends. A paragraph line also waits for the next line, because an underline such as === can turn it into a heading. The first diagram shows that hold.

flowchart LR
  D["Text delta"] --> P["Markdown processor"]
  P -->|"closed lines, tables, and code blocks"| Q["Pacer queue"]
  P -.->|"open line, setext line, open table or code block"| H["Not shown until it closes"]
  Q --> S["Transcript store"]
  S --> R["Renderer"] --> X["Screen"]
Loading

After this change the markdown processor still commits as before. After each update it also renders a provisional tail from a copy of its state. The open line uses an open-end mode of the inline parser, so it follows the same rules as committed text. The tail travels with committed text through the same queue, and the pacer applies it only after the committed bytes before it have left the queue. The transcript store keeps the tail outside its committed entries, and the renderer draws it after them. A tail row is never final, so it never enters native terminal history.

flowchart LR
  D["Text delta"] --> P["Markdown processor"]
  P -->|"committed text, unchanged"| Q["Pacer queue"]
  P -->|"provisional tail, after committed bytes"| Q
  Q --> S["Transcript store: committed entries and tail"]
  P -->|"terminal fx ask, no pacer"| A["Ask presenter"] --> S
  S --> R["Renderer: committed, then tail"] --> X["Screen"]
Loading

Checks

Latency. Times come from benchmarks/stream_latency.ts, run as bun benchmarks/stream_latency.ts --binary <base> --binary <head> --runs 20 --scenario s1 --scenario s2 --scenario s3 --scenario s4 --json <path>. The base is origin/main at e1703a338c, and the head is 067cca3385. The next commit, 011c82a6c6, changes only test files, so the product source is the same. Both are ReleaseSafe builds, and the two binaries take turns run by run after two warm-up runs each. The script drives each build in tmux against a fake gateway that sends one word every 30 ms, and it polls the pane every 5 ms, so each time is an upper bound. The figures are medians of 20 runs. On the first commit of this change, measured against base commit f39cc4b729, the final screen and the full scrollback matched the base in 80 of 80 runs (four scenarios, 20 runs each), after masking elapsed time and token counts.

Committed output. The head matches its base commit e1703a338c byte for byte over 104,496 outputs, with 0 differing. The outputs come from two corpora of 21,124 and 5,000 documents, each run in four chunkings, on 067cca3385.

Finality holds. A geometry rebase can push native history past an active finality floor, and growth during the hold then left rows in neither native history nor the screen. finality_floor_at_or_after in src/core/output/transcript_release.zig now ignores a floor that history has already passed. The provisional tail still never enters history. main has the same gap with committed growth alone. The new test a picker close past a tool finality floor keeps all rows visible during committed growth fails on origin/main at e1703a338c and passes on this head. The preview made the case frequent, because it grows the screen during every hold.

TLA+. check.sh in tests/tla/assistant_stream/ runs ten configs, and each gives its expected verdict. The driver in tests/tla/drivers/assistant_stream/ runs the model's sequences against the built binary. Result on the head build: all 27 sequences pass for design_a, and the current variant fails all 27, as expected.

Fuzz. inline_open_end and provisional_previews are registered in tests/fuzz/targets.json and src/fuzz_targets.zig. Seven of the fuzz targets that this change reaches ran for 60 seconds each on the first commit of this change, and each finished with status ok: switch_order, agents_menu_selection, transcript_paint, markdown_lists, inline_open_end, provisional_previews, and request_wrapper_text. After the follow-up fixes, inline_open_end, provisional_previews, and markdown_lists ran again for 30 seconds each with status ok. The Fuzz workflow runs on this pull request and covers the remaining reached targets.

E2E. With FX_SOUND=0 and Bun 1.4.2, each file ran once on the merged head 067cca3385, before the test-only commit 011c82a6c6: tui-gateway-stream-lifecycle.test.ts 113 pass, ask-presentation.test.ts 29 pass, tui-resume.test.ts 98 pass, vision-route-fake-gateway.test.ts 64 pass, and tui-auth-source-selection.test.ts 236 pass, all with 0 failures. gateway-stream-lifecycle.test.ts has 268 tests: 265 pass and 1 fails. That test, default fx ask starts fresh network pacing after explicitly timed provider retries, failed three times in a row in our sandbox, and it also failed three times in the same sandbox on origin/main at e1703a338c. Main's CI run 45334067388 on e1703a338c is green, so this is treated as a sandbox environment failure, and CI decides on this head. CI runs every E2E file on this head.

Changed tests. In tests/e2e/tui-gateway-stream-lifecycle.test.ts, the token counter test no longer requires the final marker to be absent from the screen, because the open line now shows. The cancel test checks that the buffered tail appears after the visible prefix, instead of checking that it is absent before steering. Both keep their goals. In tests/e2e/tui-resize.test.ts, three checks that a streamed line is absent during the stream now allow one copy, because the open line shows in the tail while it streams. A second copy still fails. The vision, command-permissions, and resume tests waited for a final line without a newline as the end of the turn. They now wait for the live status row to go away, and six dead "Streaming (" checks now name "Generating (". A reply's last line now shows before its turn ends, so tests that waited for that line and then read saved state, compared turn-end rows, or typed the next prompt raced the turn end. The turnSettled helper in tests/e2e/tmux-helpers.ts checks that the live Generating row is gone, and 153 waits in 19 test files now also wait for it. A second pass covers keys and commands after a reply (Ctrl+G, Ctrl+O, Ctrl+X, /compact, /quit and others) at 115 sites in 25 files. Each changed test passed 5 of 5 repeated runs, and every changed file was green.

Model areas. The check lists seven TLA+ model areas near code that this change touches: agent_runtime, auth, saved_turn, and toolbox (through orchestrator.zig), agents_menu (through app_agents_runtime.zig), and subagent and turn_clock (through app_worker_runtime.zig). The edits in those files add small steps for the tail: an empty tail after each flush, a held tail that counts as unapplied work for a hidden child agent, and a tail event that child agents drop. None of them changes a turn, a login, a saved message, or a menu state that these models describe, so the models are unchanged.

Sleeps. The stream driver polls the pane every 50 ms until it has been unchanged for 200 ms. The pane gives no change signal, so this is the same pattern as waitForStableGrid.

SDK sizes. The terminal wasm draws the live text. On the merged head, fx-term.wasm measures 4,271,883 bytes, above main's budget of 4,254,000, so its budget in sdk/tests/package-size-budgets.json rises from 4,254,000 to 4,276,000. The headless core never shows live text. builds_previews in inline_render.zig compiles the preview out of fx-core.wasm, which measures 2,470,506 bytes, within the 2,475,000 budget that main already sets. The constant is true for the native binary and fx-term.wasm, so their code is unchanged by it.

Format. zig fmt --check src/ passes.

Linear: FXC-345

Formatted words now appear as they stream, so bold, code, links, lists, tables, and code blocks show their final look while their line is still open. Committed output and scrollback are unchanged. Terminal fx ask shows the same live text.
@fazxes fazxes added the ci:macos Run macOS arm64 checks on this PR label Nov 23, 2026
@vercel-internal-security-reviewer

Copy link
Copy Markdown

Security review details

…ss core

The reply preview now counts its link ids in its own counter instead of saving and restoring the shared one. A stream with no preview consumer builds no preview. Command output and a hidden main agent's due preview are handled like other appends, and test writes go to /dev/null. The fx-term size budget rises because the terminal draws the preview.
…words-formatted

# Conflicts:
#	src/ui/ask_presentation.zig
The test now passes the ask header that main introduced, as the file's other ask tests do. The fx-core budget rises by the shared code that build runs, while the preview itself is compiled out of it.
A geometry rebase can push native history past an active finality floor, and growth during the hold then left rows in neither history nor the screen. Floors that history has passed are now ignored, while the provisional tail still never enters history. The preview loses an unused helper, logs a dropped tail at deinit, and is cleared with the transcript. Streaming tests now wait for the turn to end instead of for a final line the preview shows early, and benchmarks/stream_latency.ts measures the streaming latency.
A reply's last line now shows before its turn ends, so tests that waited for that line and then read saved state, compared turn-end rows, or typed the next prompt raced the turn end. They now also wait for `turnSettled`, which checks that the live "Generating" row is gone.
…words-formatted

# Conflicts:
#	sdk/tests/package-size-budgets.json
@fazxes fazxes added the type: improvement Improves existing user-facing behavior label Nov 24, 2026
Tests that pressed a key or sent a command such as Ctrl+G, Ctrl+O, /compact, or /quit right after a reply's last line appeared could land before the turn ended, now that the line shows early. They now also wait for `turnSettled` first, and tests that act during a running turn on purpose are unchanged.
@fazxes
fazxes marked this pull request as ready for review November 24, 2026 21:43
@fazxes
fazxes merged commit d3c9b5e into main Nov 24, 2026
153 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:macos Run macOS arm64 checks on this PR type: improvement Improves existing user-facing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant