Source: https://frameworkrecipes.dev/problems/retry-safe-work/

[Agent repair workflows by failure](https://frameworkrecipes.dev/problems/)

# Preserve completed work and reject duplicate delivery

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.

## How do I keep retries from losing work or applying it twice?

Choose the implementation for your framework. Each linked guide includes the source, integration prerequisites, failure-path tests, saved requirement and recorded check.

Existing captured source checks; these are individual examples

| Implementation | Saved requirement | Broken source | Corrected source | Capture date |
| --- | --- | --- | --- | --- |
| [Deduplicate a signed Flask webhook inside its state transaction](https://frameworkrecipes.dev/flask/webhook-deduplication/) | webhook-receipt-gates-side-effect | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/flask/webhook-deduplication/capture.json) |
| [Preserve complete POSIX writes when appending an order record](https://frameworkrecipes.dev/posix/complete-write-loop/) | partial-writes-advance-by-count | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/posix/complete-write-loop/capture.json) |

## Inspect the requirement before installing it

The [Deduplicate a signed Flask webhook inside its state transaction](https://frameworkrecipes.dev/flask/webhook-deduplication/) example uses this requirement on `webhooks.py`:

```
- name: webhook-receipt-gates-side-effect
  where: "webhooks.py"
  ensure: >-
    If the unique webhook receipt insert returns no row, apply_paid_event must return before changing any order.
```

[Exact corrected source and broken edit](https://frameworkrecipes.dev/flask/webhook-deduplication/source.json) · [Recorded Perch output](https://frameworkrecipes.dev/flask/webhook-deduplication/capture.json) · [Download this requirement](https://reporules.fyi/flask/webhook-deduplication/rule-pack.zip)

## Make the agent check the requirement after its edit

Keep your existing perch.yaml. The [scoped rule pack](https://reporules.fyi/flask/webhook-deduplication/) 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/flask/webhook-deduplication/rule-pack.zip' -o requirement.zip
unzip -n requirement.zip
perch check webhooks.py --rules webhook-receipt-gates-side-effect --json
# Read the finding, repair the implementation, then repeat:
perch check webhooks.py --rules webhook-receipt-gates-side-effect --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

- **[Deduplicate a signed Flask webhook inside its state transaction](https://frameworkrecipes.dev/flask/webhook-deduplication/)**

  A provider may deliver an authenticated event several times. Signature verification establishes its origin; a unique receipt and a transaction establish whether this application already processed it. Neither check replaces the other. [Inspect its rule pack](https://reporules.fyi/flask/webhook-deduplication/).
- **[Preserve complete POSIX writes when appending an order record](https://frameworkrecipes.dev/posix/complete-write-loop/)**

  write may accept fewer bytes than requested or be interrupted before writing. A log append helper must keep the remaining slice and retry interruptions. Treat a zero-byte write as an error rather than spin forever. [Inspect its rule pack](https://reporules.fyi/posix/complete-write-loop/).

## 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.

[Other agent-edit failure paths](https://frameworkrecipes.dev/problems/) · [All framework recipes](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/retry-safe-work/index.md) · [Resource index](https://frameworkrecipes.dev/llms.txt)

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