feat(budget): Worker runtime budgets — CPU measurement, deploy gate, and fleet analytics #402

Merged
gmackie merged 31 commits from feat/worker-runtime-budgets into main 2026-08-23 21:34:04 +00:00
Owner

What

Worker runtime budgets: measure and enforce CPU time for Cloudflare Workers, and report compliance across the fleet.

  • @forgegraph/worker-budget — wraps a Worker's entrypoint (including an OpenNext adapter) to measure CPU time per request, clamp declared cpu_ms, and emit violations as structured telemetry. Cron and marker support included.
  • Deploy gate — a Worker declaring a limit above its plan, or an agent without the budget capability, is refused before upload instead of failing at the edge. Enforcement runs against a pinned, verified worker artifact with a bounded dependency closure.
  • Fleet analytics — /runtime-budgets dashboard plus forge budget workers cpu, forge budget violations tail, and forge budget summary.
  • Honest coverage — CPU and violation telemetry are tracked separately; coverage reads "Complete" only when both streams are complete and lossless with no dropped events, and otherwise names which stream is incomplete and how many events were lost.

Verification

  • go build ./... and go test ./... in agent/ — green.
  • tsc --noEmit for apps/web — clean.
  • vitest run in apps/web — 169 files, 1033 passed, 40 skipped.

Rebased onto main at 18b3f957 with no conflicts.

Note for review

TestImmutableWorkerArtifactRunsInstalledWranglerDryRunWithWritableScratch looked for wrangler and zod under apps/web/node_modules, but pnpm keeps workspace dependencies at the workspace root — so it hard-failed in every environment including CI and never actually exercised Wrangler. It now resolves them by walking up from the app directory the way node resolution does, and skips rather than fails a Go-only checkout. The test now genuinely runs the dry-run (~4s).

🤖 Generated with Claude Code

## What Worker runtime budgets: measure and enforce CPU time for Cloudflare Workers, and report compliance across the fleet. - **`@forgegraph/worker-budget`** — wraps a Worker's entrypoint (including an OpenNext adapter) to measure CPU time per request, clamp declared `cpu_ms`, and emit violations as structured telemetry. Cron and marker support included. - **Deploy gate** — a Worker declaring a limit above its plan, or an agent without the budget capability, is refused before upload instead of failing at the edge. Enforcement runs against a pinned, verified worker artifact with a bounded dependency closure. - **Fleet analytics** — `/runtime-budgets` dashboard plus `forge budget workers cpu`, `forge budget violations tail`, and `forge budget summary`. - **Honest coverage** — CPU and violation telemetry are tracked separately; coverage reads "Complete" only when both streams are complete and lossless with no dropped events, and otherwise names which stream is incomplete and how many events were lost. ## Verification - `go build ./...` and `go test ./...` in `agent/` — green. - `tsc --noEmit` for `apps/web` — clean. - `vitest run` in `apps/web` — 169 files, 1033 passed, 40 skipped. Rebased onto `main` at `18b3f957` with no conflicts. ## Note for review `TestImmutableWorkerArtifactRunsInstalledWranglerDryRunWithWritableScratch` looked for wrangler and zod under `apps/web/node_modules`, but pnpm keeps workspace dependencies at the workspace root — so it hard-failed in every environment including CI and never actually exercised Wrangler. It now resolves them by walking up from the app directory the way node resolution does, and skips rather than fails a Go-only checkout. The test now genuinely runs the dry-run (~4s). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gmackie force-pushed feat/worker-runtime-budgets from e2906d856a
All checks were successful
CI / gitleaks (pull_request) Successful in 6s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 9m12s
to 1663361330
All checks were successful
CI / gitleaks (pull_request) Successful in 6s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 9m12s
2026-08-23 20:42:17 +00:00
Compare
Sign in to join this conversation.
No description provided.