Skip to content

fix(stream): persist mid-stream failures - #3937

Merged
diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.26from
rdself:coder/stream-failure-finalization-v326
Jun 15, 2026
Merged

diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.26from
rdself:coder/stream-failure-finalization-v326

Conversation

@rdself

@rdself rdself commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

This patch fixes a second stream lifecycle gap on top of the existing v3.8.26 stream readiness work: mid-stream transport/transform failures could clear the active request from memory without going through the chat completion finalization path. In that case the Logs page entry disappeared instead of becoming a durable failed call log, even though the upstream request may already have run for a long time.

Changes

  • Route pipeWithDisconnect stream errors through a new controller onError callback so chatCore can own request finalization when appropriate.
  • Persist non-200 stream completions with status, error, error code, payload summary, and usage metadata instead of clearing pending requests directly.
  • Keep in-memory completed log detail status/error fields aligned with persisted call logs.
  • Let stream-level failure handlers signal that they already handled pending cleanup, avoiding double-finalization.
  • Merge Claude/Anthropic usage incrementally so message_start input/cache tokens are not lost when later message_delta chunks only contain output usage.
  • Preserve input_tokens / output_tokens in usage normalization for Anthropic-style streams.
  • Add regression coverage for owned stream error cleanup and Claude usage merging.

The upstream request shape is unchanged, including Claude Code compatible provider payloads.

Validation

  • node --import tsx/esm --test tests/unit/stream-handler.test.ts tests/unit/stream-utils.test.ts tests/unit/active-request-stream-chunks-lifecycle.test.ts
  • npm run typecheck:core
  • Local production run against the v3.8.26 branch with verbose stream logging enabled.

Copilot AI review requested due to automatic review settings June 15, 2026 23:32
@rdself
rdself requested a review from diegosouzapw as a code owner June 15, 2026 23:32
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@diegosouzapw
diegosouzapw merged commit e134969 into diegosouzapw:release/v3.8.26 Jun 15, 2026
2 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Obrigado, @rdself! 🙏 Excelente follow-up do #3879 — fechar o segundo gap do ciclo de vida do stream (falhas mid-stream agora viram call-log de falha durável em vez de sumir da página de Logs) é exatamente o tipo de robustez que faltava. Apreciei muito que a extração do streamFailureFinalization.ts está de fato plugada (importada e usada pelo chatCore), e o merge incremental de usage Claude evita perder os tokens do message_start. Validei localmente: typecheck:core limpo, 75/75 testes de stream/usage, eslint 0 erros, file-size + any-budget OK. Entra no próximo release. 🚀

diegosouzapw pushed a commit that referenced this pull request Jun 16, 2026
Integrated into release/v3.8.26 — keep pendingById in sync with the queue detail (Object.assign in place). Validated alongside #3937: typecheck:core clean, 42/42 request-logger + lifecycle tests, eslint 0 errors, file-size OK.
This was referenced Jun 16, 2026
@rdself
rdself deleted the coder/stream-failure-finalization-v326 branch June 24, 2026 03:25
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
Integrated into release/v3.8.26 — mid-stream failure persistence (follow-up to diegosouzapw#3879). Validated locally: typecheck:core clean, 75/75 stream/usage tests, eslint 0 errors, file-size + any-budget OK.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
Integrated into release/v3.8.26 — keep pendingById in sync with the queue detail (Object.assign in place). Validated alongside diegosouzapw#3937: typecheck:core clean, 42/42 request-logger + lifecycle tests, eslint 0 errors, file-size OK.
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.

3 participants