Skip to content

feat(gateway): add per-member usage limit policies - #5056

Merged
OmarMcAdam merged 4 commits into
devfrom
ai-gateway-usage-buckets
Sep 17, 2026
Merged

OmarMcAdam merged 4 commits into
devfrom
ai-gateway-usage-buckets

Conversation

@OmarMcAdam

@OmarMcAdam OmarMcAdam commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds configurable, per-member estimated-cost Usage Limit Policies to AI Gateway, with Den administration and Desktop usage/increase-request workflows.

  • Policies contain one limit per day/week/month, with hard limits and increase requests enabled by default. USD amounts use integer micro-USD.
  • Assign policies to people or teams. Team allowances apply independently to each person; the largest allowance wins for each timeframe. Unassigned members remain unlimited by this feature.
  • Calendar periods reset at 05:00 UTC: daily, Monday weekly, and day 1 monthly.
  • Gateway rejects new requests once a hard allowance is exhausted; soft limits continue accounting and warn. Existing cost estimation is reused; legacy OpenWork Models limits remain separate.
  • Increase approval grants one additional 25% of the bucket's base allowance without clearing consumption or moving reset time.
  • Durable accounting identities, historical replay quarantine, entitlement-change invalidation, concurrent-review protection, and organization-erasure cleanup.
  • Legacy/v2 runtime hooks terminate verified policy 429 errors instead of retrying them as upstream throttling.

UI refinement batch

  • Usage Limits below Providers; compact empty state with the create-policy action.
  • Increase-request section hidden without active policies; compact pending/history states and local last-checked timestamps.
  • Two-row request layout: user/reason/time/actions above smaller bucket context; opaque request IDs removed.
  • Clearer policy form, amount validation shown only on error, and selected-timeframe reset notes.
  • Consistent Request Increase terminology, direct reason form, local reset timestamps, amber pending badge, and green approval notice/usage icon across sessions.
  • Shared table detail-row support reuses existing primitives. Refinements follow DESIGN.md P1/P3 (state and disclosure), S2/S3 (compact rows), and V2 (semantic colors). Screenshot/visual review remains outstanding.
  • Adds worlds/gateway-local.ts: an isolated, loopback-only, two-hour local stack for manually supplied provider keys. No credentials or live test data are committed.

Data and rollout

New Drizzle migrations: 0102_gateway_usage_limits, 0103_gateway_usage_replay_quarantine, and 0104_gateway_usage_reset_pagination. Most generated diff volume is their schema snapshots. Migrations were exercised against disposable databases only; no production migration or deployment was performed by this work.

Verification

Current UI batch: focused checks passed; overall verification is incomplete.

Before committing 7272f7916728df651085c54b2f60b433ba1644d5:

  • Den usage-limit UI: 26 passed; adjacent provider-page tests: 16 passed.
  • Desktop Gateway usage UI: 23 passed; state: 14; transport: 7; refresh: 4.
  • Adjacent Gateway connect: 4; provider sync: 14; providers: 2; identity-recheck composer: 1 passed.
  • App typecheck, Den typecheck, narrow Den usage-limit typecheck, and whitespace checks passed.
  • Session owner-flip, snapshot-error, and focus-continuity fixtures still have unresolved failures; Den's next lint entrypoint also fails. These are not represented as green checks.
  • The end-to-end journey selectors were updated for the intentional UI changes, but the journey was not rerun on this head.

Historical context only: both local legacy and v2 Gateway policy journeys passed on earlier revision 0fb1843b6, exercising real Den/Gateway/Electron with an isolated database and deterministic upstream. Those receipts are not current-head evidence after the rebase and refinements.

Reproduction commands for current-head full integration:

pnpm evals:e2e gateway-usage-policy --local
pnpm evals:e2e gateway-usage-policy --local --engine v2

CI on the previous head reported API-contract, generated-SDK, migration-sync, core-test, and required-verification failures. The new head needs fresh CI results; none of these checks are being bypassed.

Remaining limitations

  • No automatic provider-side reconciliation worker for observations lost during crashes or exhausted finalization retries. Unresolved/quarantined records remain explicit.
  • Hard limits check settled estimates rather than reservations; in-flight/concurrent usage may overshoot. Unexpected incomplete accounting after dispatch does not automatically suspend later admissions.
  • Native engine terminal-error serialization exposes limited metadata. Authenticated own-status supplies detailed Desktop notices.
  • Visual verification, complete repository regression coverage, and load testing remain outstanding. Evidence-report publication was previously blocked by missing review-app configuration.

Marked ready for human review at the author's request. Auto-merge, when enabled, remains subject to GitHub's required checks and approvals; this is not a claim of release readiness.

@vercel

vercel Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 17, 2026 6:15pm UTC
openwork-den Ready Ready Preview Sep 17, 2026 6:15pm UTC
openwork-diagnostics Ready Ready Preview Sep 17, 2026 6:15pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
openwork-landing Ignored Ignored Preview Sep 17, 2026 6:15pm UTC

@OmarMcAdam

OmarMcAdam commented Sep 16, 2026 •

Copy link
Copy Markdown
Member Author

Review follow-up — 6563997

