Skip to content

tui: token rate uses the final metadata burst instead of model-call duration #46883

Description

@bbartels

Description

The V2 TUI can report implausibly high token throughput when a provider delivers generated usage in an atomic final event.
packages/tui/src/routes/session/rows.ts calculates turn throughput as total output tokens divided by the sum of assistant.time.streamed - assistant.time.created. This excludes the interval before the assistant record/first streamed event.
For an encrypted-thinking Bedrock response, the model worked for 71.051 seconds and returned 4,096 output tokens atomically. The assistant timing span was only 29 ms, so the footer displayed:
1m 11s · 141241.4 tok/s
The number is exactly 4096 / 0.029, even though the full call rate was about 57.6 tokens/s. The duration and throughput therefore use incompatible time spans.
Expected: use a model-call/output-generation span that includes time spent producing an atomic response, or suppress TPS when incremental generation timing is unavailable.
Actual: metadata-only/atomic streams can produce meaningless six-digit TPS values.

Plugins

No response

OpenCode version

opencode2 v0.0.0-dev-18900; current V2 source af332a2 remains affected.

Steps to reproduce

  1. Construct a user message at time 0.
  2. Construct its assistant response with time.created = 71022, time.streamed = 71051, time.completed = 71051, and tokens.output = 4096.
  3. Render the session footer with session.tps enabled.
  4. Observe 1m 11s · 141241.4 tok/s.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions