larry-zy commented on PR #1609:
URL: https://github.com/apache/dubbo-admin/pull/1609#issuecomment-6380449431

   **[P2] Preserve unknown usage when the provider omits the usage object**
   
   Reviewed head: `8459ec48a4ce74caa03b9a8c2f0aab9ba9a119fe`.
   
   The presence check in 
[`ai/component/agent/react/hook_lifecycle.go:167–171`](https://github.com/apache/dubbo-admin/blob/8459ec48a4ce74caa03b9a8c2f0aab9ba9a119fe/ai/component/agent/react/hook_lifecycle.go#L167-L171)
 does not establish that the provider actually reported token usage:
   
   ```go
   if response, ok := output.(*ai.ModelResponse); ok && response != nil && 
response.Usage != nil {
       endState.InputTokens = response.Usage.InputTokens
       endState.OutputTokens = response.Usage.OutputTokens
       endState.TotalTokens = response.Usage.TotalTokens
       endState.UsagePresent = true
   }
   ```
   
   With the currently pinned Genkit v1.2.0 OpenAI-compatible adapter, a 
successful completion without a `usage` object still produces a non-nil 
`GenerationUsage` containing zero token counts. This branch marks it as 
present, and the usage recorder changes `AmountSource` to `provider` and stores 
non-null zero counts. Missing accounting information is therefore 
indistinguishable from a genuinely reported zero, contrary to this PR's stated 
contract.
   
   I reproduced this at the reviewed head using a local HTTP provider fixture 
whose successful response contains `choices` but no `usage`. The recorded event 
has `AmountSource=provider` and non-null `InputTokens=0`, `OutputTokens=0`, and 
`TotalTokens=0`; the expected values are `AmountSource=unknown` and nil token 
pointers. The existing hook-only tests construct the usage-presence flag 
directly and do not cover this adapter behavior.
   
   Please preserve explicit usage-field availability at the provider/adapter 
boundary and propagate it to the accounting hook. Add an HTTP-level regression 
covering missing/null usage and genuinely reported zero usage; checking whether 
all token counts are zero would also conflate those cases.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to