Overall verification: Incomplete. This supersedes the earlier-head summary; historical passing journeys are not current-head evidence.

Addressed

  • Eight review threads fixed and resolved: immutable Docker image pins, title-only usage surfaces, no raw identifiers in provenance, labeled metadata, neutral blocked treatment, dialog depth, flat member buckets, and explicit approval spending/no-undo context.
  • Admin identity lookup retained as a private feature, strengthened with private/no-store responses and real-session authorization/log-privacy tests. The disputed finding remains open for reviewer re-evaluation.
  • Regenerated OpenAPI/SDK artifacts; corrected the DB-only test import and clean Bun source-export failures; isolated three server test runtime stores.
  • Replaced the post-approval direct-fetch check with a real Desktop composer/native-engine completion assertion. Its successful execution is still outstanding.

Passing focused checks on the committed source changes

  • Desktop usage UI: 23 passed.
  • Den usage-limit UI: 28 passed.
  • Real-session API privacy: 5 passed / 145 assertions; API routes: 3 passed.
  • Usage database suite: 25 passed.
  • Runtime/package production regressions: 5 passed.
  • Relevant app/server/API/DB/SDK typechecks, API lint, SDK consistency, OpenAPI snapshot comparison, Evals typecheck/browser checks, and whitespace checks passed.

Remaining gaps

  • Local v1/v2 E2E attempts failed; the final blocker was a Chrome Page.navigate timeout during isolated Den navigation. No run reached the new post-approval composer assertion. Latest diagnostic CLI record: evals/results/.testkit/cli-run-1789668015873.json (local only).
  • General DB execution includes skipped database-dependent cases; separate usage-specific DB cases ran successfully. Six other migration cases still need their isolated database prerequisites.
  • Full core verification is not green; a desktop CA fixture still fails. Layer/channel/boundary checks and the unsupported Den lint entrypoint also remain unresolved.
  • Partial synthetic-fixture screenshots exist locally, but complete approval/recovery screenshots and public artifact links are not available. No screenshot is being used to imply a passing E2E verdict.

Required CI/review gates and auto-merge policy remain unchanged.

Comment thread apps/app/src/app/lib/den.ts Resolved
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Warden review summary — Blocked

Native findings: 14. Blocking policy matches before consolidation: 3. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run

Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (678630 ms), confidentiality-review (184628 ms), spec-provenance-review (663475 ms), desktop-den-sync-review (920206 ms), design-spec-review (1354627 ms).

Blockers

  • 35G-RRA · medium · diff-security-review · worlds/gateway-local.ts:108
  • 5P5-ECH · medium · confidentiality-review
  • BWX-MZR · high · desktop-den-sync-review · apps/app/src/app/lib/den.ts:22

Advisories

  • 69K-G4P · medium · spec-provenance-review · evals/specs/gateway-usage-policy.e2e.test.ts:227
  • W52-ND9 · low · design-spec-review
  • JA3-GUA · low · design-spec-review · apps/app/src/react-app/domains/cloud/gateway-usage-panel.tsx:95
  • J3N-6DU · medium · design-spec-review · apps/app/src/react-app/domains/cloud/use-gateway-usage.ts:89
  • 2WC-ZGX · medium · design-spec-review · apps/app/src/react-app/domains/cloud/use-gateway-usage.ts:97
  • F3M-LDK · medium · design-spec-review · apps/app/src/react-app/domains/cloud/use-gateway-usage.ts:32
  • KSC-TLY · low · design-spec-review
  • A4K-ALQ · medium · design-spec-review
  • H69-FP3 · medium · design-spec-review
  • PGT-27S · medium · design-spec-review
  • 8UT-NCW · medium · design-spec-review

Needs recheck

  • None.

Observed review-thread metrics

  • Unique observed run attempts in retained window: 2
  • Distinct heads in retained window: 2
  • Current unresolved Warden threads: 11 of 11 observed
  • Observed resolved/unresolved transitions in retained snapshots: 0 / 0
  • First observed resolved/unresolved (state at first collection, not event time): 0 / 11
  • Precision: unavailable (no adjudications; no TP/FP values are inferred)
  • Observation window: 2/20 run attempts retained; truncated: false
  • Transition snapshot: 11/11 current attributed threads retained (limit 500); truncated: false

Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority.

Comment thread worlds/gateway-local.ts Resolved
@mintlify

mintlify Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
differentai 🟢 Ready View Preview Sep 17, 2026, 6:15 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@OmarMcAdam
OmarMcAdam merged commit 9b0adb8 into dev Sep 17, 2026
40 checks passed

This branch was successfully deployed

5 active (1 outdated) deployments
staging - packages/docs — 65639977 Deployed Sep 17, 2026 by mintlify[bot]
Preview – openwork-app — 65639977 Deployed Sep 17, 2026 by vercel[bot]
Preview – openwork-den — 65639977 Deployed Sep 17, 2026 by vercel[bot]
Preview – openwork-diagnostics — 65639977 Deployed Sep 17, 2026 by vercel[bot]
Preview – openwork-landing — e98236a5 Deployed Sep 17, 2026 by vercel[bot]
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.

2 participants