Skip to content

fix(web): display recorded session token usage - #330

Merged
mikamikasuki merged 1 commit into
mikamikasuki:mainfrom
Dcastroro:fix/run-evidence-token-totals
Oct 22, 2026
Merged

mikamikasuki merged 1 commit into
mikamikasuki:mainfrom
Dcastroro:fix/run-evidence-token-totals

Conversation

@Dcastroro

Copy link
Copy Markdown
Contributor

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:

  • The final component tests on the unchanged base: 6 fail, 6 pass. All six new token cases reproduce the missing behavior.
  • Complete frontend suite: 108 tests pass across 20 files.
  • TypeScript and production build pass; the existing large-chunk warning remains.
  • Two real-Chrome presentation tests pass at 1440px and 390px. They create real temporary projects/nodes through the API, but deliberately mock run/session responses with synthetic counters. They check partial counts, zero versus missing, reload with a missing ledger, visible scrolled layout, and page errors. These tests do not measure model usage or prove worker accounting.
  • Changed TypeScript files pass Prettier; git diff --check passes. 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 ci reported 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.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 08:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 in SessionContinuity, 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 no usage_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

@Dcastroro

Copy link
Copy Markdown
Contributor Author

CI follow-up for 60c2cb0: the observation-integration job passed, including its PostgreSQL and production-browser checks. The local job failed in tests/test_research_freedom_execution.py::test_research_paths_do_not_import_digest_algorithms, which rejects the existing hashlib import in research/planning/workspace_analysis.py.

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.

@mikamikasuki
mikamikasuki merged commit 74ffa32 into mikamikasuki:main Oct 22, 2026
1 of 2 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.

Run Evidence does not display available Agent token totals

3 participants