fixed 0 token in openrouter steaming#6493
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where OpenRouter streaming responses resulted in zero token counts being reported. The issue occurred because OpenRouter sends usage data in chunks that don't have finish_reason set, and the code was filtering out usage unless finish_reason was present.
Changes:
- Removed the conditional check that only yielded usage when
finish_reasonis present, allowing usage to be captured regardless offinish_reasonstatus
jamadeo
left a comment
There was a problem hiding this comment.
Makes me wonder why the check is there in the first place -- does this hold up for all openai format providers?
|
you should ask the author of that line |
|
To be safe, I also tried Ollama, Xai and Tetrate providers which uses openai format, and it works. I traced the origin of the logic, it was introduced in this PR https://github.com/block/goose/pull/2677/. It was a while ago, maybe this is not valid any more. |
* main: fixed 0 token in openrouter steaming (#6493) feat(goose-acp): enable parallel sessions with isolated agent state (#6392) copilot instruction to flag prelease docs (#6504) docs: acp mcp support (#6491) feat: add flatpak support for linux (#6387) fix(code_execution): serialize record_result output as JSON (#6495) perf(google): avoid accumulating thoughtSignatures across conversation history (#6462) fix(openai): make tool_call arguments optional and fix silent stream termination (#6309) fix: Improve error messages for invalid tool calls (#6483)
oh yeah that was me. If only I could remember why I did it that way. Thanks for the fix :) |
…ased * 'main' of github.com:block/goose: Fix popular topics not starting chat when clicked (#6508) fix[desktop]: deeplink ui repeat on refresh (#6469) fixed test compilation on main branch (#6512) fix: correctly parse extension name from tool call for MCP apps (#6482) fixed 0 token in openrouter steaming (#6493) feat(goose-acp): enable parallel sessions with isolated agent state (#6392) copilot instruction to flag prelease docs (#6504) docs: acp mcp support (#6491) feat: add flatpak support for linux (#6387)
* 'main' of github.com:block/goose: (28 commits) chore(deps): bump aiohttp from 3.13.0 to 3.13.3 in /scripts/provider-error-proxy (#6539) chore(deps): bump brotli from 1.1.0 to 1.2.0 in /scripts/provider-error-proxy (#6538) docs: temp correction for agent directory (#6544) chore: upgrade rmcp (#6516) docs: clarify directory in /documentation readme (#6541) Release 1.20.0 Standalone mcp apps (#6458) don't add escaping to the command field (#6519) Fix popular topics not starting chat when clicked (#6508) fix[desktop]: deeplink ui repeat on refresh (#6469) fixed test compilation on main branch (#6512) fix: correctly parse extension name from tool call for MCP apps (#6482) fixed 0 token in openrouter steaming (#6493) feat(goose-acp): enable parallel sessions with isolated agent state (#6392) copilot instruction to flag prelease docs (#6504) docs: acp mcp support (#6491) feat: add flatpak support for linux (#6387) fix(code_execution): serialize record_result output as JSON (#6495) perf(google): avoid accumulating thoughtSignatures across conversation history (#6462) fix(openai): make tool_call arguments optional and fix silent stream termination (#6309) ...
Signed-off-by: fbalicchia <[email protected]>
Summary
Fix Issue #5907
Root Cause
When sending api request to openrouter via streaming mode, the response chunks with usage comes in the chunk without finish_reason. Example
Fix
Skip the check for
finish_reasonto get the usageType of Change
AI Assistance
Testing
Manual testing and also tested open_ai, databricks and github copilot provider using the same open_ai logic