DEV Community

macro8n | Desktop Automation
macro8n | Desktop Automation

Posted on AI-assisted

How to Make Desktop Automation Recover Safely After a Failure

A desktop automation that works once is a demo. One that can explain a failure and resume safely is useful in a real workflow.

Desktop workflows break for ordinary reasons: a window loses focus, a dialog appears, a network call returns late, an application changes its layout, or a run times out after an external action already succeeded. Blind retries can create duplicate files, repeat a change, or send the same request twice.

A small recovery contract for each step helps prevent that.

1. Give every step a clear contract

For each action, write down:

  • Precondition: what must be true before the step starts?
  • Action: what does the step change?
  • Postcondition: what evidence proves it completed?
  • Failure path: what should happen if the evidence is missing?

For example, a “save report” step should not be considered complete just because the save shortcut was sent. Check that the expected file exists, has a plausible size, and is newer than the run start time.

2. Match retries to the side effect

Retries are safe only when the operation is safe to repeat.

  • A read-only lookup can usually use a small, bounded retry with backoff.
  • A write with a stable idempotency key can be retried, then reconciled against its result.
  • A click or request whose outcome is unknown should stop and inspect the target state before trying again.
  • An action that sends, publishes, pays, or changes access should pause for explicit human review.

A timeout describes what the caller observed; it does not prove what the other system committed. Model “outcome unknown” as a real state instead of turning every timeout into a failure or an automatic retry.

3. Save checkpoints that help a person resume

A checkpoint should tell the operator which steps completed, what the workflow expects next, and what condition must be checked before resuming. Keep secrets out of the checkpoint and logs; store credential references, not credential values.

For UI workflows, a useful checkpoint might include the active step, the expected window or page, and a short result summary. Avoid recording more screen or user data than the workflow needs.

4. Make silent failures visible

An exception alert is not enough. A pipeline can return HTTP 200 and still produce an empty or stale result. Add checks for business invariants such as:

  • output count is within an expected range;
  • the last-updated timestamp is recent;
  • required fields are present;
  • a synthetic end-to-end run reaches its final state.

Use bounded retries, then alert with the last confirmed step and a safe-to-share error summary. That makes recovery faster without putting credentials or private inputs in the log.

5. Test the failure path on purpose

Before relying on a workflow, try losing focus, delaying a response, changing a dialog, and dropping a response after the target may already have completed the action. Check that the workflow stops safely, reports what is known, and does not duplicate the side effect.

The goal is not to make every UI change impossible. It is to make uncertainty visible and recovery deliberate.

I’m building Macro8n, a local-first desktop automation app with visual workflows. It has a free mode you can try on your own computer: https://macro8n.com/

Top comments (0)