Repository navigation
fix(preauth): don't reuse a pre-auth that overpays this request - #514
Conversation
exact settles the whole signed amount, so reusing a pre-auth bought for a bigger request charged the user the bigger price (prod 2026-10-21..24: a $0.001 call paid $0.0098). The gateway now refuses an exact payment signed more than 3% above the price (blockrun#874, PAYMENT_OVERSIGNED), so reusing one only wastes a round trip. Reuse a cached pre-auth only when it covers the request and exceeds its estimate by at most 3%.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Apply and verify the reuse limit src/payment-preauth.ts, src/payment-preauth.test.ts |
The reuse check skips cached payments when the amount exceeds the request estimate by more than 3%. Tests cover skipped reuse after a large estimate decrease and reuse at the 3% limit. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
- BlockRunAI/ClawRouter issue 511: The change prevents cached pre-authorization reuse when it can overcharge a smaller request, aligning with the issue’s focus on quote-versus-settled price accuracy.
Suggested reviewers: killerqueen-z
Merge Risk: 
Minimal · up to b230a
-
No actionable issue remains on the supplied evidence; the change appears mergeable after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "fix(preauth): don't reuse a pre-auth that overpays this request" matches the main change. The diff limits cached pre-auth reuse to cases where the cached amount covers the estimate and exceeds it by no more than 3%. The tests cover the shrunk-request fallback and the 3% reuse band. The title is specific and uses the conventional fix(scope) format.
-
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
Problem
payment-preauth.tsreused a cached pre-auth wheneverneed <= cover. exact settles the whole signed amount, so a smaller request reusing a pre-auth from a bigger one paid the bigger price. In prod 2026-10-21..24 this showed up as 259 over-signed settlements; one $0.001glm-5.3-flashcall paid $0.009782.The gateway now refuses an exact payment signed more than 3% above the price (BlockRunAI/blockrun#874, live as
blockrun-web-01201-tn6, codePAYMENT_OVERSIGNED). This client already handles that 402 by re-fetching a fresh challenge, so the user is no longer overcharged. Each such reuse is still a wasted round trip, though.Fix
Reuse only when
need <= cover <= need × 1.03, the gateway's band.Tests
payment-preauth.test.ts: a shrunk request skips pre-auth (clean unpaid request, then paid retry); reuse within 3% above still happens.tsc, eslint and the suite pass, excepttest/upstream-proxy.test.ts, which fails to load (undicibindof undefined) identically onmainin this environment.🤖 Generated with Claude Code
Summary by CodeRabbit