Skip to content

Feat economics observability#11

Merged
ripgrim merged 15 commits into
mainfrom
feat-economics-observability
Jul 23, 2026
Merged

Feat economics observability#11
ripgrim merged 15 commits into
mainfrom
feat-economics-observability

Conversation

@ripgrim

@ripgrim ripgrim commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

ripgrim added 14 commits July 22, 2026 18:40
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
ripgrim force-pushed the feat-economics-observability branch from ea5016d to 21e1b14 Compare July 23, 2026 01:42
@ripgrim
ripgrim merged commit 568c807 into main Jul 23, 2026
1 check passed
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