Feat economics observability#11
Merged
Merged
Conversation
real base ui button primitive under the same cva variants and icon slots;
asChild becomes render at 8 link-trigger call sites, nativeButton={false}
where the trigger is not a button. @base-ui/react installed alongside radix
per the migration skill; radix deps come out after the last component.
direct mappings: switch data-[state=*] hooks become data-checked/ data-unchecked, separator becomes the callable primitive with decorative dropped, avatar is 1:1. all classes unchanged; consumers source-compatible.
overlay becomes backdrop, content becomes popup (centered, no positioner); keyframe open/close animations become data-starting-style/data-ending-style transitions. layout classes and the header/footer idiom unchanged; both consumers source-compatible.
content becomes portal > positioner > popup, item highlight moves to data-highlighted, label stays a plain div (base group-label requires a group; radix label was a free div). trigger/item asChild call sites become render. all seven @radix-ui packages removed; @base-ui/react is the only primitive dependency. production build green.
Additive tables ai_review_usage, usage_counters, provider_costs_daily, economics_daily per economics-surface-contracts.md. economics_daily uses a null-safe unique index instead of a PK so the org_id null totals row is legal. Service-layer writers are idempotent on their grain; backfill seeds ai_review_usage from stored run_steps traces (both shapes), marked backfilled, cost null, source prod (only the prod worker persists traces). Contracts hold the shared constants and the pure source-derivation helper.
…w_usage writes (slice 2) Worker holds the prod OpenRouter key (OPENROUTER_API_KEY_PROD, back-compat fallback to OPENROUTER_API_KEY); eval harness uses OPENROUTER_API_KEY_EVAL. Source is derived via deriveUsageSource, never guessed. generate.ts enables usage.include and sums per-step provider cost into the trace. runWorkflows meters ai-review usage best-effort after the run persists (try/catch, run outcome unaffected); resume-run reuses persisted outcomes so no double-count. Cost flows through the trace so live writes and backfill share one read path.
GithubHttp gains an onCall metering hook (one text read serves both byte count and parse; a throwing hook can never break a forge call). The OpenRouter fetch is wrapped to size request bodies. An AsyncLocalStorage counter scopes both per run, so concurrent runs never bleed. runWorkflows runs inside that scope and writes one usage_counters row at completion (gated on meterSource, best-effort), activeMs summed from step durations.
Daily 01:40 UTC pull of OpenRouter analytics (per-key when hashes configured), Railway MTD estimated usage, and PlanetScale accrual into provider_costs_daily. Each provider is credential-gated and independently guarded, so a missing token or a failing pull skips that provider and never blocks the rest. PlanetScale always writes its interpolated flat accrual (estimated). Parse helpers and orchestration are unit-tested with injected fetch, no network. Env var names documented in .env.example.
…tion (slice 5) rollupEconomicsDay folds a UTC day's runs and prod ai_review_usage into economics_daily: one row per org plus a null-org totals row with the unattributed bucket, pulled-cost drift, Railway usage, and a credit decrement read only from prior days (idempotent delete-then-insert). COGS sums filter source=prod; eval-key pulled spend is excluded from drift. Cron 02:20 UTC after the pull. Integration-tested end to end.
…slice 6) Reads the prior day's totals row and posts a three-line Discord digest via guardedPost to ECONOMICS_WEBHOOK_URL (fallback FEEDBACK_WEBHOOK_URL). Threshold breaches (OR daily cap, drift band, Railway floor) post as [ALERT] lines. On the 1st it posts the monthly report for the closed month: accrued vs cash views (cash applies the OR credit fee), cost per run, drift, and flags for unattributed and eval-key spend. Formatters are pure and unit-tested; user copy has no em dashes. Cron 02:30 UTC.
New /admin/economics behind the existing platformAdminMiddleware staff gate. Three staff-classified server fns (overview, series, cost-by-org) wrap economics_daily reads. Thin route + page + skeleton per the frontend rules. Four metric cards (cost per run vs ceiling, metered vs accrued, drift, runs), credit burn-down and OpenRouter daily spend as dither-kit charts, a Railway floor progress bar, and a cost-by-org table with an explicit unattributed row. Registered the fns in the server-fn classification registry.
ripgrim
force-pushed
the
feat-economics-observability
branch
from
July 23, 2026 01:42
ea5016d to
21e1b14
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.