Skip to content

fix: clarify token and video usage in model call logs and prevent retry messages from inheriting token usage - #586

Merged
chenyme merged 2 commits into
devfrom
display
Aug 7, 2026
Merged

fix: clarify token and video usage in model call logs and prevent retry messages from inheriting token usage#586
chenyme merged 2 commits into
devfrom
display

Conversation

@chenyme

@chenyme chenyme commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #572.

Improve usage reporting in the admin model call log:

  • Include reasoning tokens in the output total shown in the list.
  • Keep output and reasoning separately visible in a tooltip.
  • Preserve the existing four-item Token layout for text models.
  • Rename the column from Token to Usage.
  • Display video usage as two rows:
    • Input image count
    • Output video duration
  • Persist video input image count in the immutable pricing snapshot.
  • Identify video usage through trusted media_type and duration_billable markers instead of legacy durationSeconds values.
  • Ignore historical duration values that represented request latency rather than generated media duration.
  • Remove the redundant duration badge from the top-left corner of inline video previews.

Change type

  • Bug fix
  • Feature
  • Documentation
  • Refactor
  • Configuration / deployment
  • Security hardening
  • Other

Affected areas

  • Frontend / UI
  • Backend / API
  • Authentication / authorization
  • Conversations / streaming
  • Files / RAG / extraction
  • Model routing / providers
  • MCP / tools
  • Billing / payments
  • Admin console
  • Deployment / Docker / configuration
  • Documentation

Verification

  • go test ./internal/application/billing ./internal/application/conversation
  • go test ./...
  • pnpm check
  • git diff --check

The checks include Go tests, Go vet, Biome, TypeScript, and generated API contract verification.

No browser automation or external provider generation request was used.

Screenshots, API examples, or logs

Example text-model usage:

outputTokens:    309
reasoningTokens: 717
displayed output: 1,026

The output tooltip shows:

Output         309
Reasoning      717
Output total 1,026

Example video usage:

Input    1 image
Output   6 seconds

The inline video player continues to show duration in its control bar. The redundant top-left duration badge has been removed.

Configuration, migration, and compatibility notes

  • No database migration is required.
  • No environment variables or deployment configuration are changed.
  • No public API or generated Swagger contract is changed.
  • Video input image count is stored in the existing pricing snapshot as input_image_count.
  • Video records are marked with media_type: video.
  • Existing duration_billable metadata remains the trusted indicator for video duration usage.
  • Historical records without an input image count display .
  • Historical durationSeconds values are not treated as video duration unless a trusted video marker is present.
  • Text-model usage display remains backward compatible.
  • Billing calculations and settlement behavior are unchanged.

Documentation

  • Documentation is not needed for this change.
  • Documentation was updated.
  • Documentation still needs to be updated.

The behavior is limited to the existing admin log and inline video interfaces.

Security and privacy

  • No secrets, tokens, credentials, local config, or personal data are included.
  • User data access remains scoped by authenticated user context unless an admin-only path explicitly requires broader access.
  • Security-sensitive behavior was reviewed, including billing snapshots and admin usage-log access.

Only aggregate media counts and duration metadata are added to the pricing snapshot. No attachment contents, filenames, URLs, or user-provided media are copied into it.

Checklist

  • I searched existing issues and pull requests.
  • Changes are focused and do not include unrelated refactors.
  • Tests or static verification were run where practical.
  • User-facing behavior, API compatibility, and migration impact are documented.
  • Generated artifacts are included only when this project explicitly requires them.
  • Caches, build output, .pyc files, .env files, and local storage data are not committed.

@chenyme chenyme self-assigned this Aug 7, 2026
@chenyme chenyme changed the title fix: clarify token and video usage in model call logs fix: clarify token and video usage in model call logs and prevent retry messages from inheriting token usage Aug 7, 2026
@chenyme

chenyme commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Summary

Closes #583.

Fix retry-generated assistant messages incorrectly inheriting input and cache token usage from the original response.

  • Treat assistant-only retries as owners of their own prompt-side usage.
  • Preserve authoritative zero values for cache read and cache write tokens.
  • Prevent stale usage inheritance while pending, after completion, after reload, and across repeated retries.
  • Preserve existing user-side usage behavior for normal messages, user retries, edits, and continued generations.
  • Remove all frontend test files and the obsolete frontend test script.

Change type

  • Bug fix
  • Feature
  • Documentation
  • Refactor
  • Configuration / deployment
  • Security hardening
  • Other

Affected areas

  • Frontend / UI
  • Backend / API
  • Authentication / authorization
  • Conversations / streaming
  • Files / RAG / extraction
  • Model routing / providers
  • MCP / tools
  • Billing / payments
  • Admin console
  • Deployment / Docker / configuration
  • Documentation

Verification

  • pnpm check
  • go test ./...
  • git diff --check
  • Confirmed no frontend test files remain.
  • Confirmed the workspace no longer attempts to execute a frontend test script.

Screenshots, API examples, or logs

Before the fix, an assistant retry with cacheReadTokens: 0 could display the reused user message’s previous cache usage.

After the fix, retry-owned values remain authoritative:

{
  "inputTokens": 103,
  "cacheReadTokens": 0,
  "cacheWriteTokens": 0
}

Configuration, migration, and compatibility notes

  • No database migration is required.
  • No backend API contract changed.
  • No deployment configuration changed.
  • Normal messages continue to use prompt-side usage stored on their associated user message.
  • Assistant-only retries use usage stored on the generated assistant message.
  • The frontend package no longer defines a test script.

Documentation

  • Documentation is not needed for this change.
  • Documentation was updated.
  • Documentation still needs to be updated.

Security and privacy

  • No secrets, tokens, credentials, local config, or personal data are included.
  • User data access remains scoped by authenticated user context unless an admin-only path explicitly requires broader access.
  • Security-sensitive behavior was reviewed, including authentication, authorization, provider routing, file processing, billing, and admin APIs where relevant.

Checklist

  • I searched existing issues and pull requests.
  • Changes are focused and do not include unrelated refactors.
  • Tests or static verification were run where practical.
  • User-facing behavior, deployment steps, API contracts, or configuration changes are documented.
  • Generated artifacts are included only when this project explicitly requires them.
  • Caches, build output, .pyc files, .env files, and local storage data are not committed.

@chenyme
chenyme merged commit 0a82153 into dev Aug 7, 2026
11 checks passed
@chenyme
chenyme deleted the display branch August 7, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant