fix: disable outer retry for x402 payment providers to prevent duplicate charges

The outer retry loop in client.go re-initiates the entire x402 payment
flow on each attempt, causing duplicate USDC charges. The inner x402
retry loop (5 attempts with re-signing) already handles all retryable
scenarios. Set MaxRetries=1 for Claw402, BlockRunBase, and BlockRunSol
to ensure only one payment per AI decision.
This commit is contained in:
tinkle-community
2026-03-12 14:29:42 +08:00
parent b5061d1b8f
commit 2314ece9d1
3 changed files with 3 additions and 0 deletions
+1
View File
@@ -73,6 +73,7 @@ func NewBlockRunBaseClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
mcp.WithModel(DefaultBlockRunModel),
mcp.WithBaseURL(DefaultBlockRunBaseURL),
mcp.WithTimeout(X402Timeout),
mcp.WithMaxRetries(1), // disable outer retry — inner x402 loop handles retries; outer retry causes duplicate payments
}
allOpts := append(baseOpts, opts...)
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)
+1
View File
@@ -53,6 +53,7 @@ func NewBlockRunSolClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
mcp.WithModel(DefaultBlockRunModel),
mcp.WithBaseURL(DefaultBlockRunSolURL),
mcp.WithTimeout(X402Timeout),
mcp.WithMaxRetries(1), // disable outer retry — inner x402 loop handles retries; outer retry causes duplicate payments
}
allOpts := append(baseOpts, opts...)
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)
+1
View File
@@ -70,6 +70,7 @@ func NewClaw402ClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
mcp.WithModel(DefaultClaw402Model),
mcp.WithBaseURL(DefaultClaw402URL),
mcp.WithTimeout(X402Timeout),
mcp.WithMaxRetries(1), // disable outer retry — inner x402 loop handles retries; outer retry causes duplicate payments
}
allOpts := append(baseOpts, opts...)
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)