Agent repair workflows by failure
Keep state changes and events in one transaction
Keep the state change and its outbox or job record on the same transaction handle. A commit between the writes can leave the state changed without a durable event. Dispatch external work after the transaction commits.
How do I preserve a transaction when an agent refactors my service?
Choose the implementation for your framework. Each linked guide includes the source, integration prerequisites, failure-path tests, saved requirement and recorded check.
| Implementation | Saved requirement | Broken source | Corrected source | Capture date |
|---|---|---|---|---|
| Keep a FastAPI order update and its outbox event in one transaction | outbox-no-early-commit | Rule finding | No rule finding | 2026-10-14 |
| Create a Django outbox event atomically with the order change | outbox-same-atomic-block | Rule finding | No rule finding | 2026-10-14 |
| Keep Spring order confirmation and its outbox write under one proxy transaction | confirmation-transaction-boundary | Rule finding | No rule finding | 2026-10-14 |
| Keep NestJS event persistence on the supplied TypeORM transaction manager | outbox-transaction-manager | Rule finding | No rule finding | 2026-10-14 |
Inspect the requirement before installing it
The Keep a FastAPI order update and its outbox event in one transaction example uses this requirement on confirmation.py:
- name: outbox-no-early-commit
where: "confirmation.py"
ensure: >-
The order update and outbox insertion stay in the same transaction. The function must not explicitly commit inside the session.begin block before it finishes successfully.Exact corrected source and broken edit · Recorded Perch output · Download this requirement
Make the agent check the requirement after its edit
Keep your existing perch.yaml. The scoped rule pack installs the saved requirement under .perch/rules/. Review its file selector and use the implementation’s integration prerequisites before adapting it to your application.
Install Perch and configure your agent
npm install -g @lakeday/perch
perch login
# Choose the setup command for your agent:
perch setup claude-code
# Or: perch setup codex
# Or: perch setup cursor
Check the edit and recheck the repair
curl -fL 'https://reporules.fyi/fastapi/outbox-transaction/rule-pack.zip' -o requirement.zip
unzip -n requirement.zip
perch check confirmation.py --rules outbox-no-early-commit --json
# Read the finding, repair the implementation, then repeat:
perch check confirmation.py --rules outbox-no-early-commit --json
Run the same check on the repaired working file before committing. Keep the application regression tests alongside it. Fresh model judgments can vary; an unchanged request can reuse its cached answer. A passing check does not prove application correctness.
Compare the implementations before choosing a rule
- Keep a FastAPI order update and its outbox event in one transaction
Publishing a message after a database write leaves a crash window. An outbox row is written with the order state, so a worker can deliver it later. A unique event_key prevents accidental duplicate event insertion; a delivery consumer still needs its own deduplication. Inspect its rule pack.
- Create a Django outbox event atomically with the order change
An on_commit callback runs after commit but does not make message delivery durable. Store the event in the transaction and let a retrying worker publish it. Moving create outside the block makes a failed event insert leave a confirmed order without a delivery record. Inspect its rule pack.
- Keep Spring order confirmation and its outbox write under one proxy transaction
Repository methods may each be transactional while the service action is not. Without the outer transaction, saving the order and inserting its event can commit independently. A public proxy-invoked service method supplies the required boundary. Inspect its rule pack.
- Keep NestJS event persistence on the supplied TypeORM transaction manager
TypeORM’s global manager can run outside the transaction callback’s connection. That can leave an event committed without its business change or a change committed without its event. Keep every related read and write on the manager supplied to the callback. Inspect its rule pack.
Keep the check tied to its source
The table reports saved checks on the exact linked source versions. Adapt the paths, adapters and regression tests to your repository. The example source may differ from the released framework or your service; the recorded outcome belongs to that example.