Skip to content

fix(desktop): load session stats from telemetry on resume (#3450)#5345

Open
ashishexee wants to merge 1 commit into
esengine:main-v2from
ashishexee:fix/session-stats-telemetry-resume
Open

fix(desktop): load session stats from telemetry on resume (#3450)#5345
ashishexee wants to merge 1 commit into
esengine:main-v2from
ashishexee:fix/session-stats-telemetry-resume

Conversation

@ashishexee

Copy link
Copy Markdown
Contributor

Closes #3450

Problem

After closing and reopening the Reasonix desktop app, session stats (session cost, currency, cache hit rate) show as 0 or dash (-). Only after sending a new message do the correct stats appear. The telemetry data IS persisted to .jsonl.telemetry.json files, but it's never loaded into the frontend State on session resume.

What was happening

The backend ContextUsageForTab returned sessionTokens from persisted telemetry (correct), but sessionCost, sessionCurrency, and cache stats were never included. The frontend State only received these from live usage events during turns. On resume (before the first message), no usage events have fired, so these fields stay at their zero defaults.

StatusBar displayed:

  • sessionCost: ¥0.00 (should be actual cost from telemetry)
  • sessionCurrency: ¥ (should be actual currency from telemetry)
  • Cache hit rate (avg): - (should be computed from telemetry's cumulative cache tokens)

Changes

1. desktop/app.go — Extended ContextInfo struct

Added SessionCost, SessionCurrency, CacheHitTokens, CacheMissTokens fields. Populated from tab.telemetrySnapshot().Usage in ContextUsageForTab.

2. desktop/frontend/src/lib/types.ts — Extended ContextInfo interface

Added matching optional fields to the TypeScript interface.

3. desktop/frontend/src/lib/useController.ts — Updated case "context" reducer

The reducer now loads sessionCost and sessionCurrency from the context payload (backed by telemetry) when the values are present and positive.

4. desktop/frontend/src/components/StatusBar.tsx — Added contextAvgRate fallback

When no live WireUsage is available (resume before first message), the cache hit rate (avg) is now computed from context.cacheHitTokens and context.cacheMissTokens (loaded from telemetry), instead of showing "-".

Files Changed

File Change
desktop/app.go Extended ContextInfo with 4 new fields, populated from telemetry snapshot
desktop/frontend/src/lib/types.ts Added 4 optional fields to ContextInfo interface
desktop/frontend/src/lib/useController.ts Updated case "context" reducer to load sessionCost/sessionCurrency
desktop/frontend/src/components/StatusBar.tsx Added contextAvgRate helper, used as fallback for cache hit rate

@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 26, 2026
@ashishexee

Copy link
Copy Markdown
Contributor Author

Note on CI test failures: The 6 failing tests (TestUpdateMCPServerSplitsPastedCommandLine, TestProjectHooksSettingsUseActiveWorkspaceRootAndTrust, TestTrustProjectHooksForRootUsesDisplayedProjectRoot, TestSkillRootsViewDedupesConfiguredConventionRoot, TestSkillRootsViewDedupesConfiguredProjectConventionRoot, TestAddSkillPathRestoresConventionRootWithoutCustomPath) are pre-existing on main-v2 and unrelated to this PR.

Verified by checking out the latest main-v2 commit (5dac4f6d) and running the same tests — identical failures, identical error messages. These are Windows-specific test issues (TempDir cleanup races, backslash path handling in TOML parsing) in the desktop/ module.

Our changes only touch app.go (ContextInfo struct + ContextUsageForTab), types.ts, useController.ts, and StatusBar.tsx — none of which are related to MCP command parsing, project hooks, or skill roots.

The failures are only visible when running go test ./... from within the desktop/ directory (separate Go module). They don't appear in the root module test suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

1 participant