Dashboard: Token outlook is blank because token usage is not reaching daily accounting #975

Closed
opened 2026-10-27 13:38:31 +00:00 by sam · 0 comments
Owner

Problem

The dashboard's Token outlook card is blank instead of showing token usage/spend. The screenshot shows the card present but with no usable content.

Investigation

The live dashboard API currently returns:

{
  "workflows": [
    {"workflow":"tdd","total_tokens":904901,"avg_tokens":301633},
    {"workflow":"implement","total_tokens":0}
  ],
  "tokens_by_day": null
}

The dashboard frontend expects tokens_by_day and renders the empty state when it is missing/empty (ui/src/dashboard/dashboard.js:405-418). The runtime therefore has token totals in the tasks table but no daily token series for the card.

The persistence path is inconsistent:

  • internal/domain/workflow/agent.go:171-176 records res.TokensUsed on the task and emits an agent_finish event with data.tokens.
  • internal/store/events.go:231-251 calculates the card data exclusively from persisted agent_finish events.
  • The live task event database currently contains task_queued and turn_completed events but no agent_finish rows, while workflow statistics still contain 904,901 tokens.
  • handleSummary serializes the nil result from TokensByDay as JSON null, rather than a stable empty array or a meaningful unavailable state.

This means the dashboard cannot truthfully show spend even though token usage is already tracked elsewhere.

Expected behaviour

  • Completed agent runs contribute to the Token outlook series and the Tokens used statistic.
  • The API returns tokens_by_day: [] rather than null when no data exists.
  • The UI distinguishes "no usage recorded yet" from "usage tracking is unavailable/broken".
  • Token totals and daily totals come from one authoritative accounting path and do not diverge.
  • The card never renders blank.

Acceptance criteria

  • Add a regression test reproducing the current state: tasks have non-zero tokens_used, but no agent_finish rows; the summary must still have a defined, truthful token state.
  • Trace and repair the event persistence path so successful and failed agent runs produce the data required by TokensByDay, including NATS/container execution.
  • Add store/API tests asserting daily aggregation, timezone/day semantics, empty data, malformed/missing token fields, and multiple stages per task.
  • Return an empty JSON array for an empty series, not null.
  • Add a UI test for populated data, no data, and unavailable/error states; verify the card cannot be visually blank.
  • Verify against a running daemon with real task data and run the normal project gate.

Scope

This issue is about truthful token accounting and the Token outlook dashboard. It does not attempt to add provider billing APIs or dollar pricing unless required to make the existing token accounting correct.

Close reason

Closed


Imported from beads archie-core-1786748942590-20-c21c728b · GitHub #515 · type bug · priority P2 · created 2026-08-14 · closed 2026-09-05

## Problem The dashboard's **Token outlook** card is blank instead of showing token usage/spend. The screenshot shows the card present but with no usable content. ## Investigation The live dashboard API currently returns: ```json { "workflows": [ {"workflow":"tdd","total_tokens":904901,"avg_tokens":301633}, {"workflow":"implement","total_tokens":0} ], "tokens_by_day": null } ``` The dashboard frontend expects `tokens_by_day` and renders the empty state when it is missing/empty (`ui/src/dashboard/dashboard.js:405-418`). The runtime therefore has token totals in the `tasks` table but no daily token series for the card. The persistence path is inconsistent: - `internal/domain/workflow/agent.go:171-176` records `res.TokensUsed` on the task and emits an `agent_finish` event with `data.tokens`. - `internal/store/events.go:231-251` calculates the card data exclusively from persisted `agent_finish` events. - The live task event database currently contains `task_queued` and `turn_completed` events but no `agent_finish` rows, while workflow statistics still contain 904,901 tokens. - `handleSummary` serializes the nil result from `TokensByDay` as JSON `null`, rather than a stable empty array or a meaningful unavailable state. This means the dashboard cannot truthfully show spend even though token usage is already tracked elsewhere. ## Expected behaviour - Completed agent runs contribute to the Token outlook series and the Tokens used statistic. - The API returns `tokens_by_day: []` rather than `null` when no data exists. - The UI distinguishes "no usage recorded yet" from "usage tracking is unavailable/broken". - Token totals and daily totals come from one authoritative accounting path and do not diverge. - The card never renders blank. ## Acceptance criteria - Add a regression test reproducing the current state: tasks have non-zero `tokens_used`, but no `agent_finish` rows; the summary must still have a defined, truthful token state. - Trace and repair the event persistence path so successful and failed agent runs produce the data required by `TokensByDay`, including NATS/container execution. - Add store/API tests asserting daily aggregation, timezone/day semantics, empty data, malformed/missing token fields, and multiple stages per task. - Return an empty JSON array for an empty series, not `null`. - Add a UI test for populated data, no data, and unavailable/error states; verify the card cannot be visually blank. - Verify against a running daemon with real task data and run the normal project gate. ## Scope This issue is about truthful token accounting and the Token outlook dashboard. It does not attempt to add provider billing APIs or dollar pricing unless required to make the existing token accounting correct. ### Close reason Closed --- _Imported from beads `archie-core-1786748942590-20-c21c728b` · GitHub #515 · type bug · priority P2 · created 2026-08-14 · closed 2026-09-05_
sam added the mediumbug labels 2026-10-27 13:38:31 +00:00
sam self-assigned this 2026-10-27 13:38:31 +00:00
sam closed this issue 2026-10-27 13:38:31 +00:00
sam added a new dependency 2026-10-27 13:42:13 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#975