Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

merge_streaming_text drops characters for pure-delta streaming producers

Aperta
#9 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@Xuxchloris ci sta già lavorando.

Dal 14/8/2026.

  • #16 di @Xuxchloris — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia da lark_channel/channel/outbound/streaming/merge_text.py ed esamina merge_streaming_text, poi segui il modo in cui MarkdownStreamController.append lo chiama. Riproduci i casi documentati 40+4 e 210+0 e verifica che lo streaming con delta puri preservi i caratteri di confine ripetuti, mentre la modalità del producer selezionata si comporti come previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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; only 1.0.0 / 1.1.0 / 1.2.0 exist, 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:

  1. if prev.startswith(chunk): return prev — a single-character delta such as "4"
    easily matches the tail state and gets discarded.
  2. 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
Lingua principale
Python
Stelle
17
Fork
8
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di larksuite/channel-sdk-python

Tutte le issue di larksuite/channel-sdk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.