Repository navigation
feat(cost): daily ceiling on paid AI-engine calls - #165
Merged
Merged
Conversation
AEO_DAILY_AI_CALL_CAP (default 2000 per UTC day). /start reserves an audit's worst case (41) before the audit row exists; custom prompts reserve 4 per question after their own limits. Reserve-then-count in the shared limiter table; fails closed with a plain message (AI_DAILY_LIMIT). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…utral retry message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
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.
What
A daily ceiling on paid AI-engine calls from all visitors together, on top of the per-visitor and per-audit limits.
src/lib/aiBudget.ts:AEO_DAILY_AI_CALL_CAPcalls per UTC day, default 2000 (about 48 full audits); an unusable value means the default./api/audit/startreserves an audit's worst case, 41 calls (one to write the questions, then 4 engines × 10), after validation and before the audit row exists. Custom questions reserve 4 per question after their own limits and after the stored-results shortcut.ai-calls:<n>), so it grows by reservations, not calls. Each row counts for at most 41.AI_DAILY_LIMITin the logs).Pipeline: /tdd (aiBudget.test new module red first; start and custom-prompts reservation and refusal cases 4 red; one-row, staff, row-size-cap cases red before their fixes) → code-reviewer subagent → /security-review
Risk tier: high (cost control on public routes)
Risk
AEO_DAILY_AI_CALL_CAP, or revert.(ip, created_at)index is in draft 007, not confirmed live. Without it the count is a table scan; a failed count refuses (fails closed).Code review: the code-reviewer subagent confirmed the 41 figure and the check order (invalid, paused, gated and rate-limited requests reserve nothing). It raised row growth (fixed: one row per reservation), staff being refused and a wrong "tomorrow" (fixed: staff counted not refused; message says "later"). Index presence and the retry double-spend are listed under Risk.
Security review: no findings at confidence ≥ 8. A forged limiter key could only add one row of at most 41 calls.
Checks:
npx vitest run265/265 in 25 files;npx tsc --noEmitclean; eslint on changed files 0 errors.🤖 Generated with Claude Code