Repository navigation
Conversation
The per-call USD cap still let a model repeat a purchase with a fresh idempotency_nonce, region or profile and spend again. Real purchases now also need CUDLY_MCP_BUDGET_USD, a ceiling on the total USD this server process commits. An unset or invalid value refuses before credentials are resolved. After the USD cap prices a purchase, its total is reserved against the budget under a mutex, so concurrent calls cannot both pass. Once PurchaseCommitment has been invoked the reservation stays counted on every error and every non-no-op result; only a clean no-op or a commitment the library adopted is released. The budget lives in memory: it resets on restart, is not shared between processes and cannot see purchases made elsewhere, which the README states. Refs #51 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Member
Author
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
This is part 3 of 3 for #51. It is stacked on #69. Merge #69 first, then retarget this PR to main.
The per-call USD cap (#69) still let a model repeat a purchase with a fresh
idempotency_nonce, region or profile and spend again. Real purchases now also requireCUDLY_MCP_BUDGET_USD, a ceiling on the total USD this server process commits.authorizeRealPurchasereads the budget, and an unset or invalid value refuses beforeResolveClient. It now returnspurchaseLimits{usd, budget}.enforceUSDCapprices the purchase, its total is reserved against the budget under a mutex, so concurrent calls cannot both pass. One stderr line is logged per reservation.purchaseAndSettlemakes thePurchaseCommitmentcall, logs, audits and settles. Once the purchase is invoked, the reservation stays counted on every error, including an unknown outcome, and on every non-no-op result. Only a clean no-op, or a commitment the library adopted (ExistingCommitment), releases it. Refusals before the purchase call never count.mcpb/manifest.json: env var in all 3 platform blocks, plus abudget_usduser setting.server.jsonBreaking/Addedentries.Closes #51. With #66, #69 and this PR, scope items 1 and 2 are implemented. Item 3 (priced RI/CUD preview) was an optional owner decision and is not done. GCP re-enable is #67, auditing refusals is #68 and a persisted budget is #74.
Verification (local, macOS)
Fake-cloud and unit evidence only. No real purchase or cloud call is made. The full suite ran at 909549f; after the rebase onto #69 at 928c95c (range-diff identical), build, vet and
go test -racewere re-run at 241f692 and pass.gofmt,go vet ./...andmake buildpass.go test -race -count=1 ./...passes in all 3 packages. golangci-lint and gosec, both run withGOTOOLCHAIN=go1.26.9, report 0 issues.gocyclo -over 10lists no non-test code. markdownlint passes and both JSON files parse.TestBudgetRepeatCallWithFreshNonceRefusedmakes two identical $60 purchases with different nonces under a $100 budget. With the reserve call disabled both execute and the test fails. With it, the second is refused and no purchase call is made for it.-race(exactly 3 of 10 reservations succeed)>changed to>=in reserveExistingCommitmentreleaseReview
An independent reviewer (Sonnet, high effort, non-author) did two passes. It walked every
(err, Success, Error, ExistingCommitment)combination and every path between reserve and settle; there are no leaks and no double settle. It also checked the singleton against parallel tests and found no race.Pass 1 found:
>=mutation survived: added, and now caught.Pass 2 found no actionable findings. CodeRabbit is not pinged because the org's CR quota is exhausted.
🤖 Generated with Claude Code