Source: https://frameworkrecipes.dev/problems/

# Keep an agent’s next edit from undoing the fix

Save the requirement that the fix restored, check it after the next agent edit, and repeat the same check after a repair. Choose the failure below to find the relevant implementation, recorded broken/fixed source and downloadable Perch rule.

## [Stop stale responses from replacing newer state](https://frameworkrecipes.dev/problems/stale-responses/)

Invalidate the older request before the next one starts, and check that identity before writing either a result or an error. Cancellation saves work; the state guard decides which completion may update the screen.

## [Keep authorization inside the database write](https://frameworkrecipes.dev/problems/authorization-at-the-write/)

Keep the authenticated tenant or owner in the database operation that reads or changes the record. Save that requirement beside the code and check it after a refactor, including edits that leave a route-level permission check intact.

## [Keep state changes and events in one transaction](https://frameworkrecipes.dev/problems/transaction-boundaries/)

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.

## [Reject stale edits and serialize competing writes](https://frameworkrecipes.dev/problems/concurrent-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.

## [Preserve completed work and reject duplicate delivery](https://frameworkrecipes.dev/problems/retry-safe-work/)

Record whether an operation has already been applied, and keep that record atomic with its side effect. For a partial write, retain the completed byte count and advance from it. These examples distinguish duplicate delivery from incomplete progress.

## [Release resources on success, failure and disposal](https://frameworkrecipes.dev/problems/resource-cleanup/)

Keep release or disposal on every path that ends ownership, including exceptions and cancellation. A successful request alone cannot reveal a connection leak; check the error path and the lifetime of the component that owns the resource.

[Set up an agent to check a fix before committing](https://frameworkrecipes.dev/workflows/keep-agent-fixes/)

## Use the implementation that matches your application

The examples preserve different boundaries: a browser completion writes state, a database update enforces access, or a transaction owns an event. Keep that boundary explicit in the rule. [Browse all language and framework implementations](https://frameworkrecipes.dev/).

**Framework Recipes**

Implementation, failure path, check.

Published by Perch · © 2026 Verglas LLC. Framework Recipes is a Perch publication.

Perch’s MIT license covers the CLI; hosted model analysis is a paid service. Relevant source is sent to the configured model service.

[Perch CLI MIT license](https://github.com/lakeday-org/perch/blob/main/LICENSE) · [Article text](https://frameworkrecipes.dev/problems/index.md) · [Resource index](https://frameworkrecipes.dev/llms.txt)

[Privacy](https://frameworkrecipes.dev/privacy/) ·
