merge_streaming_text drops characters for pure-delta streaming producers
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start with lark_channel/channel/outbound/streaming/merge_text.py and inspect merge_streaming_text, then trace how MarkdownStreamController.append calls it. Reproduce the documented 40+4 and 210+0 cases, and verify that pure-delta streaming preserves repeated boundary characters while the selected producer mode behaves as intended.
Written by the indexing model from the issue text.
Description
merge_streaming_text drops characters for pure-delta streaming producers
Summary
merge_streaming_text (used by MarkdownStreamController.append) corrupts streamed
text when the producer emits pure incremental deltas. Whenever a new chunk's
leading character equals the trailing character of the already-accumulated content,
that character is silently dropped.
This surfaces in Feishu streaming cards as missing digits/characters, e.g. 404
rendered as 40, an account id 2100138470 rendered as 210138470, and
2026-07-23 rendered as 2026-07-2.
Version
lark-channel-sdk == 1.2.0(latest on PyPI; only1.0.0 / 1.1.0 / 1.2.0exist, so
there is no newer release to upgrade to).
Minimal Reproduction
Verified directly against the SDK's own function:
from lark_channel.channel.outbound.streaming.merge_text import merge_streaming_text as orig
orig("40", "4") # => "40" expected "404" (hits `prev.startswith(chunk)`, drops "4")
orig("210", "0") # => "210" expected "2100" (trailing "0" overlaps leading "0", dropped)
Actual output:
orig 40+4 => '40'
orig 210+0 => '210'
Expected vs. Actual
Input (prev, chunk) |
Expected | Actual | Dropped | Branch hit |
|---|---|---|---|---|
("40", "4") |
"404" |
"40" |
trailing 4 |
prev.startswith(chunk) |
("210", "0") |
"2100" |
"210" |
one 0 |
longest suffix/prefix overlap |
Root Cause
lark_channel/channel/outbound/streaming/merge_text.py:
def merge_streaming_text(prev: str, chunk: str) -> str:
if not chunk:
return prev
if not prev:
return chunk
if chunk.startswith(prev):
return chunk
if prev.startswith(chunk): # (1) drops a delta that is a prefix of prev
return prev
# Find the longest suffix of prev that is a prefix of chunk.
max_overlap = min(len(prev), len(chunk))
for size in range(max_overlap, 0, -1):
if prev[-size:] == chunk[:size]: # (2) drops the "overlap" region
return prev + chunk[size:]
return prev + chunk
The function tries to auto-detect accumulated vs. delta vs. mixed producers from the
text content alone. Two of its heuristics are invalid for pure delta producers:
if prev.startswith(chunk): return prev— a single-character delta such as"4"
easily matches the tail state and gets discarded.- The "longest suffix-of-prev that is a prefix-of-chunk" dedup deletes the overlap,
so any delta whose first char equals the accumulated tail loses that char.
As a result, repeated digits (00, 404) and boundary characters are the most
frequently corrupted.
Impact
Google ADK's LiteLlm streaming yields pure deltas (each SSE event carries only the
newly generated text, not the running total):
# google/adk/models/lite_llm.py
elif isinstance(chunk, TextChunk):
text += chunk.text
yield _message_to_generate_content_response(
ChatCompletionAssistantMessage(role="assistant", content=chunk.text), # delta only
is_partial=True,
model_version=part.model,
)
Any integration that forwards these deltas to MarkdownStreamController.append will
lose characters in the rendered card.
Suggested Fix
Do not infer the producer mode from content. Provide an explicit mode (e.g.
append_mode="delta" | "accumulated") so delta producers use plain concatenation:
def merge_streaming_text(prev: str, chunk: str) -> str:
return (prev or "") + (chunk or "") # correct for pure-delta producers
Workaround
Monkeypatch the merge function to a plain concatenation before streaming:
from lark_channel.channel.outbound.streaming import markdown_stream
def _concat(prev: str, chunk: str) -> str:
return (prev or "") + (chunk or "")
markdown_stream.merge_streaming_text = _concat
Verified after patching:
orig 40+4 => '40' # buggy
orig 210+0 => '210' # buggy
patched 40+4 => '404' # correct
patched 210+0 => '2100' # correct
- Dominant language
- Python
- Stars
- 17
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from larksuite/channel-sdk-python
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
-
webhook: signature verification silently no-ops without encrypt_key; no timestamp-freshness or replay checksPossibly taken @Xuxchloris claimed this 56 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Long threaded reply leaks out of a topic/thread chat: reply_to dropped on chunks after the firstPossibly taken @Ydz0616 claimed this 94 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
All issues in larksuite/channel-sdk-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
EvaluationSuite.run fails with default args_for_task and mutates supplied kwargsPossibly taken @ktz03 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
huggingface/evaluate#825 ·
Maintainers usually reply within 1 day
-
dependencies feature github_actions good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
wemake-services/wemake-django-template#3149 ·
Maintainers usually reply within 1 day
-
[request] vsg/1.1.16Openupstream update
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
conan-io/conan-center-index#31142 ·
Maintainers usually reply within 1 day
-
area:core bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day