Standard library only · runs in your browser
The refund endpoint passes every test the agent wrote. In production, the mobile app retries any request that takes longer than two seconds, and on a slow day finance finds orders refunded twice. Every individual call was handled correctly.
Every refund request carries an idempotency_key, generated once by the client and reused on every retry of that same request.
Fix handle(store, request) so that:
order_id and amount → return exactly the response the first call got, and change nothing. That includes error responses.{"status": "error", "code": "idempotency_key_reused"}, and don't remember it.unknown_order; amount ≤ 0 → invalid_amount; already-refunded plus this amount over the order total → exceeds_order_total. Otherwise refund, and return {"status": "ok", "refund_id": "rf-<n>"}, where n counts up from 1001.process_requests(orders, requests) (provided) replays a list of requests, retries included, and returns every response plus the total refunded per order.
handle(store: dict, request: dict) -> dict (process_requests is provided)