An agent prepares a refund and an operator approves it. Before it is sent, the order is edited. A generic “approved” flag cannot tell the executor whether the reviewer saw the amount that is about to leave the system.
For selected high-impact operations, use separate, authenticated requester and approver roles. Write down what counts as independent in your deployment. Two clicks by the same account do not satisfy a two-person rule. A harmless read may still reveal private data and needs ordinary authorization even when it requires no second approver.
Bind approval to one intent
Create a unique operation ID. Bind the approval to that ID, the operation type, account or tenant, target, exact parameters, environment, resource version and expiry. A reviewer should see the units and currency explicitly. If a dry run is available, label the inputs and state version it used. Its output is an estimate of the future effect until execution checks those preconditions again.
At execution time, validate the approval and current authority on the server. Atomically claim the unexpired, unused approval for that exact operation. A separate “already used?” read followed by a later update leaves room for competing workers. If any bound field differs, request a new review. Avoid using language-level debugging assertions for access control.
An approval controls whether the request may be sent. It cannot establish what happened after dispatch. Persist the intent before sending, use a provider-supported idempotency key when available, and retain a definitive receipt. If dispatch may have occurred and the response was lost, reconcile by operation ID before another attempt. A fresh approval alone does not resolve that uncertainty.
A tabletop check can use a fictional refund of 12 units, then change just the amount to 21, switch tenants, expire the grant, or have two workers claim the same approval. Each case should have a clear expected outcome before connecting to any payment system. The useful audit trail shows what the reviewer approved, what the executor claimed and what the receiver confirmed.
Test approval matching at the executor
Use a fake receiver with an observable count and a one-use approval for a 12-unit refund. In separate fresh fixtures change the approved amount, tenant or expiry and expect zero calls. With the valid fixture, let two workers race for the same approval. Exactly one worker should acquire the claim; the other should leave the remote call count unchanged. Verify the recipient, amount and operation ID of the accepted call.
This article was created with AI assistance.
Top comments (0)