Repository navigation
llm-pi-ai drops completion_tokens_details.reasoning_tokens, so TokenUsage.reasoningTokens is never filled #11352
Replies: 1 comment
|
Confirmed on the current upstream I prepared a tested fix in my fork: zhangdw156#1. Upstream Issues and pull requests are disabled, so I am sharing it here following CONTRIBUTING.md. The fix also incorporates the zero-value distinction discussed in #10840: ...usage.reasoning === undefined ? {} : { reasoningTokens: usage.reasoning },This preserves both positive counts and an explicit I reproduced the loss through the actual Loader-mounted adapter, pi-ai Anthropic SSE parser, Local validation: 452 adapter-package tests passed, with 100% statement/branch/function/line coverage of This establishes the adapter-to-stream fix; it does not claim to resolve or verify the separate ACP/statistics projections mentioned above. It also preserves pi-ai's existing protocol-specific normalization: for example, its Chat Completions parser currently supplies |
Uh oh!
There was an error while loading. Please reload this page.
What happens
When the provider reports how much of a reply was thinking, the Harness's assistant-stream
usageframe does not carry it.TokenUsagehas areasoningTokens?field, but it is never filled, so a client can only estimate the thinking tokens instead of showing the engine's count.Environment
@deepseek-ai/dsh0.2.1-alpha.3 (the copy bundled by Strata 0.2.7)openai-chatprotocol, streaming withstream_options.include_usageEvidence
The provider's final usage chunk (streamed; the non-streamed reply has the same field):
{"prompt_tokens":54,"completion_tokens":24,"total_tokens":78, "completion_tokens_details":{"reasoning_tokens":19}}@deepseek-ai/dsh-llm-pi-ai/lib/index.js,mapUsage():The pi-ai OpenAI-completions parser sets
usage.reasoningfromrawUsage.completion_tokens_details?.reasoning_tokens;mapUsagedrops it.What I tried
I added
...(usage.reasoning > 0 ? { reasoningTokens: usage.reasoning } : {})to that function in the bundled copy, reinstalled, and theusageframe the client receives still had noreasoningTokens. So either that function is not the one that produces the frame for this route, or a later projection drops it.TokenUsageProjectionin the published types has onlyuncachedInputTokens,outputTokens,cacheReadTokens,cacheWriteTokens; if the assistant stream uses that projection, the field is lost there. Please check both layers.Expected
When the provider reports
completion_tokens_details.reasoning_tokens, the assistant-stream usage frame carries the number (for examplereasoningTokens), so clients can show the model's own count. When it is absent, the field stays absent.Impact
A client cannot show the exact thinking token count; it can only estimate from the reasoning text and mark the number as approximate.
Reproduction
Any OpenAI-compatible server that returns the field; a local one works. Open a session, send one prompt, and read the
usagechunk the assistant stream delivers: the provider sentcompletion_tokens_details.reasoning_tokens, the chunk has no reasoning count.Limits
All reactions