DEV Community

Warm Shore
Warm Shore

Posted on

Idempotent Browser Automation: How to Make Retries Safe

Browser automation becomes fragile when a retry can accidentally repeat an irreversible action. A resilient workflow treats every step differently depending on whether it is safe to repeat.

Separate observation from mutation

Reading the current page, checking the active URL, or inspecting a form can usually be repeated safely. Publishing a post, creating an account, sending a message, or changing a setting cannot.

That distinction should be explicit in the workflow rather than left to the browser agent to infer.

Use a one-way boundary

Before a final write action, collect enough evidence to prove:

  • the correct site and account are active;
  • the expected page and form are visible;
  • the content is bound to the intended context;
  • no contradictory authentication or validation state is present.

After the final submit, the workflow should change modes. It should no longer try to “finish the action.” It should verify what happened.

Reconcile uncertainty instead of retrying

The hardest case is an ambiguous response after clicking Publish or Submit. The request may have reached the server even if the browser timed out.

Blind retrying can create duplicates.

A safer pattern is:

  1. submit once;
  2. stop all writes;
  3. inspect the resulting page, permalink, account activity, or other read-only evidence;
  4. classify the outcome as confirmed, rejected, or still uncertain.

Make success independently verifiable

A click is not success. A robust automation system should verify persistence from a fresh view and record safe evidence such as the final URL, expected title, and whether the content is present.

This makes the workflow easier to audit and dramatically reduces duplicate actions.

The main idea is simple: retries are useful for observation, but irreversible writes need explicit single-submit semantics and read-only reconciliation.

Top comments (0)