fix(proxy): capture streaming token usage for passthrough providers#1567
Merged
fix(proxy): capture streaming token usage for passthrough providers#1567
Conversation
Two fixes for streaming responses logging 0 tokens: 1. Flush the passthrough buffer after stream ends so usage from the final SSE chunk is captured even without trailing \n\n. 2. Inject stream_options.include_usage for OpenAI/OpenRouter streaming requests so providers always send usage data — needed for both Manifest DB logging and downstream client context management. Closes #1477, closes #1502 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1567 +/- ##
=======================================
Coverage 97.94% 97.94%
=======================================
Files 118 118
Lines 8616 8616
Branches 3242 3242
=======================================
Hits 8439 8439
Misses 175 175
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
andychu666
pushed a commit
to andychu666/manifest
that referenced
this pull request
Apr 15, 2026
…nfst#1567) Two fixes for streaming responses logging 0 tokens: 1. Flush the passthrough buffer after stream ends so usage from the final SSE chunk is captured even without trailing \n\n. 2. Inject stream_options.include_usage for OpenAI/OpenRouter streaming requests so providers always send usage data — needed for both Manifest DB logging and downstream client context management. Closes mnfst#1477, closes mnfst#1502 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> (cherry picked from commit 158cbaf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two bugs causing streaming responses to log 0 tokens in the dashboard and return 0 tokens to downstream clients (breaking context management in agents like OpenClaw):
Passthrough buffer flush:
pipeStream()instream-writer.tsnever flushed the passthrough buffer after the stream ended. If the final SSE chunk containingusagedidn't end with\n\n, it stayed unparsed and tokens were logged as 0. Added a flush block mirroring the existing transform-path flush.stream_optionsinjection: The proxy didn't injectstream_options.include_usage: trueinto outgoing requests for OpenAI/OpenRouter. If the calling agent didn't send this field, the provider wouldn't include usage in the stream — so neither Manifest's DB nor the downstream client got token counts. Now injected automatically for streaming requests to passthrough providers.Transform paths (Google/Anthropic/ChatGPT adapters) were unaffected — they already synthesize usage chunks.
Closes #1477, closes #1502
Test Coverage
[DONE], whitespace-only)stream_optionsinjection (OpenAI, OpenRouter, non-streaming, non-passthrough, merge with existing options)Pre-Landing Review
No issues found.
Test plan
🤖 Generated with Claude Code
Summary by cubic
Fixes zero-token logs for streaming responses by capturing usage from passthrough providers. Adds a passthrough buffer flush and injects
stream_options.include_usageforopenai/openrouterstreaming requests to ensure correct token counts in the dashboard and for downstream clients.pipeStream()to parse final usage chunks without trailing\n\n.stream_options.include_usage: truefor streaming requests toopenaiandopenrouterwhile preserving existingstream_options.Written for commit 4442ecc. Summary will update on new commits.