Skip to content

feat(pm-aggregator): quota analytics & projection section - #9363

Merged
dezren39 merged 1 commit into
mainfrom
feat/quota-analytics
Nov 13, 2026
Merged

dezren39 merged 1 commit into
mainfrom
feat/quota-analytics

Conversation

@dezren39

@dezren39 dezren39 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What

Rebuilds the /quota page's flat "at risk" strip into a proper Analytics & projection section (Drew's 2026-11-13 order), plus a read API at /api/quota-analytics.json.

Section layout (all anchored, deep-linkable)

  • #analytics-summary — at-risk strip: every pool window ≥80% used, walled or projected to wall before reset, each linking to its pool card, with unlock time (local) + duration and "after unlock: still walled" where that applies.
  • #analytics-pools / #pool-<id> — per-pool key-value cards: per window — % used, window type, reset (absolute local + duration until), projected time-to-wall (absolute + duration) from the pool's own dated readings, walls-before-reset verdict, unlock picture; burn today + 7d (calls, in/out/cache tokens, in:out ratio, cache share, recorded cost, tok/$) with the attribution basis named (credential id / provider id).
  • #analytics-breakdowns — all-route burn at last hour / today / 7d with week-over-week; model usage ratio table (call share + token share + ratios + recorded $), effort table, provider-leg table.
  • #analytics-patterns — hour-of-day (7d), day-of-week (full history), 21-day daily bars with US federal holidays labelled.
  • #analytics-activity — sessions, sub-sessions, turns, tool calls by name, skill uses, mcpx calls, fleet subcommand uses inferred from shell transcripts (labelled inferred in the UI).

Data honesty rules

  • Projections fit a least-squares slope over same-reset-period percent readings from the aggregator's snapshot store (period matched with a 2h tolerance — gatherers jitter the reported reset by seconds); states are walled / projected / no-wall-before-reset / insufficient-history, never a fabricated number.
  • Burn joins route_attempt.credential_id to quota-current's credential ids (verified live: 71.6% of attempts carry one; Antigravity attempts carry none, so its pools attribute by provider id and say so).
  • Recorded cost is shown only where the ledger records it (metered legs); subscription legs record $0 and the UI says that instead of implying free. List prices are not invented — the section links to the /aa model-review page for price data.
  • fleet subcommand use is inference from session shell transcripts and is labelled "inferred"; per-pool session attribution and direct mcpx-daemon calls are not measurable today (gap issues filed separately).

Tests

  • 16 new oracle tests (src/quota-analytics.test.ts): projection states, period jitter tolerance, WoW math, ratio math, unlock picture, holiday table, duration formatting.
  • Full suite: 2285 pass / 17 fail vs pristine-main baseline 2269 pass / 17 fail — identical pre-existing environment failures (live-service port collisions etc.), +16 new passing, no regressions. tsc: no errors in touched files (repo total unchanged).
  • Smoke-tested against live data in a worktree server: projections, unlock pictures and burns verified against quota-current.json at read time.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Rebuilds the flat "at risk" quota strip into an anchored Analytics &
projection section (Drew 2026-11-13): per-pool key-value cards with
current %, reset time + duration until reset, projected time-to-wall
(least-squares over the pool's own dated percent readings in the
snapshot store, period-matched by reset instant with a 2h tolerance
for gatherer jitter), and the unlock picture (what frees at reset vs
what stays walled on a longer window). Week-over-week duration-
until-wall where both endpoints are real projections.

Burn (calls, input/output/cache tokens, in:out ratio, cache share,
recorded cost + tokens-per-dollar) comes from the route_attempt
ledger in opencode.db, joined per pool by credential id (quota-
current's credential ids) or provider id; time scales last hour /
today / 7d (+ 7d-vs-prior-7d WoW), breakdowns by model, effort and
provider leg with usage ratios, hour-of-day / day-of-week patterns
and a 21-day daily table with US federal holidays labelled.
Activity (sessions, sub-sessions, turns, tool calls, skill uses,
mcpx calls, fleet subcommand uses inferred from shell transcripts
and labelled inferred) comes from session_v2 / session_message on a
stale-while-revalidate cache; the heavy tool-part scan never blocks
a page load. New read API: /api/quota-analytics.json.

Every number names its source in the UI; inferred series are
labelled inferred; unmeasurable metrics are absent, not invented.
16 new oracle tests for the projection / WoW / ratio math.
@dezren39
dezren39 requested a review from a team as a code owner November 13, 2026 08:07
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T08:07:58.968698Z
We couldn’t complete this review. Comment @codex review to try again.
298dd93 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 25 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f296b62-c778-448b-852f-b86456576c2b
Commits

Reviewing files that changed from the base of the PR and between 047aa8a and 298dd93.

Files selected for processing: 6

  • pm-stack/aggregator/src/analytics-store.ts
  • pm-stack/aggregator/src/quota-analytics-view.ts
  • pm-stack/aggregator/src/quota-analytics.test.ts
  • pm-stack/aggregator/src/quota-analytics.ts
  • pm-stack/aggregator/src/render.ts
  • pm-stack/aggregator/src/server.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant