← Back to Pull requests

feat(desktop): add session-wide token and time breakdowns to the trace panel #4386

Closed
unknown closed this pull request without merging on Sep 03, 2026 10:23 UTC
View on GitHub
unknown unknown commented on Aug 31, 2026 16:06 UTC
Author

Summary

The trace (Inspector) panel added with two figures — estimated cost and cache-hit rate — while token totals and elapsed time lived only in per-turn rows. The panel now opens with two donut charts:

  • Token usage — the session's metered tokens split the way a bill reads: cache read, uncached input, output (incl. reasoning), with the dominant share in the ring center.

  • Time breakdown — recorded LLM-call time against tool-execution time with per-row counts; the center states the recorded total.
  • Ring and legend are linked in both directions: hovering either highlights that segment and dims the rest. A hairline minimum sweep keeps tiny nonzero shares visible, and the hovered segment draws a thin line so the highlight lands — the legend keeps the true figures either way.

    Data sources stay session-scoped and independent of which trace pages are loaded:

  • The token split reads the existing Session usage summary. Uncached input is the input − cacheRead residual (providers that report only the cached share leave the ledger miss at zero), floored by the ledger miss when no prompt total was reported.

  • The time split needs new aggregates: UsageSummaryV2 gains totalDurationMs (summed attempt latency from both the legacy store and the canonical ledger) and toolUsage (session-scoped totals from a new TelemetryRepo.toolSummary over the tool-invocation ledger, attached by the usage coordinator). They ride the Runtime Host usage protocol on the summary rather than being derived client-side from the buckets query: the summary is the closest seam, and the figures it returns are exact rather than a client-side re-projection of buckets that already merge legacy and canonical rows with request-weighted latency. totalDurationMs is a required key — the compatibility-epoch bump refuses hosts that predate it at the handshake. toolUsage stays optional for a data reason: tool rows predate connection attribution, so a connectionSlug-scoped query omits the split instead of sending an unscoped one.
  • Before:

  • After:

  • <img width="490" height="473" alt="image" src="https://github.com/user-attachments/assets/c4aa6904-e476-41ae-b247-00ec61b5f18f" />

    Verification

  • Typecheck clean for @maka/core, @maka/storage, @maka/runtime-host, @maka/desktop (all four desktop tsconfigs); Biome clean.

  • Suites: core 742, storage 1048, runtime-host 1462, desktop 1769 — all passing, including 18 new tests (token/duration split derivation, duration totals in projection & merge, session-scoped toolSummary, protocol optional keys, ring arc geometry and minimum-sweep floors).

  • Screenshots: attached to the PR conversation shortly (UI change; before = current main, after = this branch).
  • AI use

    Select exactly one:

  • No generative tool made a substantive contribution

  • Generative tooling made a substantive contribution
  • Tool(s) and scope: ZCode authored the implementation (desktop renderer + runtime-host protocol/coordinator + storage + core aggregates) and the tests, human-directed and reviewed locally by @bowenliang123 before opening. The commit carries the Generated-by: ZCode trailer.

    Checklist

  • Tests cover the change and fail without it

  • Lint, format, typecheck and the affected suites pass locally
  • Does this PR entail a change in behavior?

  • Yes — described under Summary above

  • No
  • Diff: 424 lines (+318 / -106) across 5 files Reviewer: bowenliang123 Review duration: 3976m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.73) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.73 · 424 lines diff across 5 files
    0.73
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.362
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.073
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #4386"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 73.2% (HIGH) · Higher = larger blast radius
    73.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.9% · Safe to merge
    28.9%
    Repository