Skip to content

gateway: phase-7 endpoints, run cap meters, tygo in CI - #1686

Merged
Evanfeenstra merged 1 commit into
mainfrom
gateway/phase7-endpoints-cap-meters-tygo
Sep 14, 2026
Merged

Evanfeenstra merged 1 commit into
mainfrom
gateway/phase7-endpoints-cap-meters-tygo

Conversation

@Evanfeenstra

Copy link
Copy Markdown
Collaborator

Summary

Three stakgraph-only gaps from the gateway gap list, in one branch because they share the tygo-generated types.ts:

1. Cap meters on run detail (phase 9)

  • The accumulator now stamps bifrost:meta:run:<id> per chain layer (max_cost_usd, max_steps, exp, parent; agent/user on the leaf) and indexes the leaf under bifrost:runs:user:<user> (ZSET scored by exp). Same TTL axis as cost:run; idempotent HSET on every call.
  • GET /_plugin/runs/:id/state gains max_cost_usd / max_steps (null = no cap), exp, agent_name, user_id, and ancestors[] (nearest parent first, bounded walk, cycle-safe).
  • RunDetail's live-state card draws a cost and a steps meter per budgeted run in the chain; a run at/over any cap (its own or an ancestor's) badges exceeded with a note about enforce_budgets.

2. Missing phase 7 endpoints

  • /_plugin/spend/by-session, /_plugin/spend/by-model
  • /_plugin/histogram/tokens, /_plugin/histogram/latency (nearest-rank p50/p95/p99 + sample count)
  • /_plugin/sessions/:id, /_plugin/sessions/:id/summary — on metadata.session-id, not Bifrost's native session routes (those alias parent_request_id)
  • /_plugin/users/:id/spend, /_plugin/users/:id/quota (Bifrost customer budget + in-flight runs from the new index; degrades cleanly without a Customer or without Redis)
  • /_plugin/agents/:name/spend
  • Window/bucket params now accept the full Bifrost duration vocabulary (1d, 1w, 1M, …), rolling from now; the SPA picker keeps its subset. Token totals are now filled in the existing rollups (they were left at 0).
  • logstore_client_test.go added; handler tests for every new route. The e2e test against a real Bifrost is still not in CI (scripts/smoke-test.sh remains manual).

3. tygo in CI (phase 8 ship gate)

  • types.ts is now genuinely generated (make tygo, byte-stable); the non-struct types moved to ui/src/api/manual.ts (unions, ApiError, trust mirrors, Bifrost chat/usage shapes).
  • New .github/workflows/gateway-check.yml: go build/vet/test ./internal/..., make tygo-check with tygo pinned at v0.2.21, make ui-build.
  • Supersedes Gateway: reconcile tygo codegen with SPA and enforce in CI #1563 (same approach, rebased onto current main and the new endpoints).

Docs: phase 7 inventory/vocabulary/checklist brought in line with the code; by-realm references dropped from phases 7/8; phase 9 tygo section updated; UI AGENTS.md updated.

Test plan

  • go test ./internal/... green (auth: meta/index/lineage; adminapi: every new route, vocabulary, quota degradation, cap/ancestor state; logstore client)
  • go vet ./internal/..., go build ./internal/...
  • make tygo twice → identical output; tsc -b; vite build
  • RunDetail verified in the Vite dev server against a mock /_plugin backend: chained meters (warning tones, capless steps, killed ancestor), capless fallback, over-cap badge + note
  • Not verified against a real Bifrost + Redis stack (no compose run in this session)

Cap meters (phase 9): the accumulator records each chain layer's caps,
exp and parent link in meta:run:<id> and indexes the leaf run under
runs:user:<user>; /runs/:id/state serves max_cost_usd / max_steps /
ancestors, and RunDetail draws one cost + one steps meter per
budgeted run in the chain (badge "exceeded" at/over any cap).

Phase 7 remainder: spend/by-{session,model}, histogram/{tokens,latency},
sessions/:id{,/summary}, users/:id/{spend,quota}, agents/:name/spend.
Window/bucket params take the full Bifrost duration vocabulary
(rolling); token totals are filled in the existing rollups.
logstore_client_test.go plus per-handler tests.

tygo: types.ts is generated (byte-stable, tygo v0.2.21 pinned);
non-struct types live in manual.ts. New gateway-check workflow runs
go build/vet/test, make tygo-check and make ui-build on gateway/**.
Supersedes #1563.

Docs: phase 7 inventory, vocabulary and checklist match the code;
by-realm dropped from phases 7/8; phase 9 tygo section; UI AGENTS.md.
@Evanfeenstra
Evanfeenstra merged commit e4cc95d into main Sep 14, 2026
9 checks 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