llm: ignore llama-server SSE ping comments (#16443)

llama.cpp b9478 added a default 30s SSE ping that emits colon-only comment frames (":\n\n") while streamed requests are idle; Ollama treated non-data SSE lines as JSON, so skip SSE comments in completion and chat streams.
This commit is contained in:
Daniel Hiltgen
2026-06-02 15:40:14 -07:00
committed by GitHub
parent 7a2073d17b
commit e828061b6e
2 changed files with 9 additions and 0 deletions

View File

@@ -1507,6 +1507,9 @@ func (s *llamaServerRunner) Completion(ctx context.Context, req CompletionReques
if len(line) == 0 {
continue
}
if bytes.HasPrefix(line, []byte(":")) {
continue
}
evt, ok := bytes.CutPrefix(line, []byte("data: "))
if !ok {
@@ -1794,6 +1797,9 @@ func (s *llamaServerRunner) Chat(ctx context.Context, req ChatRequest, fn func(C
if len(line) == 0 {
continue
}
if bytes.HasPrefix(line, []byte(":")) {
continue
}
evt, ok := bytes.CutPrefix(line, []byte("data: "))
if !ok {

View File

@@ -131,8 +131,10 @@ func TestLlamaServerCompletionSSEParsing(t *testing.T) {
sseLines := []string{
`data: {"content":"Hello","stop":false}`,
``,
`:`,
`data: {"content":" world","stop":false}`,
``,
`:`,
`data: {"content":"","stop":true,"stop_type":"eos","timings":{"prompt_n":5,"prompt_ms":10.5,"predicted_n":2,"predicted_ms":20.3}}`,
``,
}
@@ -277,6 +279,7 @@ func TestLlamaServerChatPromptEvalCountIncludesCache(t *testing.T) {
case "/v1/chat/completions":
w.Header().Set("Content-Type", "text/event-stream")
fmt.Fprintln(w, `data: {"choices":[{"delta":{"content":"Hello"}}]}`)
fmt.Fprintln(w, `:`)
fmt.Fprintln(w, `data: {"choices":[{"delta":{},"finish_reason":"stop"}],"timings":{"cache_n":12,"prompt_n":5,"prompt_ms":10,"predicted_n":2,"predicted_ms":20}}`)
fmt.Fprintln(w, `data: [DONE]`)
default: