codebaobab
Python workspace

All problemsData & Systems

Payment Retry Review

Review an AI-written pull request that adds retries to a payments client and fix its blocking problems.

Python45 minutesData & Systems

Challenge brief

Read before you begin

Your mission · AI code review

Review an AI-written pull request that adds retries to a payments client, and fix what blocks it.

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.

  • Mode · code review
  • Review · NOTES.md
Skip to round setup

Your assignment

  1. Read the retry policy, the Paydock docs and PR 231.
  2. Rank your findings in NOTES.md, with a script each.
  3. Fix the blocking findings, one at a time.
  4. Handle the new requirement when it arrives.
  5. Tell the author what to change before merging.

The problem

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.

Every error is retried

A declined card or a missing charge is tried four times.

Impact: Paydock's risk team flags repeated declines as card testing.

The backoff ignores the cap

The backoff doubles with no upper limit, and the copied loop sits in two methods.

Impact: Safe today, unbounded once someone raises the attempts.

Context

Payments missed Nov 1
2,300
Timeouts after the charge
1 in 300
Next rent run
Dec 1

Requirements

  • One charge per payment, through any retry.
  • Idempotency-Key is the payment id.
  • Retry timeouts, drops, 429 and 5xx only.
  • Never retry another 4xx.
  • At most 4 attempts: 200, 400, 800 ms.
  • No wait over 2000 ms.
  • Keep replay and the fake Paydock as they are.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

Rent runMonthly charge job
Paydock client(Your work)Sends charges with retries
Retry policyThe rules for retries
PaydockPayment provider
Rent ledgerPayment states
Tenant noticesTells tenants
Read the connections
  • Rent run → Paydock client: charge
  • Retry policy → Paydock client: review against
  • Paydock client → Paydock: POST /charges
  • Rent run → Rent ledger: result
  • Rent ledger → Tenant notices: failed, paid
  • Rent run: Charges every tenant on the first of the month, one payment at a time.
  • Paydock client: PaydockClient in rentpay/adapters/client.py and the retries in rentpay/services/retries.py.
  • Retry policy: docs/retry-policy.md: what to retry, how often, and the key on charges.
  • Paydock: Card and bank payments. Keeps idempotency keys 24 hours.
  • Rent ledger: Each payment's state: paid, failed or retry_later.
  • Tenant notices: Email and SMS for declined cards and receipts.

Data model

Outcome script

FieldTypeNotes
"ok"stringPaydock answers normally.
"timeout"stringPaydock did the work and the response was lost.
"drop"stringThe request never reached Paydock.
"400", "402", "404"stringFinal errors. The same request gets the same answer again.
"429", "500", "503"stringErrors worth retrying.

replay result

FieldTypeNotes
resultslist{payment, status: "paid", charge}, {payment, status: "failed" or "retry_later", error}, or {charge, status} for a lookup.
requestsintegerRequests Paydock received.
sleepslist of msEvery wait, in order.
chargeslist of [payment, amount]Every charge Paydock made. Two for one payment is a double charge.

Details

Full requirements

Functional

  1. Never charge a payment twice. Every POST /charges carries Idempotency-Key set to the payment id, on every attempt, so a retry after a lost response, or the same payment in tomorrow's run, returns the charge Paydock already made.
  2. Retry only what may succeed next time: a timeout, a dropped connection, 429 and 500 or above. Any other 4xx is final: a declined card stays declined, and retrying it looks like card testing to Paydock.
  3. At most 4 attempts, waiting 200, 400 and 800 ms. No wait is ever longer than 2000 ms, whatever the attempts are set to.
  4. A read (GET /charges/{id}) is safe to repeat and needs no key.
  5. replay and the fake Paydock in rentpay/testing/fixtures.py are the test rig the checks use. The fix belongs in the client and the retry module.

Non-functional

  • Scale: about 41,000 charges on the first of the month, most between 6:00 and 9:00 Eastern.
  • Money: a double charge costs a refund, a support call and often the tenant's overdraft fee; one in 300 timeouts on 41,000 payments is about 137 tenants a month.
  • Time: the run must finish by 9:00. Four attempts with waits of 200, 400 and 800 ms add at most 1.4 seconds to a payment.
  • Paydock limits: 100 requests a second per account, and keys are kept 24 hours.

Out of scope

  • Bank (ACH) payments and refunds. They go through another client.
  • Running payments in parallel.
  • Telling tenants about a declined card. The rent run does that from the result.
  • Changing replay or the fake Paydock.
Files you are given · 6
  • 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 = 2000
  • samples/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
Tickets · 3
  • 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.

What you hand in
  • A client that passes every public check, including the new requirement when it arrives.
  • NOTES.md: your findings ranked by severity, each with a script and whether you fixed it, and what looks wrong but is fine.
  • Two or three sentences for the author on what must change before the December 1 run.
How the work is judged
Breaking down the work
Reviews the diff against each row of the policy before changing code, and separates blocking findings from should-fix and nits.
Directing the assistant
Asks the assistant to trace a named outcome script, such as one lost response, not "is this pull request correct?".
Checking the work
Shows each finding with a script in Preview, then reruns every check after each fix, including the mixed rent run.
Judging the assistant
Ranks the double charge first and the 4xx retries second, calls the missing cap a should-fix, and keeps the GET retry, the 429 retry and the missing jitter off the blocking list.
Correct result
All checks pass: one charge per payment through any number of lost responses, no retry of a final 4xx, and the follow-up Retry-After rules.
Explaining the work
NOTES.md tells the author plainly what a tenant would see, with the script that proves it and the fix.
Trade-offs to discuss
  • Blocking the merge versus merging the fixed retries now and adding the cap and the cleanup in the next PR.
  • Using the payment id as the key versus a key per run, when a tenant changes the amount between runs.
  • Retrying a timeout on the same day versus leaving the payment for tomorrow.
  • Four attempts per payment versus fewer, in a run that must end by 9:00.
How you are graded
  • Decomposition 5%
  • Prompting the assistant 5%
  • Verification 20%
  • Judgment about AI output 30%
  • Correctness 15%
  • Communication 25%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

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.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 7 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • What was your most severe finding, and what script convinced you it was real?
  • Name one thing the assistant flagged that you decided was not a problem. How did you check?
  • The missing cap breaks no check today. How did you decide its severity, and what would you tell the author?