Retries resend a charge blind
A timed-out charge is sent again with nothing that lets Paydock see it is the same payment.
Impact: A tenant can pay $1,825 of rent twice.
All problemsData & Systems
Review an AI-written pull request that adds retries to a payments client and fix its blocking problems.
Your mission · AI code review
On November 1, Paydock timeouts and 503s left 2,300 rent payments unpaid until the next day, and landlords called support. A teammate asked an assistant for automatic retries, and the pull request is waiting for review. The December 1 rent run is in five days, and a client that charges a tenant twice would be worse than the outage.
A timed-out charge is sent again with nothing that lets Paydock see it is the same payment.
Impact: A tenant can pay $1,825 of rent twice.
A declined card or a missing charge is tried four times.
Impact: Paydock's risk team flags repeated declines as card testing.
The backoff doubles with no upper limit, and the copied loop sits in two methods.
Impact: Safe today, unbounded once someone raises the attempts.
Edit the components marked “Your work”. The other components show where your changes fit.
| Field | Type | Notes |
|---|---|---|
"ok" | string | Paydock answers normally. |
"timeout" | string | Paydock did the work and the response was lost. |
"drop" | string | The request never reached Paydock. |
"400", "402", "404" | string | Final errors. The same request gets the same answer again. |
"429", "500", "503" | string | Errors worth retrying. |
| Field | Type | Notes |
|---|---|---|
results | list | {payment, status: "paid", charge}, {payment, status: "failed" or "retry_later", error}, or {charge, status} for a lookup. |
requests | integer | Requests Paydock received. |
sleeps | list of ms | Every wait, in order. |
charges | list of [payment, amount] | Every charge Paydock made. Two for one payment is a double charge. |
review/PR-231.md The pull request description the assistant wrote. Its claims are what you are reviewing.# PR 231: automatic retries with exponential backoff for Paydock Author: AI coding assistant, opened for Marcus (Payments) Reviewers: you (required) ## Summary - Wraps every Paydock call in a retry loop: up to 4 attempts. - Exponential backoff between attempts: 200 ms, 400 ms, 800 ms. - Retries all Paydock errors and network errors, so transient failures never reach the tenant. - Adds MAX_ATTEMPTS, BASE_DELAY_MS and MAX_DELAY_MS to the settings. ## Why On November 1, 2,300 payments failed on timeouts and 503s. With these retries, the replay of that morning's errors charges every one of them on the same day. ## Changes See review/PR-231.diff: rentpay/adapters/client.py, and the new rentpay/services/retries.py and rentpay/config/settings.py. ## Test plan - [x] 503 then success: charged after one retry - [x] Four 503s: payment left for the next run - [x] Waits are 200, 400, 800 ms
review/PR-231.diff The change under review, as git shows it: PaydockClient in rentpay/adapters/client.py and the new rentpay/services/retries.py and rentpay/config/settings.py.diff --git a/rentpay/adapters/client.py b/rentpay/adapters/client.py
index 8eb42c3..9092e18 100644
--- a/rentpay/adapters/client.py
+++ b/rentpay/adapters/client.py
@@ -1,3 +1,8 @@
+from rentpay.config.settings import MAX_ATTEMPTS
+from rentpay.domain.errors import PaydockError
+from rentpay.services.retries import backoff
+
+
class PaydockClient:
"""The calls Hollis Rent makes to Paydock."""
@@ -7,8 +12,24 @@ class PaydockClient:
def charge(self, payment, amount):
"""Charge the tenant's saved card for one rent payment. Returns the Paydock charge."""
- return self.transport.send("POST", "/charges", {"payment": payment, "amount": amount})
+ attempt = 0
+ while True:
+ try:
+ return self.transport.send("POST", "/charges", {"payment": payment, "amount": amount})
+ except (PaydockError, TimeoutError, ConnectionError):
+ attempt += 1
+ if attempt >= MAX_ATTEMPTS:
+ raise
+ self.clock.sleep(backoff(attempt))
def get_charge(self, charge_id):
"""Look up a charge by its id."""
- return self.transport.send("GET", "/charges/" + charge_id)
+ attempt = 0
+ while True:
+ try:
+ return self.transport.send("GET", "/charges/" + charge_id)
+ except (PaydockError, TimeoutError, ConnectionError):
+ attempt += 1
+ if attempt >= MAX_ATTEMPTS:
+ raise
+ self.clock.sleep(backoff(attempt))
diff --git a/rentpay/services/retries.py b/rentpay/services/retries.py
new file mode 100644
index 0000000..2ab7f38
--- /dev/null
+++ b/rentpay/services/retries.py
@@ -0,0 +1,6 @@
+from rentpay.config.settings import BASE_DELAY_MS
+
+
+def backoff(attempt):
+ """Exponential backoff: 200 ms before the first retry, then 400, then 800."""
+ return BASE_DELAY_MS * 2 ** (attempt - 1)
diff --git a/rentpay/config/settings.py b/rentpay/config/settings.py
new file mode 100644
index 0000000..69931b9
--- /dev/null
+++ b/rentpay/config/settings.py
@@ -0,0 +1,7 @@
+MAX_ATTEMPTS = 4
+
+
+BASE_DELAY_MS = 200
+
+
+MAX_DELAY_MS = 2000samples/first-of-month.json Four rent payments and a lookup through a lost response, a declined card and a short outage. Arguments for Preview.[
[
"ok",
"timeout",
"ok",
"402",
"503",
"503"
],
[
{
"op": "charge",
"payment": "pay-4410",
"amount": 182500
},
{
"op": "charge",
"payment": "pay-4411",
"amount": 214000
},
{
"op": "charge",
"payment": "pay-4412",
"amount": 139500
},
{
"op": "charge",
"payment": "pay-4413",
"amount": 167500
},
{
"op": "get",
"charge": "ch_2"
}
]
]samples/first-of-month-expected.json What the retry policy says that sample returns. The pull request as it is makes two charges for pay-4411.{
"results": [
{"payment": "pay-4410", "status": "paid", "charge": "ch_1"},
{"payment": "pay-4411", "status": "paid", "charge": "ch_2"},
{"payment": "pay-4412", "status": "failed", "error": "card_declined"},
{"payment": "pay-4413", "status": "paid", "charge": "ch_3"},
{"charge": "ch_2", "status": "succeeded"}
],
"requests": 8,
"sleeps": [200, 200, 400],
"charges": [["pay-4410", 182500], ["pay-4411", 214000], ["pay-4413", 167500]]
}logs/paydock-2026-11-01.log Lines from the November 1 run: a timeout after which Paydock reported the charge as made, a 503, and a declined card.2026-11-01T06:12:04-05:00 rentrun charge payment=pay-38817 amount=182500 attempt=1 2026-11-01T06:12:14-05:00 rentrun charge payment=pay-38817 error=timeout after_ms=10000 2026-11-01T06:12:14-05:00 rentrun payment=pay-38817 status=retry_later 2026-11-01T06:12:15-05:00 paydock webhook charge.succeeded id=ch_8Hq2 payment=pay-38817 amount=182500 2026-11-01T06:31:40-05:00 rentrun charge payment=pay-40112 amount=139500 attempt=1 2026-11-01T06:31:40-05:00 rentrun charge payment=pay-40112 error=503 unavailable 2026-11-01T06:31:40-05:00 rentrun payment=pay-40112 status=retry_later 2026-11-01T06:52:09-05:00 rentrun charge payment=pay-40871 error=402 card_declined 2026-11-01T06:52:09-05:00 rentrun payment=pay-40871 status=failed
metrics/rent-run-2026-11.csv The last three rent runs: payments, results, and the errors behind them.run,payments,paid,failed,retry_later,timeouts,errors_503,errors_429,declined 2026-09-01,40388,38972,1117,299,131,104,12,1117 2026-10-01,40801,39340,1149,312,140,119,9,1149 2026-11-01,41210,37742,1168,2300,612,1544,144,1168
TASK-201 Read the retry policy and the Paydock docs, then PR 231 line by line, and rank your findings Reported by Priya (payments lead)
Expected A ranked list of findings in NOTES.md, each with a severity and an outcome script that shows it.
Actual The PR's test plan covers 503s only. Nobody has checked it against the policy.
TASK-202 Fix the blocking findings in the client and the retry module Reported by Marco (QA)
Expected Three charges, eight requests, waits of 200, 200 and 400 ms, and pay-4411 charged once as ch_2.
Actual Four charges: pay-4411 is charged twice. Eleven requests, and the declined card for pay-4412 is tried four times.
TASK-203 Write what the author should change before merging Reported by Priya (payments lead)
Expected Every finding has a severity, the script, what the tenant or Paydock sees and the fix, and the things that look wrong but are fine are listed.
Actual NOTES.md has the empty template.
Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard
A teammate used an assistant to add automatic retries to our Paydock client, and wants it merged before the next rent run. Review the pull request. Rank your findings by severity in NOTES.md, then fix the ones that should block the merge. Use the AI assistant however you like, but the review is yours. Before you change any code, tell me your most severe finding and the outcome script that shows it.