Skip to content

feat(crash-worker): add /v1/metrics ingest for opt-in agent metrics#4030

Merged
esengine merged 1 commit into
main-v2from
feat/metrics-endpoint
Jun 11, 2026
Merged

feat(crash-worker): add /v1/metrics ingest for opt-in agent metrics#4030
esengine merged 1 commit into
main-v2from
feat/metrics-endpoint

Conversation

@esengine

Copy link
Copy Markdown
Owner

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

  • metrics table (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). signal is an enum; bucket is ^[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 page section (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)

  1. wrangler d1 execute reasonix-crash --remote --file=schema.sql (idempotent — CREATE TABLE IF NOT EXISTS)
  2. wrangler deploy

Test

  • npm run typecheck (worker) — pass

Next

Desktop aggregator tapping the existing toWire event sink + desktop.metrics opt-in flag + settings toggle + first-run disclosure.

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.
@esengine esengine requested a review from SivanCola as a code owner June 11, 2026 11:39
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 11, 2026
@esengine esengine merged commit 653ab07 into main-v2 Jun 11, 2026
14 checks passed
@esengine esengine deleted the feat/metrics-endpoint branch June 11, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant