Skip to content

[Bug]: Chat Completions streams can drop measured token totals #447

Closed

Description

@devSejung

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

OpenAI-compatible streaming replies can persist zero tokens after the provider sent a valid aggregate or omitted the usage event.

Steps to reproduce

  1. Stream a normal Chat Completions response followed by a choices-empty chunk with usage of {"total_tokens":42}.
  2. Consume the successful final assistant response in either Chat Completions stream implementation.
  3. Repeat with no usage chunk, or with complete usage followed by an empty usage object.

Expected behavior

The assistant response preserves 42 tokens. Missing telemetry is marked unknown and a later empty chunk does not overwrite measured usage.

Actual behavior

The shared usage parser ignores total_tokens and the stream defaults to zero. An empty usage object also overwrites the previous measurement.

OpenClaw version

PlatformClaw source 0a5f031.

Operating system

Ubuntu Linux, Node 24.

Install method

Source checkout in task-owned Docker.

Model

Synthetic Chat Completions fixture.

Provider / routing chain

Package provider and managed transport → Chat Completions SSE → assistant usage → retained usage report.

Impact and severity

The reporting API can undercount actual measured tokens and present unknown telemetry as zero. This follows #446; the production incidence is unknown.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions