Skip to content

fix(sub): emit Anthropic SSE pings on quiet reroute streams - #221

Merged
fkiene merged 2 commits into
mainfrom
fix/sub-sse-keepalive-ping
Jul 26, 2026
Merged

fix(sub): emit Anthropic SSE pings on quiet reroute streams#221
fkiene merged 2 commits into
mainfrom
fix/sub-sse-keepalive-ping

Conversation

@fkiene

@fkiene fkiene commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Claude Code kills a stream after ~180s with no downstream SSE events (Response stalled mid-stream). Quiet Codex/Grok/Kimi turns (long reasoning, buffered tool-arg generation) went silent on the Anthropic side and aborted at exactly three minutes (incomplete_stream / no terminal frame in serve.log).
  • Live sub reroute now emits Anthropic event: ping keepalives every 15s once message_start has been sent — both on total upstream silence (tokio::select! timer) and when upstream still sends chunks that produce no client-visible ReduceEvents (buffered tool args).
  • Encoder helpers is_open / emit_ping only fire while the message is open; pings never land before message_start or after close.

Test plan

  • cargo test -p llmtrim emit_ping
  • cargo test -p llmtrim keepalive_interval
  • cargo test -p llmtrim client_abort_mid_stream
  • CI green on this PR
  • After merge: restart local daemon and confirm a multi-minute quiet sub turn no longer dies at 180s; serve.log should not show exact duration_ms≈180000 client-abort ghosts for those turns

Claude Code aborts after ~180s with no downstream events ("Response
stalled mid-stream"). Sub backends often go silent while reasoning or
while tool args are buffered, which showed up as incomplete_stream with
no terminal frame at exactly three minutes. Emit event: ping every 15s
once message_start is out — on total upstream silence and on upstream
noise that produces no client-visible events. Same shape as
claude-code-proxy's historical tool-buffer keepalive.

Signed-off-by: François Kiene <46886660+fkiene@users.noreply.github.com>
@fkiene
fkiene enabled auto-merge (squash) July 26, 2026 12:05
Signed-off-by: François Kiene <46886660+fkiene@users.noreply.github.com>
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.77982% with 70 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/llmtrim-cli/src/serve.rs 0.00% 70 Missing ⚠️

📢 Thoughts on this report? Let us know!

@fkiene
fkiene merged commit 3f3fcf0 into main Jul 26, 2026
30 checks passed
@fkiene
fkiene deleted the fix/sub-sse-keepalive-ping branch July 26, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant