fix(streaming): add delta_only mode so pure-delta chunks are never dropped (fixes #9) - #16
Open
Xuxchloris wants to merge 1 commit into
Open
fix(streaming): add delta_only mode so pure-delta chunks are never dropped (fixes #9)#16Xuxchloris wants to merge 1 commit into
Xuxchloris wants to merge 1 commit into
Conversation
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.
Fixes #9
Problem
merge_streaming_text(used byMarkdownStreamController.append) corrupts streamed text from pure incremental-delta producers: whenever a new chunk's leading character equals the trailing character of the accumulated content, that character is silently dropped.404renders as40,2100138470as210138470,2026-07-23as2026-07-2.Root cause: the merge heuristics (rewind detection
prev.startswith(chunk)and longest suffix/prefix overlap) are correct for accumulated/mixed producers but wrong for pure-delta producers — for those, every chunk is brand-new text, so a chunk like4after40(or0after210) must be concatenated, never treated as a rewind or overlap. The two semantics are indistinguishable from the(prev, chunk)pair alone, so the correct fix is to make the merge strategy explicit.Changes
lark_channel/channel/outbound/streaming/merge_text.py:merge_streaming_text(prev, chunk, *, delta_only=False)—delta_only=Trueperforms a plain concatenation (empty-input guards only), so pure-delta producers never lose characters. The default keeps the existing heuristics and behaviour unchanged.lark_channel/channel/outbound/streaming/markdown_stream.py:MarkdownStreamControllergains an optionaldelta_only: bool = Falseconstructor flag, forwarded to the merge inappend().lark_channel/channel/tests/test_streaming_primitives.py: new tests — delta-only merge for the exact issue cases (40+4→404,210+0→2100,2026-07-2+3→2026-07-23), default-mode behaviour unchanged, and a controller-level test asserting the final card content keeps every character.Verification
python -m pytest lark_channel— 992 passed; the single failure (test_upload_error_propagation.py::test_gather_buffer_missing_local_file_raises_upload_failed) is a pre-existing Windows-only path-escaping assertion unrelated to this change (CI runs on Linux).