Repository navigation
Usage & Billing Hub v1 + v1.1 (aggregator /quota) - #967
Conversation
Model + Source.usage() for the hub (design 2026-10-25): family-2 SaasService/PaygLine/ChargeRow/AttentionFlag/SnapshotRecord types, Provenance gains a usage facet. New saas-extract.ts parses quota-view.md Part (b) with quota-extract's fail-soft dated-read pattern (per-service highlight metrics per design §2.2, Decision-004 PAYG estimates, charges evidence, renewal-only subscriptions strip). New snapshots.ts: the §4 append-only store — monthly JSONL files, dedupe on re-append, original timestamps/source classes preserved. Bubble rules (>80% of limit, >$5 projected unbilled), freshness, and pace projection derivations in derive.ts. Collector embeds saas/payg/ charges/subscriptions sections into the fleet feed; the live source falls back to a direct quota-view+registry read, then fixtures. Manifest: quota page retitled 'Usage & billing', route unchanged.
/quota becomes the hub (design §1.1): needs-attention strip (bubble rules across both families), token-quota pool cards as before, the PAYG dollars card (counted figures per Decision 004, ranges on the detail view), family-2 SaaS cards grouped per §1.4 with highlight metrics only, domains summary card linking /dns (never forking the register), the renewal-only subscriptions strip, and the charges evidence strip. Every card carries a measured-at + source stamp; cards past their cadence dim with a stale badge. Conflicts render as a marker linking to the dated history on the detail page. v1.1 (§1.5): /quota/service/<id> + /api/quota/service.json?id= — full metric list (incl. the Cloudflare long tail), snapshot history charts with reset markers, pace projections where history supports them, all dated source reads, and recorded conflicts. /api/quota.json gains saas/payg/charges/attention/domains/ subscriptions keys; pools/burn/choices are unchanged.
scripts/backfill-usage-snapshots.ts seeds the §4 store from quota-view.md + provider-quota-registry.md dated observations (31 records, 2026-10-20 → 2026-10-25, original dates + source classes kept; idempotent via store dedupe; the ¥ DeepSeek balance is deliberately excluded — the §4 unit enum has no CNY). test/usage.test.ts (20 tests): Part (b) extraction pinned to the real phrasing, PAYG/charges evidence, bubble-rule edges (exactly 80% / exactly $5 do not bubble), store round-trip + dedupe, pace projection across a reset boundary, freshness, hub + detail renders. boot.test.ts: the quota-page assertion follows the retitle. Fixes from live runs: measuredAt comes from each section's Last-checked record (a future operational date in the section is not a read), PAYG estimate notes strip their bold label cleanly, freshness ages date-only stamps by calendar day.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou'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 56 minutes. View limit details
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 493363b2ee
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export function projectPace(records: SnapshotRecord[], metricId: string): PaceProjection | null { | ||
| const recs = records | ||
| .filter((r) => r.metricId === metricId && r.unit === "pct" && typeof r.value === "number") | ||
| .sort((a, b) => a.ts.localeCompare(b.ts)); |
There was a problem hiding this comment.
Sort snapshot timestamps by instant rather than string
When snapshot history mixes UTC timestamps and CDT offsets—as the new backfill script does with dayTs() and cdt()—lexicographic ordering is not chronological. For example, readings of 10 at 2026-10-24T12:00:00Z, 40 at 2026-10-25T12:00:00Z, and 80 at 2026-10-25T09:17:00-05:00 are sorted as 10, 80, 40. This makes projectPace() return null for increasing usage and makes resetMarkers() invent a reset; the same ordering in the snapshot store and chart renderer also corrupts history display. Compare parsed timestamps consistently across these functions instead.
Useful? React with 👍 / 👎.
Builds the Usage & Billing Hub per the approved design (
hub-design-2026-10-25.md, goalusage-billing-hub-token-quotas-per-service-saas-limits; all §6 defaults Q2–Q8 as approved). The quota page evolves in place — route stays/quota, manifest entry retitled Usage & billing.v1 — the hub page
src/saas-extract.tsparses quota-view.md Part (b) with quota-extract's fail-soft dated-read pattern: per-service highlight metrics (the §2.2 † set), Decision-004 PAYG estimates (low/high recorded; 1.2 × high counted on cards, range on detail), charges evidence, renewal-only subscriptions strip. Missing patterns → identity shells, never invented numbers./api/quota.jsonextended, not replaced:saas/payg/charges/attention/domains/subscriptionskeys added; pools/burn/choices byte-identical for existing consumers (quota-guidance).v1.1 — detail + trends (§1.5)
/quota/service/<id>+/api/quota/service.json?id=: full metric list (incl. the Cloudflare long tail — 22 metrics), snapshot history charts with reset markers, pace projections where history supports them, all dated source reads, recorded conflicts, PAYG range detail.Snapshot store (§4)
src/snapshots.ts: append-only, one JSONL file per month beside the comments/registry stores (PM_AGG_SNAPSHOTS_DIR), dedupe on re-append, original timestamps + source classes preserved; estimates stored as low/highusd-estpairs — the 1.2× rule applies at render.scripts/backfill-usage-snapshots.ts: one-shot seed from quota-view.md + provider-quota-registry.md dated observations — 31 records, 2026-10-20 → 2026-10-25, 0 unmatched patterns, idempotent re-run. (The ¥44.63 DeepSeek balance is deliberately excluded: the §4 unit enum has no CNY and recording it as USD would corrupt history.)Design decisions / deviations
Verification
bunx tsc --noEmit— clean.bun test— 102 pass / 0 fail (20 new intest/usage.test.ts;boot.test.tsquota assertion follows the retitle). Full suite re-run after merging current main./quota,/api/quota.json,/quota/service/turso, service twin all 200; strip, PAYG card, charges, pace + chart render.collect-fleet-feed.ts→ feed with hub sections + 40-domain dns): real pools, domains summary $606.70/yr, provenancelive (fleet feed …), Cloudflare detail shows history chart + conflicts + dated reads against the backfilled store.Follow-ups (not in this PR)
PM_AGG_SNAPSHOTS_DIR), then confirm the tailnet page.Need help on this PR? Tag
@codesmith-botwith what you need.