← Blog

August 6, 2026 · 10 min read

How to build an OpenClaw automation that survives retries

A practical design for scheduled agent work that can time out, retry, and still avoid duplicate emails, posts, commits, or charges.

An OpenClaw automation survives retries when running it twice produces one intended outcome. That property is called idempotency. You need it before you automate anything that sends, publishes, charges, deletes, merges, or writes to shared state.

The dangerous failure is rarely a clean crash before work begins. It is a timeout after the side effect happened but before the agent recorded success. The next run sees no completion marker and does the same thing again. Congratulations, your weekly report has become a two-email tradition.

Start with an outcome key

Every run should derive a stable key from the outcome it intends to create. A daily report might use report:2026-08-08. A deployment might use deploy:repo:commit-sha. A content publish might use site:slug. The key describes the business effect, not the attempt number.

job: weekly-ops-report
outcomeKey: weekly-ops-report:2026-W32
attempt: 2
state: running
expectedArtifact: reports/2026-W32.md
sideEffect: email:jake@example.com:weekly-ops-report:2026-W32

Attempts get unique folders and logs. Outcomes keep the same key. That lets you investigate attempt two without letting it create a second outcome.

Separate the phases that people usually blur together

PhaseQuestionDurable evidence
PlanWhat outcome are we trying to create?Outcome key and acceptance checks
PrepareIs the artifact complete and valid?File, checksum, test output, preview
CommitMay the external side effect happen?Approval or explicit authority
ExecuteDid the side effect happen?Provider ID, commit SHA, message ID, URL
Close outDoes the result satisfy the original outcome?Terminal status plus independent verification

For an email job, rendering the report and sending it are different phases. For a blog job, writing a post, committing it, deploying it, and seeing the production URL are different phases. A single 'done' boolean cannot explain where the run stopped.

Check before you act

  1. Look up the outcome key in your local status store.
  2. Look up the external system when possible. Search the sent mailbox, deployment provider, git log, or publishing API.
  3. If the effect already exists, verify it and close out without repeating it.
  4. If state is ambiguous, stop and surface the ambiguity. Do not guess with a second irreversible action.
  5. Only execute when both local and external checks say the outcome is absent.

This is why provider-generated IDs matter. Save the email ID, payment idempotency key, deployment ID, pull request number, or post URL immediately after the call succeeds. A prose note saying 'sent email' is much harder to reconcile after a crash.

Use safe writes for local state

Do not let retries overwrite the same mutable attempt folder. A timed-out process may still be writing after the scheduler marks it failed. Give each attempt its own path, then maintain a small parent summary that points to the accepted attempt.

runs/weekly-ops-report/2026-W32/
  summary.json
  attempt-1/
    status.json
    report.md
  attempt-2/
    status.json
    report.md

Write terminal status before optional cleanup. If the required artifact and checks pass, mark done, then write the nice summary. Otherwise a timeout during summary writing can make completed work look abandoned.

Retry policy by side effect

ActionAutomatic retry?Guard
Read API dataUsuallyBackoff and bounded attempts
Write a local attempt fileYesFresh attempt path
Create a git commitWith careCheck intended paths and existing commit
Send email or messageOnly with dedupeStable message key or sent-item lookup
Publish a postOnly with slug lookupCanonical slug and production check
Charge or transfer moneyProvider support requiredProvider idempotency key and strict authority
Delete dataNo blind retryExplicit target verification and recovery plan

The parent must verify the child

A worker's final sentence is not evidence. The parent or controlling run should reconcile the task record, terminal status, expected artifact, repository state, and external side effect. This sounds fussy until the first time a worker finishes the work and times out while trying to report it.

OpenClaw gives you task records and automation run history. Use them, but do not confuse platform success with business success. A run can execute cleanly and still produce the wrong report. It can also time out after producing the right one. Your acceptance check closes that gap.

A small template for the automation prompt

Outcome: create exactly one weekly report for {{week}}.

Before acting:
1. Derive outcome key weekly-report:{{week}}.
2. Check summary state and sent-mail records for that key.
3. If already sent, verify and close out without sending again.

Execution:
4. Work in a fresh attempt folder.
5. Validate the report before any external action.
6. Send once, record the provider message ID, then mark done.

On ambiguity:
7. Stop with state blocked and report the exact reconciliation needed.

The wording is deliberately dull. Reliable automation is mostly clear ownership, durable evidence, and refusing to improvise around ambiguity.

Frequently asked questions

What does idempotent mean for an AI agent?

It means repeating a run does not repeat the intended side effect. The workflow checks a stable outcome key and external evidence before sending, publishing, charging, or changing shared state again.

Should OpenClaw automatically retry failed jobs?

Retry read-only and safely isolated work with bounded backoff. Retry external side effects only after adding a reliable deduplication or provider idempotency mechanism.

Is a successful task record enough to prove completion?

No. Verify the expected business artifact, such as the sent message ID, deployed URL, commit SHA, or generated report, in addition to the task record.

Sources and further reading

More posts

November 2, 2026

An outdated dependency is not a security alert

October 30, 2026

Your certificate renewed. Is the public hostname serving it?

October 27, 2026

Your GitHub Actions run history is not your bill

October 23, 2026

A DNS record changed. Should your OpenClaw monitor alert?

October 20, 2026

Zero errors is not always good news: checking the log pipeline before an agent alerts

October 17, 2026

A running container is not a healthy service: an OpenClaw monitoring runbook

October 14, 2026

OpenClaw database backup checks vs restore tests: what each proves

October 5, 2026

OpenClaw automation ran, but no message arrived: diagnose execution and delivery

October 2, 2026

OpenClaw SecretRefs for recurring workflows: a practical migration checklist

September 29, 2026

The scheduled blog queue ran dry: a runway check that catches it early

August 24, 2026

Agent workflow validation checklist before you reuse a template

August 21, 2026

Bounded background tasks for coding agents

August 18, 2026

Agent runbook status files that actually work

August 15, 2026

7 OpenClaw workflows worth running, and 5 that are not

August 12, 2026

The OpenClaw workflow security checklist we use before turning on tools

August 9, 2026

Your HEARTBEAT.md should be boring

August 3, 2026

OpenClaw cron vs heartbeat: the production rule that actually works

April 30, 2026

OpenClaw just shipped real voice agent calls. Here are 5 workflows worth setting up.

March 27, 2026

The best OpenClaw skills nobody knows about

March 25, 2026

Top AI agent workflow templates for developers in 2026

March 23, 2026

OpenClaw vs n8n: when to use each for agent automation

March 20, 2026

How to automate Make.com workflows with AI agents

March 18, 2026

Best n8n workflow templates for email automation

March 15, 2026

OpenClaw starter packs: the fastest way to a useful agent

March 12, 2026

How to build your own OpenClaw runbook from scratch

March 9, 2026

5 OpenClaw workflows that save 10 hours/week