Skip to content

fix: handle null token usage stats without crashing sessions - #236

Merged
co-l merged 1 commit into
co-l:developfrom
theshwal:fix/null-usage-stats
Aug 12, 2026
Merged

fix: handle null token usage stats without crashing sessions#236
co-l merged 1 commit into
co-l:developfrom
theshwal:fix/null-usage-stats

Conversation

@theshwal

@theshwal theshwal commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • normalize null or missing token usage fields at the OpenAI-compatible streaming boundary
  • preserve previously reported usage values when a later streaming chunk contains partial or null usage
  • render unavailable persisted token statistics safely instead of crashing the entire session
  • display unavailable telemetry as an em dash rather than misleading zero measurements

Context

Some OpenAI-compatible providers return null for prompt_tokens, completion_tokens, and total_tokens in streaming usage chunks.

Those values were copied directly into message statistics. Persisted sessions containing null token counts or speeds could then crash AssistantMessage when formatting the values, leaving the whole session view blank.

The non-streaming path already normalizes nullish usage values.

Testing

  • Targeted tests: 27 passed
  • npm run check: passed
  • Unit/web suite: 3799 passed, 29 skipped
  • Full E2E execution remains unstable in this environment: multiple suites timed out after 10 seconds in createTestServer() setup, followed by cleanup errors for uninitialized server handles. One run also observed a timing-sensitive failure in ask-user.test.ts, where isRunning remained true after a 100 ms wait. This patch does not modify E2E infrastructure, server startup, or ask-user session state.

AI Model

OpenAI GPT-5.6

@theshwal theshwal closed this Aug 11, 2026
@theshwal theshwal reopened this Aug 11, 2026
@co-l
co-l merged commit d48f0eb into co-l:develop Aug 12, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants