A revenue-recovery agent that out-earns naive retry on every
surface it works, and breaks zero rules doing it — because every action it takes is
ruled on by code, not by a prompt.
Retry budgets, decline-code rules, contact caps, quiet hours, value
thresholds and stopping rules are code, not prompts. Every action an LLM
proposes is ruled on before it can execute, and a vetoed action is logged with
the rule that fired.
That turns “zero policy violations” from an assertion into a statement about a
record. It also survives the thing most agent demos quietly depend on — the model
being good. Backstop’s guarantee does not.
Every arm faces identical orders and identical latent recoverability,
fixed before any of them ran. The policy engine evaluates every action in every
arm — the only difference is whether its rulings are obeyed, which is what makes
the violation counts comparable rather than self-reported.
₹1,70,30,028 per year was at risk across 1,331 lapsed authorisations.
A restored mandate is credited a year of billing, not one charge.
arm
recovered
of which illegal
keepable net
mandates
contacts
violations
do-nothing
₹0
–
₹0
0
0
0
naive-retry
₹44,05,644
₹1,85,796
₹42,13,859
363
3,993
1,899
planner-unpoliced
₹42,19,848
₹49,140
₹41,68,470
346
1,492
20
backstop
₹41,81,472
–
₹41,79,263
344
1,473
0
Receivables
invoices that were never paid
₹4,01,69,841 outstanding across 377 overdue invoices — of which
only ₹69,06,052 was ever incrementally collectable. The rest arrives on the buyer’s
own cycle, or never arrives.
arm
recovered
of which illegal
keepable net
invoices
contacts
violations
do-nothing
₹0
–
₹0
0
0
0
naive-retry
₹44,40,758
₹82,497
₹43,56,565
51
1,131
678
planner-unpoliced
₹47,27,686
₹36,612
₹46,90,405
57
446
18
backstop
₹46,91,074
–
₹46,90,432
55
428
0
Two things the columns are doing.
“Of which illegal” is revenue taken by actions the rules refuse — a merchant cannot
keep it, so crediting it would score the baseline for exactly the behaviour the
policy engine exists to stop. And the three surfaces are tabled apart and never
added: a recovered payment is one amount that landed, a re-registered mandate is a
year of billing restored, a collected invoice is a balance already owed. Summing
them would produce a headline nobody could reconcile.
naive recovered₹49,16,423
−
cannot keep₹49,821
−
51,015 charges + 17,005 contacts₹45,913
=
keepable net₹48,20,689
Five things worth reading off those tables
It beats the realistic alternative, not a strawman
Backstop keeps ₹9.5L more than naive retry on payments while making 68% fewer
charge attempts. Naive breaks 27,889 rules across the three surfaces getting
its number — including 600 retries of cards reported stolen, 2,667 attempts to
chase customers who explicitly revoked their mandate, 93 chases of invoices the
buyer is actively disputing, and 84 sent to buyers who had already committed to
a payment date.
−68%charge attempts
27,889rules naive breaks
0rules Backstop breaks
Nobody hears from Backstop more than six times a fortnight
Not per order, not per invoice, not per mandate — per person, across all three
surfaces at once. Over six seeds the policed arm’s worst 14-day burst against
any one human being is exactly 6, with nobody above it, where naive reaches 15
to 18. A customer with a failed order, a lapsed mandate and two overdue invoices
is one person, and every per-subject cap can be scrupulously observed while they
are written to a dozen times.
6worst burst, policed
15–18worst burst, naive
The leash is free on all three surfaces, and it did not used to be
The policed and unpoliced arms run identical proposed actions, so the gap
between them is the cost of compliance alone — and it now runs in policing’s
favour on every surface: ₹10,792 on recurring, ₹214 on payments, ₹27 on
receivables. The unpoliced arm takes money it cannot keep and spends more
doing it. Payments used to be the exception, at an apparent cost of ₹1,795,
and that was an artefact of the reschedule bug below rather than a price of
compliance.
It holds when the model gets worse
The tables above are the weak model. gpt-oss-20b proposes
visibly worse actions — 40 re-presentations of mandates whose diagnosis had
already established that re-presenting cannot work, 12 re-asks of customers who
revoked their authorisation, 16 messages to people who opted out — and the
engine refuses every one. 210 rule breaks in the unpoliced arm, 0 in the
policed one. That is the whole argument: safety that does not depend on model
quality.
It holds when the model is gone
The Groq quota was exhausted mid-run and every cluster returned a 429. Recovery
degraded to the deterministic playbook rather than stopping: still 35,158 actions
proposed, still ₹58,30,774 recovered on payments, still zero rules broken. Worth
saying plainly — the fallback out-recovered the weak model by about ₹31,000. On
failures with no incident to reason about, a lookup table beats a small model.
The model earns its place on diagnosis and cluster strategy, and nowhere else.
The counterfactual is the hard part
Most overdue invoices are paid whether or not anybody chases them. An
accounts-payable department runs on a cycle; an invoice twelve days late is usually
not a collections problem, it is a Tuesday.
Of the ₹4.02 crore outstanding, ₹1.92 crore arrives on the buyer’s own cycle
with no action at all and is credited to nobody. Only ₹69,06,052 is
incremental — the ceiling on what any collections effort could add. A tool that
dunned the whole aged debtors report and booked everything that subsequently arrived
would show a spectacular recovery rate having caused almost none of it.
The same discipline runs through the other two surfaces. A third of paused mandates
resume with no prompting, so an agent that mails those customers and books the
resumption has measured its own postage — ground truth marks them non-incremental and
they are credited nothing however well the contact is timed. And the ninety-day
receivables bracket, where settlement and write-off decisions live, is handed to a
person and books nothing at all. Across six seeds that bracket is worth
₹83,267–₹5,16,803 to the naive arm. It is the single largest thing policing costs,
and on one seed in six it is enough for naive to come out ahead.
₹4.02croutstanding
₹1.92crarrives anyway — credited to nobody
₹69,06,052genuinely incremental
It executes for real
Behind one protocol sit two backends: the simulator the measurement runs
on, and a Razorpay test-mode adapter that really dispatches. Orders for
re-presentments, payment links for dunning and part-payment offers, authorisation
links for lapsed mandates.
A dispatch is not a recovery, and the type system says so. A payment
link is paid when a human opens it, hours or days later and out of band — so a live
dispatch reports a fourth outcome, dispatched, and reconciles afterwards.
Which is precisely why the adapter cannot run the backtest: the four-arm comparison
needs a counterfactual, and reality does not offer one.
Two guardrails, written as refusals rather than options. Live keys are refused
outright — this code dispatches payment links at people, and there is no
override flag. Notifications are off unless asked for, because test
mode really delivers.
$ python -m backstop.demo --stage razorpay
payment retry_payment order_000100004cfc2
ruling ALLOW 16 rules consulted
scheduled 08-27 11:15 UTC, held until then
receivable send_dunning inv_000100004e5ea via email
ruling ALLOW 16 rules consulted
scheduled 08-31 12:00 UTC, held until then
430 candidates held for approval, and queued rather than dropped
Zero settled is the correct answer rather
than a disappointing one.
The gate has a queue behind it
Those 430 held actions used to go nowhere. The engine produced the
ruling, the ledger counted it, and the live run correctly refused to send — then
dropped it. A gate with nothing behind it is a deletion.
An approval is permission from a person, not an exemption from the rules.
A release re-runs all sixteen rules in the world that holds then, not the one
that held when the request was raised. Time passes while a request sits: a contact
budget fills, an hour becomes a quiet hour, a mandate gets revoked, an invoice goes
into dispute. A queue that dispatched whatever a reviewer approved on Tuesday would
be a hole in the policy engine exactly the width of the queue. So a denial still
denies after a yes, and the reviewer is told which rule overtook their decision.
What the yes discharges is the approval requirement itself — and nothing else, or
every approved action would be immortal in the queue.
Silence is not consent. Unanswered requests expire, and expiry is
recorded rather than dropped. That is what makes the backtest’s assumption — that a
merchant staffs the desk — falsifiable instead of merely convenient. A merchant who
does not staff it gets a pile of expired requests, not the revenue.
430held for a person
1answered, then re-ruled and dispatched
429expired — credited to nobody
Every decision names a human being; there is no auto-approve.
The backtest’s staffed desk is written down as a reviewer with a stated latency and a
staffing rate, deterministic per request, so an assumption is something a reader can
see and argue with. And a request’s identity is the same fingerprint the adapter uses
for idempotency — verb, subject, moment, channel, amount, and deliberately not the
model’s wording. Re-running a plan finds the request a reviewer has already seen, and
a model rewording its own justification cannot buy a second ask.
A reschedule that nobody honours is a log entry
Three of the sixteen rules exist mainly to move an action’s
moment: quiet hours pushes an SMS out of the night, retry spacing refuses to
re-present a card seconds after it declined, and an outage hold defers a charge
until the rail recovers.
The measurement honoured those times. The live path did not — it dispatched
immediately and threw the schedule away, which made RESCHEDULE
decorative in the one place it mattered. An engine that moves a 22:30 SMS to
09:00, followed by an adapter that sends it at 22:30, has not protected anybody.
It has produced a record saying it did.
Nothing fires before it is due. That is the guarantee, and it
is the reason there is no flush() and no force argument anywhere on
the scheduler: the method that skipped the wait would remove the only thing the
component promises.
The rules run again when it comes due, on the queue’s
reasoning — the world an action was judged in is not the world it lands in. That
is also what makes lateness safe rather than merely tolerated: an action arriving
at an awkward hour is pushed again then, instead of squeaking through on
yesterday’s verdict.
But it cannot be re-held forever. Something rescheduled again
and again is not being carefully timed, it is being chased by a blocker that is
not clearing — so after three deferrals it is abandoned and recorded. An
unbounded retry loop is the same failure as an unbounded contact loop.
And a missed window is not a licence to fire late: past a day,
an action is dropped as stale, because a retry timed for the hour after a failure
is a different act three days later, and a reminder can arrive after the invoice
was paid.
the clock advances — 4 scheduled moments, stepped rather than slept throughfired 08-27 11:15 retry_payment order_000100004cfc2
created order order_TWCsS24apsObn5
fired 08-31 12:00 send_dunning inv_000100004e5ea
created payment_link plink_TWCsU2fE3tQfnr
fired 09-01 00:00 request_mandate_reregistration sub_0001000048737
fired 09-03 00:00 request_mandate_reregistration sub_000100004879a
The walkthrough steps the clock to
each moment rather than sleeping between them, and says so — the same loop with
the waiting taken out. It starts from the earliest scheduled moment rather than
from now, because the batch is historical: a plan drawn against it is drawn for
moments that have already passed, and reading the clock any other way would
report every action as arriving a week late.
Wiring this in caught a bug in the approval queue
shipped an hour earlier. Letting the candidate scan run to completion — so the
queue could see the whole pool rather than only what preceded one dispatch — left
a loop variable describing the last candidate instead of the chosen one, so every
action was being re-ruled against an unrelated subject. It surfaced as fire-time
refusals naming rules that do not depend on the clock at all, which is the kind of
wrongness that is only obvious because each refusal has to name the rule that
produced it.
What a receiver has to refuse
Polling is the wrong shape for this. A dispatch settles when a human
opens a link, so a poll either runs constantly and learns nothing or runs rarely and
reports recovery long after it happened. Razorpay pushes the news instead.
A webhook receiver is the one place in this system where an outsider proposes
a change to the revenue number — everything else is proposed by our own planner and
disposed of by our own rules. So it is written as a list of refusals. Four deliveries,
four different answers:
delivery
verdict
answer
Signed with the wrong secret
rejected
400
A payment link the merchant created themselves, paid
unmatched
200
An order recovery dispatched, paid
recovered
200
The same delivery, sent again
duplicate
200
The second row is the counterfactual argument arriving over
HTTP. A merchant’s own payment links are paid all day; that is real revenue and
recovery caused none of it. A receiver that credited every payment_link.paid
on the account would make exactly the error the receivables surface exists to warn
about — measuring the world’s ordinary behaviour and booking it as the agent’s work.
It answers 200 because it was handled correctly, and only a bad signature is a 400.
The signature is checked against the raw bytes, before parsing, always; a missing
secret fails closed, because a receiver that treats “no secret configured” as
“everything is authentic” is worse than one with no check at all. Deduplication runs
in two layers — on the delivery, and underneath it on the dispatch, which is the thing
that can be recovered once. And settlement value goes through the same call the poll
uses, so a re-registered mandate is a year of billing whichever way the news arrives.
One caveat, stated rather than
buried. Receiving a real delivery needs a public URL, which a walkthrough on a
laptop does not have — so the sample above is signed locally. The verification, the
matching and the crediting are the real ones. Only the postman is simulated.
Building it surfaced a bug that had been in the adapter
since it was written. The record of what went out lived only in memory, so a process
that sent a link and then died had lost its only handle on it — and a payment landing
on that link could never be credited by either path. An already-sent action now looks
its reference back up. Probed rather than assumed: payment links filter on their
reference, orders on their receipt. Authorisation links do not come back from the
invoice listing at all, so that one is stated as a gap rather than guessed at.
A process that forgets is a process that repeats
The scheduler holds actions for hours or days. That is the point of
it, and it is also an assumption that one process will still be running when the
moment arrives — which is not an assumption a deployment gets to make.
The obvious cost of a restart is lost work: a held action nobody ever fires. The
expensive cost is quieter. Three sets in this system are what make “once” mean
once — the record that an approval was already spent, the record of what was
already dispatched, and the record of what was already credited. Emptied by a
restart, the first sends a second message to somebody off one reviewer’s single
yes; the second orphans a live payment link, so money landing on it can never be
credited by a poll or a webhook; the third books one payment as recovery twice,
and Razorpay redelivers webhooks by design. Those are not lost work. They are lost
guarantees, which is why the journal lives next to the rules rather than in a
deployment note.
Whole snapshots, appended, last one wins. Every state change
writes the complete entity rather than a description of what changed, and replay
keeps the last snapshot of each id. That is the opposite of the usual advice, and
the reason is how writes fail: a torn record in a delta log leaves an entity in the
wrong state forever — an approval whose release record was lost is an approval that
can be spent again — while a torn snapshot costs one update and the entity falls
back to its previous known state. Stale, but never invented. Anything unparseable
is skipped and counted rather than guessed at, and every append is fsynced before
the caller is told it happened, because a durability layer that loses the last
write in exactly the crash it exists for is decoration.
Restoring changes nothing about what may happen. A restored
action still does not fire early. A moment that passed while the process was down
is still dropped as stale rather than fired two days late. A restored approval is
still re-ruled before it dispatches. And the deferral counter comes back where it
was — otherwise a crash loop would be an unbounded retry loop, three pushes at a
time.
the process dies here — nothing below reads a single object from above
restored 08-31 01:00 UTC order_0001000006352 waiting
restored 09-02 03:00 UTC order_0001000006271 waiting
restored 09-02 06:00 UTC order_000100000f9cb waiting
restored inv_00010000104eb approved by ops@merchant.test, still unspent
two days later, the clock advancesstale 08-31 01:00 past the 1 day horizon, so not fired late
dispatched 09-02 03:00 order_0001000006271
deferred 09-02 09:00 outage_hold moved it to 09-02 09:00
dispatched 09-02 09:00 blocker had cleared
recovered a payment lands on the dispatched link, in the new process
duplicate Razorpay redelivers it — credited nothing, twice is once
Two limits, stated rather than
buried. Nothing ticks the scheduler on a timer — the walkthrough steps a clock to
each moment, and a deployment would run the same loop against the same file on a
real one. And the journal is a file, so it assumes a single writer; two schedulers
on one file would interleave snapshots and the last would win. That wants a
database, and every component takes the store as a constructor argument so
swapping one in is not a rewrite.
Wiring this up found a bug older than any of it.
RESCHEDULE was not counted as an allowed disposition, and the measured
arm skipped everything that was not allowed — so the three rules that exist to
move an action were quietly working as three more ways to kill it. On
seed 1 that is 588 of the 34,808 actions the policed arm proposed: an SMS pushed
out of the night was not sent in the morning, it was not sent at all. It survived because it produced no record — an
action absent from the executed list looks exactly like an action nobody proposed.
Every refusal in this system names the rule behind it, and now every deferral does
too.
Two of these properties cannot be printed
A transcript scrolls past in a second. A deferral landing and an
approval being overruled are things that happen in time, and neither
survives being flattened into a log.
So there is a console: a browser over the same objects, running the same engine,
reading the same ledger. It is a viewer and a set of controls, not a second
implementation — no route in it decides anything, because a safety boundary
somebody could reach around by adding an HTTP handler would not be one.
It rules on two plans at once. The argument this system makes is
comparative: same rules, same contexts, same moments, and the only difference is
whether the rulings are obeyed. A stream drawn from Backstop’s own playbook makes
that argument badly — a good planner rarely proposes anything the rules must
refuse, so on a sample of 450 subjects it draws nine denials against 510
permissions, and a page showing only that is a boundary holding back nothing. The
naive plan is ruled beside it, in the same engine, and lights eleven of the sixteen
rules. It is displayed and dispatched nowhere; a console is not a place to run an
unpoliced arm at a person.
It moves a clock. Advancing it is the loop a deployment would run
against real time, with the waiting taken out. Actions come due and are re-ruled at
the moment they land; deferrals go back into the queue with their new time;
approvals nobody answered expire on the hour they expire. That last one is the
backtest’s staffing assumption made falsifiable rather than convenient — a merchant
who does not staff the desk does not get the revenue, they get a pile of expired
requests.
And it can show an approval being overruled, which is the one
property of the queue a screenshot cannot assert. Approve everything pending, let
eighteen hours pass, release: the rules refuse three of them, because the buyer
committed to a payment date in the interval between the ask and the answer.
seed 1, a 450-subject sample — the console opens on this
backstop 510 allow 14 reschedule 161 require_approval 9 deny
naive 349 allow 237 reschedule 181 require_approval 733 denyrun the clock out with nobody at the desk
342 fired · 0 fired early · 0 dropped as stale · 161 approvals expired unanswered
or approve all 161, wait eighteen hours, then releasereleased 158
refused 3 promise_to_pay — the buyer committed to a date while the request sat
The clock starts at the earliest
moment the plan asks for rather than at “now”, because the batch is historical and a
plan drawn against it is drawn for moments that have already passed. Read the clock
the other way and the scheduler is quite right to drop the whole plan as stale — the
console would open on 239 actions it had already given up on. The live tab binds the
test-mode adapter, rules on an action again at the moment the button is pressed, and
returns a payment link that opens; POST /webhooks/razorpay is the
receiver with a server in front of it at last, raw bytes through, signature checked
before anything parses them.
What these numbers are not
Recovery rates in simulate/recoverability.py are stated configuration,
not measured from Razorpay traffic. No real transaction data exists for this, so the
batch is generated — which is what makes the rest checkable: every incident is planted
deliberately, so detection and diagnosis are scored against truth rather than against
a vibe, and the detector never sees any of it.
Read the tables as a comparison under a declared world model, not as a forecast. The
agent is also graded against rates deliberately different from the ones it believes,
so it cannot mark its own homework.
Run it yourself
# the operator console: two plans, a clock you can push, a live dispatch
python -m backstop.console
# the full walkthrough, 20 seconds, ground truth beside every prediction
python -m backstop.demo --offline
# just the safety boundary — sixteen probes, including ones that must be refused
python -m backstop.demo --stage policy
# the four-arm measurement
python -m backstop.evaluation.backtest
# the queue, the webhook receiver, and a real dispatch — needs test-mode keys
python -m backstop.demo --stage razorpay
# kill it mid-flight and bring it back — no keys, no network
python -m backstop.demo --stage restart