Inspiration
You get the alert: "Your account has been debited."
But the airtime never arrives. The transfer says pending. The POS said "failed," and your balance says otherwise. Then comes the waiting: a reversal "within 24 hours," a call to customer care, a screenshot sent to a friend who works at a bank.
A few months ago, I sent money home on a shaky connection, got debited twice, and spent three days chasing customer support for a reversal that never should have been needed.
If you've lived in Nigeria, you know that feeling in your stomach. Behind it is always a person: a trader waiting on a payment, a student whose school fees are stuck on "processing," someone trying to send money home.
I'm a student in Lagos who builds backend APIs, which means I'm one of the people who writes the code behind that alert. What bothers me is how rarely these failures look like failures. The code runs. The tests pass. The demo is fine. Then two requests arrive at the same instant, or a phone retries on a weak signal, and money is lost, created, or counted twice. Real people pay for that.
AI has made this sharper. I can ask an assistant for a withdrawal endpoint and get clean, confident code in seconds, which is exactly the kind of code that looks right. I wanted a tool that doesn't trust looks. One that asks the uncomfortable questions (what if this runs twice, at once, or only halfway?) before a real person finds out the hard way.
What it does
ContractReaper is a safety check for APIs that move money.
- It reads your API and suggests the rules that must always be true, like "a balance never drops below zero" or "a retry never charges twice." Each suggestion shows the exact code it came from.
- You decide. You approve, edit or reject every rule. Nothing runs until you say so.
- It attacks your API. It tries hundreds of random sequences: retries, simultaneous withdrawals, transfers that fail halfway. When a rule breaks, it shrinks the failure to the smallest version that still breaks and saves a replay code.
- It hands the fix to Kiro. You get a plain-language report and a bugfix spec. Kiro reads the failure, proposes a fix, and you review it. Then you re-run the exact same failure and watch it go from red to green.
It never edits your code on its own. And when it finds nothing, it says "no violation found in this run," not "your API is secure," because a test run can't promise that.
How we built it
- A target worth breaking. A Wallet API in TypeScript and Express on SQLite, seeded with synthetic accounts and three planted bugs: duplicate debit on retry, negative balance under concurrent withdrawals, partial transfer with no rollback. It has a one-click reset and vulnerable and fixed modes.
- Evidence, not guesses. An OpenAPI parser and ts-morph read routes, field names, headers (like Idempotency-Key) and handlers with multiple writes, then turn them into candidate rules with source locations. Deterministic templates do this by default; an LLM is optional, so the whole demo works with no API key.
- A typed rule language. Approved rules live in a small Zod schema, never as free-form code. The families are bounds ($b \ge 0$), idempotency, and atomicity and conservation ($\sum_i b_i^{\text{before}} = \sum_i b_i^{\text{after}}$). LLM output is never executed.
- Property-based testing with fast-check. Command-based sequence tests generate the operations. For races, fast-check's scheduler controls the order in which async steps resolve, so the same interleaving can be replayed from a seed and shrunk to a minimal case. A parallel-request burst against the live server is a realism check (14 of 50 bursts reproduced it).
- Reports and specs. A Markdown Reaper Report with the rule, the repro, the seed and expected versus observed state, plus a bugfix spec in Kiro's own format.
- Kiro, all the way through. A local MCP server (official TypeScript SDK) with five tools; specs that drove the build; steering files for product, tech and the rule language; a save-time hook that re-runs approved rules when route files change; and a custom "reaper" agent. I also used the Kiro CLI to run the test suite and verify fixes right from the terminal.
- The dashboard. Next.js, four screens: Evidence, Approve, Run, Report. A hosted sandbox at https://contractreaper.vercel.app runs only the bundled API, with production-looking targets blocked.
Challenges we ran into
- SQLite made the race too safe. It allows one writer at a time and better-sqlite3 is synchronous, so a naive "check balance, then write" never failed. I had to plant an honest async gap (a simulated audit step) between the check and the write, then drive it with the scheduler instead of hoping for luck.
- Replays must be exact. A seed only reproduces a failure if everything else is identical, so I reset state deterministically and injected clocks and IDs. The night I almost lost was debugging why fast-check's shrunk counterexample wouldn't replay deterministically. It turned out an unseeded UUID generator in the middleware was silently shifting the database state between runs.
- Shrinking stateful tests is slow. Every attempt needs a clean database, so I used in-memory copies and capped run counts for the demo.
- Keeping the AI honest. LLM suggestions are guesses. The typed rules, the evidence next to each claim and the human approval step keep them from becoming "truth" by accident.
- Scope. Eleven days, solo. I cut Prisma input, two rule families and three MCP tools to finish one flow well.
Accomplishments that we're proud of
- ContractReaper found 3 planted bugs automatically, with no hand-written test cases.
- It shrank one failure to a two-step repro that anyone can read.
- The same seed replays the same failure, and after the fix it goes green.
- Kiro read the failure through MCP and produced a bugfix spec, and I reviewed the change.
- It works with no API key, and was built solo, as a student, in 11 days.
What we learned
- The hard part of testing isn't generating inputs. It's naming the rule. Writing "a balance never goes negative" exposed gaps in how I thought about my own endpoints.
- Concurrency bugs only feel random. Once you control the schedule, they can be replayed and shrunk like any other failure.
- Specs and steering changed how Kiro behaved. A vague prompt got guesses; a bugfix spec with a failing seed got focus. The moment that surprised me was watching Kiro read the failing concurrency trace via MCP and immediately wrap the balance check and debit in an atomic transaction without touching unrelated routes.
- Evidence beats confidence. Showing the code behind every AI suggestion earned more trust than any score could.
- Kiro's property-based testing checks that new code matches the spec you wrote. The gap I wanted to close was existing code whose rules were never written down.
- Money bugs are people bugs. I'll remember that more than any library.
What's next for ContractReaper
- A PostgreSQL adapter with row-locking tests (SELECT ... FOR UPDATE).
- Ledger reconciliation as a fourth rule family, so a stored balance always matches its transaction history.
- Support for more frameworks beyond Express, and a CI mode that fails a build when an approved rule breaks.
- Packaging the MCP server and steering as a Kiro Power.
- Talking to engineers at wallet and payments teams, including Nigerian fintechs, to learn which rules matter most in practice.
Built With
- better-sqlite3
- docker
- express.js
- fast-check
- fintech
- github-actions
- kiro
- kiro-hooks
- kiro-specs
- kiro-steering
- llm
- markdown
- mcp
- model-context-protocol
- next.js
- node.js
- openapi
- property-based-testing
- react
- sqlite
- tailwindcss
- ts-morph
- typescript
- vitest
- zod

