feat(crash-worker): add /v1/metrics ingest for opt-in agent metrics#4030
Merged
Conversation
Adds the worker side of the desktop opt-in metrics flush: a generic (date, version, os, signal, bucket) -> count table, a zod-validated /v1/metrics POST that upserts per-launch aggregate snapshots, a dedicated rate-limit bucket, and a stats-page section that breaks each signal down by bucket. The signal set is an enum and the bucket is length+charset capped, so the table can never be polluted with arbitrary keys. No install id and no content reach this endpoint — only enumerated counters. Deploy is owner-run: apply schema.sql to D1, then wrangler deploy.
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.
Worker side of the opt-in agent-metrics telemetry (desktop-only, aggregate, opt-in — per the telemetry-scope decision). This PR is the ingest + storage + stats; the desktop aggregator + opt-in flag land in a follow-up, so nothing posts here until that ships and a user turns it on.
What it adds
metricstable (schema.sql): generic(date, version, os, signal, bucket) -> count. New signals are just new rows — no migration to add one.POST /v1/metrics(index.ts): zod-validated per-launch snapshot, upserts each counter (count = count + delta).signalis an enum;bucketis^[a-z0-9_]+$capped at 32 chars, ≤64 counters/request — the table can't be polluted with arbitrary keys.METRICS_LIMITER(wrangler.toml): own rate-limit bucket (30/60), so a launch's metrics flush never eats the ping budget on a shared NAT IP.stats.ts): "Agent signals" card, each signal broken down by bucket.Privacy
No install id, no content, no keys, no prompts, no paths — only enumerated integer counters. v1 signals:
finish_reason,empty_final,provider_error,cache_hit,tool_error,compaction,turns.Deploy (owner-run)
wrangler d1 execute reasonix-crash --remote --file=schema.sql(idempotent —CREATE TABLE IF NOT EXISTS)wrangler deployTest
npm run typecheck(worker) — passNext
Desktop aggregator tapping the existing
toWireevent sink +desktop.metricsopt-in flag + settings toggle + first-run disclosure.