fix(cloud): refund MCP proxy upfront debit on every post-debit failure, not just non-ok HTTP (#11637) - #11652
Conversation
…ilure, not just non-ok HTTP (#11637) mcp/proxy/[mcpId] debits the caller upfront (reserveAndDeductCredits) but only refunded when the upstream returned a non-ok HTTP status. Every other post-debit failure kept the money = a silent over-charge: - unsafe/blocked external endpoint → 400 - container has no load balancer → 503 - endpoint misconfigured → 500 - upstream unreachable/DNS/refused → 502 Add a `refundPrecharge(reason, status?)` helper right after the debit and call it on all four early-return failure branches; the non-ok HTTP branch now routes through the same helper. Refund amount = the exact upfront debit. Test (__tests__/mcp-proxy-refund.test.ts): drives the real route with mocked deps and asserts refundCredits fires on unreachable(502)/unsafe(400)/ container(503)/non-ok, and NOT on success. Red-before/green-after proven by stashing the route: the three new failure-path cases fail (refund never called) without the fix. typecheck + biome clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
Reviewed #11652 against #11637 and pushed one follow-up in Finding fixed:
Fresh verification in Manual route review after the follow-up: every post-debit branch before upstream delivery now calls |
lalalune
left a comment
There was a problem hiding this comment.
Approved after review and follow-up f8f3c63fa9. The remaining post-debit invalid-JSON branch now refunds, and the route-level suite covers all failure branches plus success/no-refund.
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Closes #11637.
[cloud-money]Bug (MED, money — user over-charged)
mcp/proxy/[mcpId]/route.tsdebits the caller upfront (reserveAndDeductCredits) but only refunded on a non-ok HTTP status. Every other post-debit failure kept the money → a live external MCP that's momentarily down silently over-charges the org:Fix
A
refundPrecharge(reason, status?)helper right after the debit, called on all four early-return failure branches; the non-ok HTTP branch now routes through the same helper. Refund = the exact upfront debit amount.Proof (red-before / green-after)
New
__tests__/mcp-proxy-refund.test.tsdrives the real route with mocked deps:bun test __tests__/mcp-proxy-refund.test.ts→ 5/5 green (refund fires on 502/400/503/non-ok; NOT on success).Money path — do not self-merge.