Repository navigation
fix(web): display recorded session token usage - #330
Conversation
Fixes mikamikasuki#87. Assisted-by: OpenAI Codex.
There was a problem hiding this comment.
🟢 Approval recommended
It is a small, well-tested, presentation-only change that correctly reads ledger-bound token totals and preserves evidence-integrity invariants without touching backend state, provenance, or concurrency.
No open issues 🎉
What changed in this PR
This PR resolves issue #87 by surfacing per-run token totals (input, output, cached-input, reasoning) in the Research session area of RunEvidence, which previously rendered session status/turns/active-seconds but never the token counters already present in the /api/runs/{id}/session?summary=true response. The change is presentation-only and preserves FOREST evidence-integrity invariants: counters are read exclusively from the ledger-backed session.usage.totals, measured 0 is distinguished from absent/invalid ("unavailable"), an explicit usage_error suppresses potentially stale counts, incomplete accounting is flagged, and scientific checkpoint totals are never used as a fallback.
Changes:
- Render a
role="group""Recorded token usage" block inSessionContinuity, validating each counter as a safe non-negative integer before display and otherwise labeling it"unavailable". - Add a partial-accounting notice when
usage.usage_complete === false(and nousage_error). - Add unit tests (
RunEvidence.test.tsx), a real-Chrome presentation spec (run-evidence-tokens.spec.ts), and supporting flex-wrap CSS; reformat surrounding JSX.
| File | Description |
|---|---|
apps/web/src/RunEvidence.tsx |
Adds token-usage rendering with strict numeric validation, error suppression, and incomplete-accounting notice; reformats existing lifecycle/active-seconds JSX (no behavior change). |
apps/web/src/RunEvidence.test.tsx |
New recorded session token usage suite covering all four counters, zero-vs-missing, no checkpoint fallback, error suppression, partial accounting, and malformed/unsafe inputs; reformats existing cases. |
apps/web/tests/run-evidence-tokens.spec.ts |
New isolated Playwright presentation test at 1440px/390px using synthetic (mocked) session counters with real project/node creation and teardown. |
apps/web/src/run-evidence.css |
Adds .run-evidence-tokens flex-wrap layout occupying a full row within the session section. |
Review effort: Balanced
|
CI follow-up for 60c2cb0: the observation-integration job passed, including its PostgreSQL and production-browser checks. The local job failed in I reproduced the same single-test failure on both the unchanged base e8819a5 and this PR head. Both the failing test and the reported production file have identical Git blobs at those commits. This frontend-only PR does not change either file. The remaining frontend steps in the local job were skipped after pytest failed; the PR's local frontend/build/browser results remain as documented. No checks have been disabled. Investigation performed with OpenAI Codex assistance. |
The Research session section of run evidence omits token counters already returned by the session summary. Display the recorded input, output, cached-input and reasoning counts from
session.usage.totals, preserving zero and labeling absent or invalid counters as unavailable. Explicit ledger errors suppress potentially stale counters, and incomplete accounting remains visibly partial. Scientific checkpoint totals are never used as a fallback.Fixes #87.
Validation at
60c2cb06834bc44056247b40a2eb389bee251728:git diff --checkpasses. Production screenshots were inspected.No backend, accounting, provider, dependency, permission or workflow changes. Existing English panel copy and styling are retained. Full backend/PostgreSQL, real provider inference, dark mode and other browsers were not exercised.
npm cireported four existing dependency advisories (two moderate, two high); dependencies and the lockfile are unchanged.Implemented and tested with OpenAI Codex assistance. No independent human review is claimed.