Repository navigation
Refactor AI-credit guard into focused modules - #11949
Merged
Merged
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
lpcox
marked this pull request as ready for review
November 22, 2026 17:23
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Verifying shared-state wiring, hard-cap precedence, and fail-closed behavior across the extracted modules requires deeper review because errors could bypass spending limits.
No open issues 🎉
What changed in this PR
Refactors the API proxy’s AI-credit budget guard into focused modules, addressing #11942 while retaining the existing public interface and enforcement logic.
Changes:
- Separates configuration, pricing, accounting, and steering into four modules.
- Keeps mutable state and the configuration cache in the facade, with live state access across resets.
- Adds characterization tests for shared totals, reset isolation, configuration refreshes, warning deduplication, and public exports.
| File | Description |
|---|---|
containers/api-proxy/guards/ai-credits/steering.js |
Extracts budget warnings, reflection, and limit handling. |
containers/api-proxy/guards/ai-credits/pricing.js |
Extracts pricing resolution, fallbacks, and pricing warnings. |
containers/api-proxy/guards/ai-credits/config.js |
Extracts configuration parsing and hard-cap handling. |
containers/api-proxy/guards/ai-credits/accounting.js |
Extracts exact credit calculations and usage accumulation. |
containers/api-proxy/guards/ai-credits-guard.js |
Becomes the facade and retains shared state ownership. |
containers/api-proxy/guards/ai-credits-facade.test.js |
Adds coverage for facade compatibility and shared-state behavior. |
Review effort: Max (adaptive)
Contributor
|
✅ Copilot review passed with no inline comments. @lpcox Add the |
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.
The 840-line AI-credit guard mixes configuration, pricing, accounting, and steering on the budget-enforcement boundary. This refactor separates those concerns without changing callers or enforcement behavior.