F25: Hard budget enforcement — reject events when budget exceeded#3
Merged
Conversation
- Add BudgetExceededInfo type and onBudgetExceeded callback to ClientConfig - Add budgetBackoffMs config option (default 5 min) - Circuit breaker: on 429 + X-Budget-Exceeded, silently drop events for backoff period, then probe with one request - BudgetExceededError skips retry loop (Sentinel amendment #1) - Single warning log + callback when entering budget-exceeded mode - Fire-and-forget contract preserved Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Code Review — SentinelVerdict: REQUEST CHANGES — missing test fileBlocking IssueMissing circuit breaker tests (High)
No test file was included. The circuit breaker is a state machine with 3 states — this must be tested. Code Quality — PASSED ✓
Security — PASSED ✓No concerns. Client-side library. Action Required
|
4 test scenarios: - Enters circuit breaker on 429 + X-Budget-Exceeded, drops subsequent events - Fires onBudgetExceeded callback exactly once - Retries probe after backoff expires - Does not enter circuit breaker on regular 429 (no header) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Sentinel Re-review: APPROVED ✅SDK changes verified: BudgetExceededError skips retries, circuit breaker state machine correct, onBudgetExceeded fires once, 4 tests pass. Ready to merge. |
Contributor
Author
Sentinel — Merge ApprovedB18 resolved. App PR #72 deployed successfully. SDK PR #3 unblocked. Code review was approved in previous session. Circuit breaker, BudgetExceededError, onBudgetExceeded callback all verified. |
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.
Summary
enforceLimitboolean toWorkspaceBudgetmodel (default false)enforceLimit=trueand monthly spend >= budget,POST /api/ingestandPOST /api/ingest/otlpreturn 429 withX-Budget-Exceeded: trueheaderenforceLimitin POST bodyTask
Task file:
aispendguard-tasks/active/features/F25-hard-budget-enforcement.mdChanges
prisma/schema.prismaenforceLimit Boolean @default(false)to WorkspaceBudgetlib/billing/budget.tscheckBudgetEnforcement(), update BudgetConfig typeapp/api/ingest/route.tsapp/api/ingest/otlp/route.tsapp/api/budgets/route.tsenforceLimitboolean in POSTapp/(app)/billing/budget-panel.tsxapp/(app)/dashboard/page.tsxapp/components/budget-enforcement-banner.tsxTesting
npx tsc --noEmitpassesDocumentation
SDK docs and architecture docs to be updated as part of docs sync.