Repository navigation
text: Commit background parses that a newer streamed chunk overtook - #3344
Merged
Merged
Conversation
TextViewState discarded every background parse result whose revision was not the latest. A stream that appends faster than a parse completes has always pushed another chunk by the time a result lands, so every result was discarded and the view showed nothing new until the stream stopped. Commit a result parsed since the text was last replaced: it is a prefix of the current text. Results from before a replacement, or older than the committed revision, are still discarded. Signed-off-by: FenjuFu <[email protected]>
trancong12102
pushed a commit
to aislopware/gpui-kit
that referenced
this pull request
Oct 1, 2026
Taken from longbridge#3344 (FenjuFu), not yet merged there. A background parse result used to be dropped whenever its revision was not the latest. A stream that appends faster than a parse completes had always moved on, so nothing landed until the stream stopped. A result parsed since the text was last replaced is a prefix of the current text, and is now committed. One from before that replacement, or older than what is already committed, is discarded. Reconciled with this fork's own changes: - The receiving task reads the state first, so that a result it discards is not an update. It now uses the same rule (`takes_parse_of`). - `commit_parsed_update` hands the result to the fork's `commit_parse`. - The fork parses a small append on the UI thread, so the two tests build on a paragraph long enough to send the append to the background parser. Co-Authored-By: Claude Code
trancong12102
added a commit
to aislopware/slopty
that referenced
this pull request
Oct 1, 2026
gpui-fast moves to 85f8347, which imports zed 1399a804. The only GPUI change is zed#64935: the which-key popup hides bindings that are disabled, and key dispatch is unchanged. longbridge/gpui-fast main 92a9b0f (#33, #34) was already in the fork. gpui-kit moves to 5b79c23a. It takes longbridge/gpui-kit#3344 ahead of its merge upstream. A background parse that a newer streamed chunk overtook used to be dropped, so a long streamed answer showed nothing until the stream stopped. Now it is committed. The receiving task still reads before it updates, so a parse it drops changes nothing. Co-Authored-By: Claude Code
trancong12102
pushed a commit
to aislopware/gpui-kit
that referenced
this pull request
Oct 2, 2026
Taken from longbridge#3344 (FenjuFu), not yet merged there. A background parse result used to be dropped whenever its revision was not the latest. A stream that appends faster than a parse completes had always moved on, so nothing landed until the stream stopped. A result parsed since the text was last replaced is a prefix of the current text, and is now committed. One from before that replacement, or older than what is already committed, is discarded. Reconciled with this fork's own changes: - The receiving task reads the state first, so that a result it discards is not an update. It now uses the same rule (`takes_parse_of`). - `commit_parsed_update` hands the result to the fork's `commit_parse`. - The fork parses a small append on the UI thread, so the two tests build on a paragraph long enough to send the append to the background parser. Co-Authored-By: Claude Code
Co-authored-by: Codex <[email protected]>
huacnlee
enabled auto-merge (squash)
October 2, 2026 13:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2634
Description
This fixes the condition @huacnlee pointed out in #2634 (comment): the result receiver in
TextViewStatedrops any background parse whose revision is not the latest one.When a stream appends faster than the background parser finishes, the next
push_str/set_textarrives while a parse is still running. By the time that parse's result reaches the receiver,state.revisionhas already moved on, so the result is dropped. The next parse has the same problem. During a steady stream every result is discarded, and the view only updates after the stream goes quiet. This also undoesMAX_COALESCED_UPDATES_PER_PARSE. That bound exists so sustained streams still render intermediate updates (#2371), but the intermediate results it produces always carry an older revision, so they were dropped too.A result parsed after the last full replacement is a prefix of the current text, and committing it is safe. The background parser builds every append on top of the document it has accumulated, so later results still contain all of the text. This PR moves the receiver body into
TextViewState::commit_parsed_updateand changes only the discard rule:full_update_revisionand newer thancommitted_revision;Everything else in the commit path is unchanged.
Real-stream cadence
To check that a real LLM stream hits this, I streamed one answer from Spark-X2.5 (the open-weight XHToken/Spark-X2.5 reasoning model, served through iFlytek Astron's OpenAI-compatible API) and timed the deltas:
reasoning_contentcontentThat is the same ~55–100 ms cadence reported in the issue, sustained for over two minutes while the model reasons. Any parse that takes longer than one gap gets overtaken.
How to Test
New tests in
crates/base/src/text/state.rs:stream_commits_a_parse_that_a_newer_chunk_overtook: pushes a chunk, then pushes the next chunk before the first one's parse lands, and checks that the overtaken parse is committed. The final parse then brings in the rest.a_parse_from_before_a_replacement_is_discarded: a parse that lands after a (background) full replacement is still discarded.cargo test -p gpui-base --lib cargo clippy -p gpui-base --all-targets -- --deny warningsI ran both on Linux in my fork's CI, along with a check that restores the old
revision != state.revisionrule and confirmsstream_commits_a_parse_that_a_newer_chunk_overtookfails without the fix: https://github.com/FenjuFu/gpui-kit/actions/runs/36841533259 (1282 passed; the old rule fails the new test).I could not run the Story app on my machine (Windows without the MSVC linker), so this is verified by the tests above, not by watching
example-stream-markdown.Checklist
cargo runfor story tests related to the changes.