Agent repair workflows by failure
Reject stale edits and serialize competing writes
Put the availability decision inside a lock or conditional update, and reject edits based on an obsolete version. Choose the mechanism for the conflict: competing reservations and a customer submitting an old screen need different checks.
How do I keep two requests from changing the same stock or order incorrectly?
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 |
|---|---|---|---|---|
| Serialize Rails stock reservations with an Active Record row lock | locked-stock-availability | Rule finding | No rule finding | 2026-10-14 |
| Reject stale Rails cancellation decisions with optimistic locking | submitted-order-version | Rule finding | No rule finding | 2026-10-14 |
| Reserve stock in Express with one conditional database update | stock-never-negative | Rule finding | No rule finding | 2026-10-14 |
| Return a conflict when EF Core detects a stale order edit | stale-update-is-not-success | Rule finding | No rule finding | 2026-10-14 |
Inspect the requirement before installing it
The Serialize Rails stock reservations with an Active Record row lock example uses this requirement on app/services/reserve_stock.rb:
- name: locked-stock-availability
where: "app/services/reserve_stock.rb"
ensure: >-
Inside the row lock, available stock must be checked against quantity before it is decremented. Reject reservations that exceed the locked stock.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/rails/locked-stock/rule-pack.zip' -o requirement.zip
unzip -n requirement.zip
perch check app/services/reserve_stock.rb --rules locked-stock-availability --json
# Read the finding, repair the implementation, then repeat:
perch check app/services/reserve_stock.rb --rules locked-stock-availability --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
- Serialize Rails stock reservations with an Active Record row lock
The lock reloads the record and serializes competing reservations. An availability check made before taking the lock can become stale. Keeping the check, decrement, and save inside with_lock makes the inventory decision atomic for that row. Inspect its rule pack.
- Reject stale Rails cancellation decisions with optimistic locking
Active Record detects a write conflict after the record is loaded, but it cannot infer that a customer made a decision using an older screen. Compare the submitted version first, then let lock_version protect the save from a race that occurs during this request. Inspect its rule pack.
- Reserve stock in Express with one conditional database update
Checking stock in JavaScript and then writing a new total permits two requests to reserve the same remaining unit. A conditional UPDATE puts the availability decision into the database statement that changes the row. Parameter binding keeps the SKU out of SQL syntax. Inspect its rule pack.
- Return a conflict when EF Core detects a stale order edit
A concurrency token lets EF put the expected row version into the UPDATE predicate. When another edit won, the application must return a conflict or explicitly resolve it, rather than tell the caller their old decision succeeded. 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.