ExpenseBot turns receipts from Gmail, cards and uploads into expense records. Our daily checks look for things like a duplicate, a wrong date or a missing receipt. When we confirm a problem, our agents fix the code and use reversible tools to repair the affected records. Larger repairs wait for a person.
It looked like it was working, because every run produced a report. Then we stopped reading the reports and checked the records ourselves.
We found four problems:
- One budget was a single point of failure. When the shared Claude usage limit ran out, the repair run and the scorecard both stopped for three days. Nothing picked up the work.
- "Pushed" was being treated as "done". We had shipped 26 code fixes with tests. We hadn't checked that they were running in production. We've since confirmed all 26.
- Old cases sat open. Our repair queue had 125 cases that had been open for more than a week.
- Cases could close on paper. "Documented" or "noted" counted as closed, even when nobody had confirmed the customer's records were repaired.
This is the failure Anthropic describes in its research on long-running agents: they declare the job done too early and leave half-finished work behind. Better prompts didn't fix it for us. We wrote three rules and put them in code.
The architecture at a glance
Checks feed cases into one ledger. The scorecard reads it and turns anything red into a dated to-do item. Three workers claim items. To close a case as fixed, we record the repair, the commit and the regression test. A separate check confirms production is running that commit. Two days later, we check the outcome on real data.
Rule 1: closed means fixed, and the code checks
Every problem now ends one of two ways.
- Fixed. The worker has to attach three things: proof that every affected customer record was repaired and read back, the commit that fixes the whole class of bug, and a test that fails without that fix.
- Dropped. Either there is evidence it isn't a bug, or someone decided the fix is too risky. That call comes from a person or a separate reviewing model, never from the agent that wants the case closed.
The command that closes cases refuses anything else. "Documented" used to be a way out. Now it returns an error.
Two habits came with it. The first is to check which records were affected. When one customer hits a bug, the agent checks the other accounts the same bug could have touched and repairs the records it confirms were affected. Repairs use reversible tools, and anything touching more than 10 accounts at once waits for a human. The second is to reopen the case if the problem comes back after the fix ships.
The life of a case
Here’s how we follow a confirmed bug from the first alert through the outcome check.
- Detected. A scheduled check finds it, or a person does. When a person finds the problem, we add an automated check for it the same day, so the loop catches the next one.
- Claimed. One agent takes it, so two agents don't work it at once.
- Reproduced. The agent reads the real evidence (the email, the sheet row, the logs) and confirms the failure.
- Data repaired. The agent finds the other accounts the same problem touched and repairs them through guarded, reversible tools, then reads each one back.
- Class fixed. The cause is fixed in code, with a test that fails without the fix.
- Confirmed in production. A script checks that production is serving the fix commit.
- Outcome checked. Two days later, the result is checked on real data.
- Closed, or reopened. If the problem comes back, the case reopens and its stored lesson is flagged.
A "fixed" closure has to include its proof. Here is the shape of one from our case ledger:
{
"disposition": "fixed",
"repairRef": "repair run id + readback of every affected record",
"classFixRef": "commit that fixes the whole class",
"regressionTestRef": "test file that fails without the fix",
"actor": "claude"
}A "dropped" closure carries either evidence that it isn't a defect or a decisionRef pointing to the person or reviewing model that judged the fix too risky. Closures are create-only: a closure is written once and not edited afterwards.
Rule 2: two AI agents, one to-do list
We run agents from two companies: Claude (Anthropic) and GPT through Codex (OpenAI). For a long time they didn't coordinate. Each kept its own notes, so neither knew what the other had picked up, and when Claude ran out of budget, its work waited.
Now they share one to-do list, stored in our database, where both can read it. Every item has an owner, a next action and a due date. Every run starts by reading the list and ends by updating it. Before touching an item, an agent claims it, so the two don't work the same thing at once.
The list also handles the outage case. If Claude's morning run fails because it hit a usage limit, GPT's run later that morning is set up to claim the day and work through the backlog under the same rules. Both agents read one shared rulebook. When we change a rule for one, we change it for the other the same day.
A due date can't be quietly pushed back. An overdue item stays overdue, shows up as a failure, and is the first thing the next agent picks up.
What's on each item
| Field | What it holds |
|---|---|
| id | A stable name, so two runs never create the same item twice |
| owner | One agent or one person, never "the team" |
| stage | Open, waiting on someone outside, done or dropped |
| nextAction | The single next step, in one sentence |
| dueDate | A calendar date, at most 7 days out |
| dependency | Required when the item waits on someone outside, such as a vendor or a customer |
| evidenceRef | Where the proof lives once it's done |
| claim | Who holds it right now, and when that hold expires |
How claiming works
- A claim is written in a single database transaction. If another agent already holds a live claim, the write is refused.
- Every claim is a lease with an expiry: 30 minutes by default, two hours at most. If an agent crashes, its lease runs out and the next agent takes over. If the slow agent comes back later and tries to write, it is refused, because the item now belongs to the new holder.
- Each takeover bumps a generation number, so you can see when an item changed hands.
- Closing an item requires an evidence reference, and no agent can update or close an item another agent is holding.
Three limits keep the list short and current. It holds at most 40 open items. A due date more than 7 days out is rejected unless the item names an outside dependency. A lint check runs at the end of each agent run and fails on any item missing an owner, an action or a date.
Rule 3: a scorecard that needs no AI, and checks the loop too
The day starts at 6:15 a.m. with a plain script. No model is involved, so a usage limit can't stop it. It scores each part of the loop green or red: did the repair run happen, are new problems being noticed, are fixes landing, are they live, did they work.
Every red part becomes an item on the shared to-do list, due the next day. When the part turns green, the item closes on its own. Nobody has to notice the problem or remember to follow up.
The scorecard also checks the loop itself. Did yesterday's scorecard run? Did someone claim yesterday's repair work? Is anything more than two days overdue? Does every open item have an owner and a date? If any answer is no, the loop has a bug, and it's fixed like any other bug: an agent claims it the same day and repairs the script, the schedule or the prompt.
Once a week, an agent looks at the last seven scorecards. If a part was red on three or more days, the agent treats it as a problem with the loop itself. It changes the loop and writes down what it changed and why.
The daily cycle, in order:
- 6:15 a.m. The script runs the checks and scores the loop. Red parts become to-do items.
- 9:05 a.m. Claude claims the day and works the open cases and its due items.
- 10:45 a.m. GPT reads the list. If Claude hit its usage limit, GPT is set up to take over the day.
- 11:31 a.m. A second Claude run starts from the scorecard and fixes the weakest red part.
What the scorecard checks
Each part reads stored records and scores them green, amber or red. No part asks a model to judge.
| Part | Turns red when |
|---|---|
| Consumer | Yesterday's repair run didn't happen, or nobody claimed it |
| Notice | A detection check has gone stale, or the daily report is missing |
| Fix | Any loop-owned case is older than 7 days without a closure or a named outside dependency |
| Verify | Shipped fixes aren't confirmed as running in production |
| Outcome | The number of open problems customers see is growing instead of shrinking |
| Memory | The agents' always-loaded memory is close to its size limit, so lessons risk being cut off |
| Machinery | The loop itself broke: yesterday's scorecard didn't run, a to-do item is more than 2 days overdue, an item is missing an owner or date, or the weekly lesson check didn't run |
The last row checks the loop itself. It catches slow failures that no single case would show, such as a scheduled job that has stopped running.
One job per loop
The biggest lesson we took from David Ondrej's goal loop is that a loop should have exactly one job. Our main repair run had grown the opposite way. Every time we found a new kind of problem, we added another paragraph to the same prompt. It came to cover duplicates, card matching, team accounts, bill payments and more, in one long set of instructions that kept getting harder to follow reliably.
So every loop starts with a short contract: one sentence saying what it is for, the business result it is judged on, its limits, the files to read first, the command that proves progress, when to stop, and where it logs what it did. Long details live in reference files the loop opens when it needs them, not in the prompt itself.
The new pieces follow this from the start: the scorecard only scores, the evaluator only fixes the weakest red part, and the to-do list only tracks work. We're splitting the main repair run the same way, into eight smaller loops, each with its own contract and stopping point.
Here is a contract in the shape we use, written for the daily scorecard. Copy the shape for your own loops:
Objective: Score the self-healing loop once a day and turn every red part into dated work.
Outcome: Problems customers see go down; no failure goes unnoticed for more than a day.
Constraints: Reads only. No AI model. Never edits cases or customer data.
Writes one scorecard record and to-do items, nothing else.
Read first: The closure rules, the to-do list rules, yesterday's scorecard.
Validation: The scorecard record exists for today, and every red part has an
open to-do item due tomorrow.
Stop when: All parts are scored and the to-do list passes lint.
Run log: One line per run in its own log file, so any run can be traced and undone.If a line takes more than a sentence or two to fill in, the loop is probably doing more than one job.
Why we held off on Dreams
Short answer: we held off on Anthropic's Dreams because our agents don't run on Managed Agents, and using it would mean uploading customer data to a preview service that isn't covered by zero data retention. We built a weekly check of our stored lessons instead. It costs nothing extra to run.
Dreams is a research preview for Anthropic’s Managed Agents platform. You give it an agent's memory and a batch of past sessions. It runs as a separate job and writes a new, consolidated memory store. Your original memory is left untouched, and you decide whether to use the new one.
We like the idea. Anthropic's own memory research found that a pass like this corrected a wrong note that had been causing repeated failures, and that small, accurate memory beats a large, messy one. Our loop keeps a short lesson for each kind of problem it has fixed, more than 120 of them, and lessons like these go stale over time.
We decided not to turn Dreams on yet:
- It doesn't fit how our agents run. Dreams works on Managed Agents sessions. Ours run as scheduled Claude Code and Codex jobs, so we would have to migrate first.
- It would mean uploading customer data. Our agents' work logs include customer receipt details, and we won't send those to a preview service. Dreams is a preview, isn't covered by zero data retention, and keeps transcripts until you delete them.
- We wanted to review each lesson. Dreams leaves the original memory intact. We wanted a reviewer to approve each proposed change to a lesson.
- It costs extra, on the same AI budget whose limit had already stopped us once.
- Our lessons are short. A plain script can check most of what matters for free.
So we kept the idea and built a cheaper version. Every Monday, a script checks each stored lesson against its own evidence. Is the fix it points to still in the code? Does its test still exist? Did the problem come back after we called it fixed? Does a newer lesson contradict it? Lessons that fail come back as proposals, not automatic edits, and a reviewer approves each change.
We'll revisit Dreams later, as an offline trial on sanitized lessons with a measured result.
What runs every day
Put together, this is what happens every day without anyone starting it:
- A case closes as fixed only with a repair, a fix and a test, and the code enforces it.
- Claude and GPT work from one shared to-do list, and GPT is set up to take over if Claude hits its usage limit.
- A scorecard that needs no AI scores the loop each morning, checks the loop itself, and turns anything red into dated work.
- A shipped fix counts only once it is confirmed running in production and checked on real data.
- Every Monday, each stored lesson is checked against its evidence.
Each piece is small. Together they keep a problem on the list until someone can show what happened. If it comes back, the case reopens.
If you connect accounting systems with agents
When an agent can write to a ledger, "it said it fixed it" isn't good enough. These are the rules we'd want from any vendor we connect to, and the ones we hold ourselves to:
- Repairs can be undone. The loop marks a bad row as excluded rather than deleting it, so a wrong repair can be reversed.
- Repairs are read back. A case can't close as fixed until the agent has re-read the repaired record.
- Fix the whole class of bug. One customer's bug triggers a check of every account it could have touched.
- Humans keep the big decisions. Repairs across many accounts, sharing changes, pricing and anything that deletes data need a person's approval.
- There's an audit trail. Every case keeps its evidence, the fix commit, the test, and who closed it.
- Helper models have no production access. They can draft code fixes. They can’t apply them to customer records.
If you're building integrations where agents touch financial records, we'd like to compare notes.
What you can copy
You don't need our stack to use these ideas. If you run agents that are supposed to fix things on their own, try this:
- Give each loop one job and a short contract: its purpose, how it proves progress, and when it stops.
- Write down the only two ways a case may close, and make the closing command refuse anything else.
- Count a fix as finished when it is deployed and confirmed working. Merged is too early.
- Score the loop with a plain script that keeps running when your AI budget runs out.
- Turn every red score into a dated item with an owner, and never let a date slide quietly.
- If you run more than one agent, give them one shared list and a claim step before they touch anything.
- Have the loop check itself, and fix its own breakdowns like any other bug.
- Check stored lessons against evidence on a schedule, before you reach for a bigger memory tool.
We built this on ideas from Anthropic's agent research and David Ondrej's goal loop: one goal per loop, a command that proves progress, a clear stopping point, and never weakening a test to make it pass.
Sources
- Effective harnesses for long-running agents, Anthropic, 2025-11-26
- Building effective agents, Anthropic, 2024-12-19
- Demystifying evals for AI agents, Anthropic, 2026-01-09
- The components of agent memory, Anthropic, 2026-11-06
- Dreams, Claude Platform docs (research preview)
- goal-loop skill, David Ondrej
