Skip to content

fix(markdown): stream Markdown cheaply and converge with one parse - #66

Merged
Ericky14 merged 1 commit into
masterfrom
feat/incremental-markdown
Oct 30, 2026
Merged

Ericky14 merged 1 commit into
masterfrom
feat/incremental-markdown

Conversation

@Ericky14

@Ericky14 Ericky14 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

agentos-chat-panel feeds every streamed LLM delta to markdown::Content::push_str. Each push re-parses the whole last block, so a long list gets slower with every token. The streamed result can also differ from parsing the finished text: an image shows twice, a reference link stays broken, or a closed metadata block is not swallowed.

Fix

  • push_str re-parses only the last bullet of a list, so a push costs about the same however long the list is.
  • A stream of pushes gives the same items and images as one parse of the same text, whatever the chunks.
  • TeX math (ENABLE_MATH) stays on.
  • A highlighted code line now continues from the line before it, so a string spanning lines keeps its colour.
  • Ported from upstream iced-rs/iced#3465, adapted to our highlighter.

Testing

  • New widget/tests/markdown.rs: upstream's convergence tests and fuzzer, plus math cases and a highlighter case. 42 pass (43 with highlighter). Against master, 21 of the 42 fail.
  • cargo lint and cargo fmt --check pass.
  • agentos-chat-panel against this branch: all 20 tests pass, including a new check that a streaming reply renders like the finished text. It fails on master at the image line. The check waits on chat-panel's test/streamed-markdown branch until chat-panel moves to this iced.
  • Streaming a 20 KB reply (a 200-item list, a table, a code block) in 4-byte deltas, release build: 148 ms before and 8 ms after through chat-panel's chat entry; 328 ms before and 8 ms after into one markdown::Content.
  • Nothing changes on screen apart from the broken cases above, so there are no images.

To try it:

  1. cargo test -p iced_widget --test markdown
  2. cargo test -p iced_widget --features highlighter --test markdown highlight

🤖 Generated with Claude Code

Port of upstream `iced-rs#3465`, keeping our TeX math option and
adapting its code-highlighter commit fix to our `Highlighter`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ericky14
Ericky14 merged commit 32049c2 into master Oct 30, 2026
8 checks passed
@Ericky14
Ericky14 deleted the feat/incremental-markdown branch October 30, 2026 15:29
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