Agent Session Viewer ● live
6 platforms · 38 sessions
a3f812c0 ~/Code/checkout-service ⎇ feat/payment-retry ● Live 203 messages
✓ Add RetryPolicy interface with jitter support
◆ Wire exponential backoff into PaymentClient.charge()
○ Write integration tests against Stripe test clock
add exponential backoff with jitter to the payment charge call — cap at 4 retries, 30s max delay. use the existing RetryPolicy interface.
Thinking · Check RetryPolicy signature and where PaymentClient.charge is called…
📄 Read PaymentClient.ts src/clients/ ▸
📄 Read retry.ts src/utils/ ▸
✏️ Edit PaymentClient.ts src/clients/ ▾
-  async charge(params: ChargeParams): Promise<ChargeResult> {
-    return this.stripe.paymentIntents.create(params)
-  }
+  async charge(params: ChargeParams): Promise<ChargeResult> {
+    return withRetry(() => this.stripe.paymentIntents.create(params), {
+      maxAttempts: 4, baseDelayMs: 500, maxDelayMs: 30_000, jitter: true,
+    })
+  }
›_ Bash npx tsc --noEmit verify no type errors ▾
Done in 1.4s

Wired withRetry into PaymentClient.charge() — full jitter caps delay at 30 s after 4 attempts. Types pass. Next: integration tests against the Stripe test clock.

write a unit test that verifies the 4-attempt cap and that delays grow exponentially.
✍️ Write PaymentClient.retry.test.ts src/clients/__tests__/ ▸
›_ Bash npx vitest run src/clients/__tests__/PaymentClient.retry.test.ts ▾
 ✓ caps retries at 4 attempts (12ms)
 ✓ delay grows exponentially with jitter bound (8ms)
 ✓ succeeds on first attempt when no error (3ms)

Test Files  1 passed (1)
Tests       3 passed (3)

All 3 tests pass. The exponential growth assertion uses vi.useFakeTimers() to confirm each delay is ≥ 2× the previous before jitter.