Skip to content

Chat stream error for an invalid negotiated tool completion omits captured usage #7841

Closed

Description

@lidge-jun

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.

  1. 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).
  2. Stream a response whose chunks report usage before the tool-call completion marker.
  3. Send a repeated completion marker, or an argument fragment after the call was marked completed, so that observeCompletedToolBlock returns "invalid".
  4. 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 sequence

Screenshots 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

  1. added
    bug
    on Oct 27, 2026
  2. added
    provider
    streaming
    tools
    on Oct 27, 2026
  3. lidge-jun commented on Oct 28, 2026

    @lidge-jun
    OwnerAuthor

    Fixed on dev by #7849 (squash 1997c69): the invalid negotiated tool-completion error now carries the usage already captured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugproviderstreamingtools

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions