Skip to content

Add drill-through: from aggregates to the sessions that compose them - #1316

Merged
iamtoruk merged 5 commits into
mainfrom
feat/drill-through
Sep 12, 2026
Merged

iamtoruk merged 5 commits into
mainfrom
feat/drill-through

Conversation

@iamtoruk

@iamtoruk iamtoruk commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Supersedes #1295 by @ozymandiashh, rebased onto main (was 40+ commits behind, branched from effa656) with three fixes.

Drill-through: day, model, category and project aggregates open a filtered session list (the pull-request row is not wired yet: prFilters and onInvestigate are threaded through but no handler invokes them; tracked as a follow-up) with a detail drawer and navigation history, separating a session's contribution to the selection from its full cost. CLI gains sessions --format json --contributions plus optional identity fields on buildJsonReport and menubar-json.

Rebase

No textual conflicts. The dangerous part was what git could not see: the new getSessionsContributions handler landed next to #1307's Projects-pane filter without picking it up, so the drill-through would have listed unfiltered sessions under a filtered headline. Its own comment claimed "same filtering semantics as getSessions" and that was false after the rebase.

Fixes on top

  1. app/electron/main.ts — add projectArgs() to the new handler, matching getSessions. The existing "scopes every fetch by it" test now asserts the new channel; without the fix it fails (6 argv entries vs 8).
  2. src/usage-aggregator.ts + src/day-aggregator.ts — actually set categories[].rawCategory. menubar-json declared the field and forwarded it, but no producer ever wrote it, so topActivities[].rawCategory was always undefined and Overview.tsx's drillable gate was permanently false. The category drill entry was dead in both aggregation paths. Now 13/13 activities carry a raw key, and all 13 match a segment.category value.
  3. app/renderer/sections/Models.tsx — key the model drill off modelDisplayName. Contribution segments are keyed by canonical short name ("Fable 5"); the row's raw provider ids ("claude-fable-5") matched 0 of 19 segment keys on real data. modelDisplayName matches 15/19 (the other 4 are zero-cost models with no row).

Verification on real data

Contribution partition is exact: max |sum(segments.cost) - row.cost| = 6.8e-13 over 1929 sessions, and sum(segment.calls) == row.calls for every row.

Day selection vs report.daily, 2026-08-25..09-08, deltas at float noise:

day contrib sum daily row delta
08-25 801.997785 801.997785 2e-12
08-28 653.482357 653.482357 -6e-13
08-30 1038.851068 1038.851068 1e-12
08-31 1125.654153 1125.654153 5e-12
09-01 777.503609 780.028229 -2.52
09-02 543.042386 543.042386 1e-13
09-05 196.834552 196.834552 -1e-13
09-08 198.702476 198.702476 3e-14

The 09-01 gap is a pre-existing report-vs-sessions total difference, not this PR: main's CLI reproduces it to the digit ($2.524620 on both). Worth a separate look, since the drill-through headline comes from the report aggregate while the list sums from sessions.

Model selection reconciles exactly across all 19 models (max delta 2.7e-12), and sum(segment.models) == segment.cost to 7.1e-15.

Multi-day and multi-model splits, on one real 5-day session (56dea73b, $1584.457194, 2447 calls): day segments sum to the row exactly across 08-29..09-02 with calls 203/533/566/680/465 = 2447; model segments split Fable 5 / Fable 5.1 / Opus 4.8 = 1233.400116 / 337.872770 / 13.184308, summing to the row at -1.1e-12. No double counting.

Identities line up across all three outputs: every menubar topSessions and report.topSessions row resolves to a --contributions row at delta 0, projectKey == row.project everywhere, all 32 topProjects[].sessionDetails ids resolve, and projectId equals menubar topProjects[].id exactly.

Main-vs-PR on two frozen ranges (2026-08-25..09-08 and 2026-07-01..07-15): added fields only — activities[].rawCategory, topSessions[].provider|projectKey|sessionId, topProjects[].sessionDetails[].sessionId|provider. Zero removed. The only changed values are today's live row and month-to-date plan figures, which drift identically on a main-vs-main control run.

Contract and privacy

All added fields are optional and additive; no existing field renamed, removed or re-typed.

projectKey is the raw session project, which on Claude is a dash-encoded absolute path (-Users-…-Projects-eywa) — more identifying than the sibling project display name. It does not leave the machine: sanitizeForSharing empties topProjects and topSessions wholesale and drops liveSessions, and running it over the real payload removes every one of projectKey, sessionId and the dash-path string. The only absolute paths surviving sanitize are the pre-existing claudeConfigs.options[].path. withContributions's projectId (a real absolute path) and branch names are CLI-stdout only and never reach the menubar payload, sharing, or MCP.

One latent issue, not reachable today and not fixed here: src/mcp/redact.ts:29-31 and :48 redact by spreading ({...d, date: ''} / {...s, project: pseudonym(s.project)}) rather than rebuilding allowlisted objects, so the new fields would pass through unredacted — and projectKey would sit in plaintext beside the pseudonymized project. src/mcp/server.ts never serializes those arrays, so nothing exposes it now. Worth converting to an allowlist before any MCP tool returns the fuller payload.

--contributions is rejected unless plain --format json: bare, --format table, --by-pr and --by-work-unit all exit 1 with the documented message; --format json alone exits 0. serve --stdio allowlists it at src/serve.ts:107.

Known gap

The PR body advertises PR drill-through, but it does not fire. prFilters is imported in PullRequests.tsx:14 and onInvestigate is threaded through four component levels, yet neither is ever invoked — PrRowView's only handler is expand/collapse. Left as-is rather than inventing a click target; investigation.test.ts covers prFilters in isolation, which is why it reads as wired.

Two smaller ones, not fixed: Sessions.tsx:254 resets internalVisibleCount, which is dead once App.tsx:917 passes a controlled visibleCount, so removing a chip or changing sort does not reset pagination depth; and FilterChips.tsx:49 keys chips by a truncated label (sessionId.slice(0,12), or a branch's leaf directory), which can collide and drop a chip's remove button.

Tests

Root tsc --noEmit clean; npm test 294 files / 3995 passed, 5 skipped. App typecheck clean; vitest 920 passed, 27 failed in usePolled.test.ts and overviewSnapshot.test.ts only — both pre-existing and unrelated.

Mutations both caught: dropping projectArgs() fails the filter test; removing the day boundary from the segment split fails 3 contribution tests.

Lifetime on this machine (8992 sessions, 16607 segments): plain sessions --format json 2.03s/2.05s, with --contributions 2.18s/2.34s. Payload 4.66 MB to 15.16 MB.

ozymandiashh and others added 5 commits September 12, 2026 12:22
… the CLI reports

sessions --format json --contributions attaches turn-granular segments
(day, task category, carried git branch, short-model costs, active PR set)
that partition each session, so a selection can sum its exact share (20 of
a session's 100) while aggregate totals reconcile. Legacy prLinks-only
transcripts carry the whole set with the approx even-split marker, matching
the by-PR report. The menubar payload's topSessions and project
sessionDetails now carry provider + sessionId (+ raw projectKey for
topSessions) so the desktop can open the exact session behind a row, and
topActivities carries the raw TaskCategory for chips. serve learns the
--contributions flag so the desktop's resident child can answer it.
…n drawer

InvestigationFilters is a normalized, serializable selection (days,
providers, projects, models, categories, PRs, project-scoped branches,
provider-scoped sessions) with OR within a dimension and AND across them.
Contribution math walks each row's segments and multiplies per-dimension
shares, so sums reconcile every dimension's aggregate exactly; rows without
segments are excluded and disclosed. NavState + the history stack back the
in-app Back/Forward (filters, sort, page depth, open drawer) and the
restart snapshot. The drawer shows metadata, full totals beside the
in-selection figures, and the per-model/category/branch/day/PR breakdowns
with an Escape-and-focus-return contract.
…s, drawer, history

Every report grows real entries: Overview day bars, expensive sessions
(provider+id matched), model names, task categories, Spend projects,
and PR cards. The Sessions destination renders the selection chips with
per-chip removal and Clear, fetches the contributions report once per
population (widened to cover the selected days so a day outside the top-bar
period still reconciles), computes every chip combination client-side over
the full population, and shows each row's contribution beside its full
cost. Row clicks open the side drawer (Escape closes, focus returns); the
top bar gains Back/Forward (Cmd+[ / Cmd+] on macOS, Alt+arrows elsewhere)
over the in-app history; the position survives a renderer restart. IPC
gains getSessionsContributions with the same argv validation as the plain
report.
…ll entries

Rebasing onto main put the new getSessionsContributions handler beside the
Projects-pane filter from #1307 without picking it up, so the drill-through
would have listed unfiltered sessions under a filtered headline.

- main.ts: add projectArgs() to the new handler, matching getSessions; the
  existing filter test now asserts the new channel too.
- usage-aggregator/day-aggregator: actually set categories[].rawCategory.
  menubar-json already declared and forwarded it, but no producer wrote it,
  so topActivities[].rawCategory was always undefined and the category
  drill entry was permanently disabled in both aggregation paths.
- Models.tsx: key the model drill off modelDisplayName. Contribution
  segments are keyed by canonical short name ("Fable 5"); the row's raw
  provider ids ("claude-fable-5") matched 0 of 19 segment keys on real data.
@iamtoruk
iamtoruk merged commit 2d18da0 into main Sep 12, 2026
20 checks passed
iamtoruk added a commit that referenced this pull request Sep 12, 2026
…w flags

Rebased on main, which since gained #1307, #1316 and #1319.

- Delete app/renderer/lib/sampleNavigation.ts. It was a placeholder for a
  registry that never landed: #1316 ships drill-through as an onInvestigate
  callback prop plus NavState. The sample rows now call it, threaded from
  App.tsx through Compare, and open the owning session for real.
- Give a CohortObservation the provider/project/session triple the sessions
  report keys rows by (inferSessionProvider, session.project || project.project),
  so a sample resolves to exactly one session row. Without it a cohort sample
  could not build sessionRowKey at all.
- Carry projectArgs() on both cohort spawns, per #1307. The saved project
  filter now scopes the facet query and the report; --project-id still narrows
  within it. Extended the scopes-every-fetch test to cover both.
- Allow --from, --to, --category and --project-id on compare in SERVE_OPTIONS.
  Verified over stdio: before, every cohort request but the bare facet query
  came back "command not served" and fell back to a spawn.
- Catch the invalid-date throw on compare like report does, instead of an
  unhandled UsageQueryError stack trace.
- Drop the unrelated CODEBURN_USER_DATA_DIR hunk in bootstrap().
ozymandiashh pushed a commit to ozymandiashh/codeburn that referenced this pull request Sep 12, 2026
…rrors

Rebase fixes on top of getagentseal#1296.

- App.tsx shipped a stub inspectRange calling a setCustomRange that no longer
  exists after getagentseal#1316. Replaced with the real navigation: commitNav to Sessions
  with the clicked side's range AND projectFilters/modelFilters for the
  contribution key, so the drill-through lands on the population the row
  describes instead of the whole range.
- getPeriodCompare and getPeriodCompareSessions carried no projectArgs(), so a
  saved project filter did not scope either fetch (getagentseal#1307). Added, and the
  "scopes every fetch" main-process test now covers both channels.
- compare-periods --format sessions ignored --project/--exclude, so a drill-down
  could surface a session from a hidden project. It now filters like the report.
- A bad --from-a/--to-a printed a raw stack trace: parseDateRangeFlags throws
  and the null check could never fire. Wrapped in the same try/catch every other
  date-flag command uses.
- Totals card now says inline how much daily history has no session detail
  behind it. On a machine with aged-off sources the detail-only total is far
  below report/status for the same range; the Coverage card alone was three
  cards away from the number it qualifies.
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.

2 participants