A streaming text delta that repeats everything streamed so far is missing from the recorded turn

Aperta Adatta ai principianti
#435 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@cpsievert ci sta già lavorando.

Dal 14/9/2026.

  • #436 di @cpsievert — aperta
  • #471 di @pcbeingused33 — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia con OpenAICompletionsProvider.stream_merge_chunks e stream_turn, utilizzando la riproduzione fornita di ChatCompletionChunk per tracciare come vengono accumulati e registrati i delta ripetuti. Aggiungi un test di regressione che copra ["\n", "\n", "Here is the answer."] e gli altri esempi, quindi verifica che il turno registrato corrisponda al testo completo trasmesso in streaming.

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

Descrizione

ai-triage:done Priority: Medium

If a streamed response contains a text delta identical to everything streamed before it, that delta does not make it onto the assistant turn. The caller watches the right text go by, and the turn that gets stored, and sent back as history on the next request, is short by one delta.

The easy case is a response starting with two identical deltas, which is what a leading "\n\n" often looks like coming off a local model.

No API key needed for this, it drives the completions provider's streaming contract:

from openai.types.chat import ChatCompletionChunk
from chatlas._provider_openai_completions import OpenAICompletionsProvider

provider = OpenAICompletionsProvider(api_key="unused", model="gpt-4o-mini")

def chunk(text, last=False):
    return ChatCompletionChunk.model_validate({
        "id": "chatcmpl-1",
        "object": "chat.completion.chunk",
        "created": 1,
        "model": "gpt-4o-mini",
        "choices": [{
            "index": 0,
            "delta": {"role": "assistant", "content": text},
            "finish_reason": "stop" if last else None,
        }],
    })

deltas = ["\n", "\n", "Here is the answer."]

completion = None
for i, d in enumerate(deltas):
    completion = provider.stream_merge_chunks(completion, chunk(d, last=i == len(deltas) - 1))
turn = provider.stream_turn(completion, has_data_model=False)

print("streamed:", repr("".join(deltas)))
print("turn:    ", repr(turn.text))
streamed: '\n\nHere is the answer.'
turn:     '\nHere is the answer.'

I expected both to be '\n\nHere is the answer.'.

It is not just the first two deltas. ["ab", "c", "abc"] streams abcabc and records abc, while ["ab", "c", "ab"] comes out fine, so it seems to bite when the new delta equals the whole accumulation so far.

chatlas at 7b3aa569, openai 3.13.0, python 3.12.14. Everything built on OpenAICompletionsProvider shares that call, so ChatOllama(), ChatGroq(), ChatDeepSeek() and ChatOpenRouter() are in the same boat. I found it driving the provider rather than a live model, so I cannot say how often a real stream lands on it.

Lingua principale
Python
Stelle
179
Fork
32
Merge medio
1g 3h
PR unite (30g)
10

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 posit-dev/chatlas

Tutte le issue di posit-dev/chatlas

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.