Rails: preserve requirements through advanced agent edits
Work through Ruby examples of real application boundaries: Serialize Rails stock reservations with an Active Record row lock; Reject stale Rails cancellation decisions with optimistic locking. Each recipe includes implementation code, integration prerequisites, failure-path tests to add, a Perch rule, and the captured broken/fixed source checks.
Download the Rails rule pack ZIP · Inspect the YAML rules
Ruby
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.
Broken edit flagged · corrected edit passes
Ruby
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.
Broken edit flagged · corrected edit passes
Introductory framework example
Use a correction as a saved requirement
Choose the failure you need to prevent, add the scoped rule to your repository, and check both the broken and corrected implementation. Ask your agent to inspect the finding, repair the code and recheck the same rule. Keep framework tests beside the model check.
Perch keeps the requirement beside the code. Reuse the named check during the agent’s next edit and in CI, with cached answers free on unchanged requests.
Official Rails documentation · All language and framework recipes