Repository navigation
Description
Client or integration
Direct HTTP/API client
Area
Provider adapter
Summary
In the OpenAI-compatible Chat streaming adapter, one terminal error path drops the usage that was already captured from upstream. At src/adapters/openai-chat.ts:514 (dev 102ccee61), when negotiated completed-tool-block delivery (block-stop-v1, added in #7561) sees an invalid completion sequence, the stream ends with terminateWithError({ type: "error", message: "invalid negotiated tool completion sequence" }). Every other terminal path in the same generator passes pendingUsage (for example invalidChoicesEvent(pendingUsage), invalidToolCallsEvent(..., pendingUsage), upstreamErrorEvent(..., pendingUsage)). If upstream usage arrived before the invalid completion marker or a late argument fragment, those tokens are not reported for the request.
Expected: the error event carries usage: pendingUsage like the other terminal errors, so usage accounting stays complete when this path fires.
Reproduction
Found by code review during the #7561 integration (noted as a non-blocking follow-up in its merge decision comment). Not yet reproduced against a live provider.
- Enable completed-tool-block delivery for an OpenAI-compatible Chat provider (local configuration plus relay acknowledgement, as introduced in feat(responses): preserve structural tool turns #7561).
- Stream a response whose chunks report
usagebefore the tool-call completion marker. - Send a repeated completion marker, or an argument fragment after the call was marked completed, so that
observeCompletedToolBlockreturns"invalid". - Observe the terminal error event has no
usage, unlike the other stream-error paths.
A focused regression would assert that this error event includes the usage captured before it.
Version
dev 102ccee
Operating system
Platform-independent (source inspection)
Provider and model
Any OpenAI-compatible Chat provider with completed-tool-block delivery enabled
Logs or error output
invalid negotiated tool completion sequenceScreenshots and supporting files
No response
Redacted configuration
No response
Checks
- I searched existing issues and documentation.
- I removed secrets, tokens, account details, request credentials, and personal data.
Activity
lidge-jun commentedon Oct 28, 2026
Fixed on dev by #7849 (squash 1997c69): the invalid negotiated tool-completion error now carries the usage already captured.