ANTIGRAVITY LABJP
Articles/Agents & Manager
Agents & Manager/2026-06-01Advanced

Rolling Back a Half-Finished Agent: Compensating Transactions for Partial Failure

When you let an Antigravity agent run work that spans several external systems, a failure in the middle leaves the world half-rewritten. Retrying doesn't fix that. Here is how to fold it back safely with compensating transactions (the Saga pattern), with TypeScript and real operational numbers.

Antigravity338AI agents24compensating transactionsreliability design4production operations5

Premium Article

Running six apps by myself, a release is never a single button. Update the AdMob mediation config, swap the App Store Connect metadata, flip a Remote Config flag, and finally draft a short announcement post. This was the sequence I'd been doing by hand since 2014, and this spring I started handing the whole chain to an Antigravity agent.

The first few runs felt great. Then, late one Thursday, it broke. The AdMob update landed, the Remote Config flag went up — and the App Store Connect metadata update hit a rate limit partway through the fourth app. The agent honestly reported "failed" and stopped. Correct behavior. But what I was left holding was a state that should never exist anywhere: the ad config was new, the store listing was half-new, and the flag had already turned a new feature on.

Telling the agent "just run it again" here is dangerous. Re-running non-idempotent operations could rewrite the already-successful AdMob config and double-fire billing events. Some kinds of breakage don't heal with a retry. What I needed was a way to deliberately undo side effects that had already succeeded — what distributed systems call a compensating transaction, or the Saga pattern.

Why retries aren't enough

When people talk about agent reliability, retries and idempotency keys come up first. I've written before about suppressing duplicate execution with idempotency keys. But that mechanism is for "send the same operation twice, take effect once." It is not for "fold up a state where some of several different operations succeeded and others didn't."

A multi-step side effect has three states:

  1. All steps succeeded — do nothing.
  2. All steps failed (never took the first step) — a retry is enough.
  3. Partial success — this is the real problem. You must decide whether to push forward to completion or roll back to nothing.

Retries only protect you in case 2. Case 3 — partial success — cements a "half-new world" into production if you ignore it. The agent can report that it stopped, but it won't clean up the side effects that happened before the point where it stopped. You have to fill that gap in the design.

The four rules a compensating action must satisfy

The heart of a Saga is giving each step a pair: a forward operation (do) and an undo operation (compensate). A compensating action is more constrained than an ordinary function. I refuse to accept anything as a compensation unless it satisfies these four rules.

  • It must be idempotent. If the compensation itself fails midway and reruns, it must not undo twice. "Set the flag to false" is idempotent; "decrement a counter by one" is not.
  • It must not depend on the forward step having fully completed. Don't assume do finished. The compensation must be safe to call even if do got partway and then failed.
  • It must have an observable completion condition. You should be able to confirm the compensation "took," not guess — re-fetch the flag, re-read the metadata.
  • It must not create a new partial failure itself. If a compensation has multiple side effects, then that compensation is also a Saga.

The fourth rule is the harshest in practice. The compensation for "revert App Store metadata" turns out to be a two-step "update metadata + roll back screenshots."

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Build a Saga orchestrator in TypeScript that converges the dreaded 'step 3 failed but steps 1 and 2 already happened' partial failure, using two distinct strategies — forward recovery and backward compensation
Learn from a real incident running six apps in parallel where an iOS release left AdMob updated but App Store metadata half-applied, plus the four rules a compensating action must satisfy and how to tell reversible operations from irreversible ones
Decide compensation idempotency, where to place the point-of-no-return, and partial-failure detection time (90s down to 8s in my own operation) using real numbers that don't bloat your runtime with over-engineering
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Agents & Manager2026-06-30
When the Android CLI Got 3x Faster and Cut Tokens by ~70%, the Right Move Was More Verification Per Change — Not More Parallelism
Reading that the Android CLI agent runs ~3x faster while using ~70% fewer tokens, my first instinct was to ask how many runs to parallelize. But a faster agent doesn't change how much work ships — it changes where the queue forms. This walks through why, sizes the new bottleneck (review and verification gates) with Little's Law, enforces a WIP cap with a working Python admission controller, and reinvests the freed budget into depth per change — with measured results.
Agents & Manager2026-05-31
Flow Control for Autonomous Agents: Backpressure and Queues That Keep Production Alive
Run several Antigravity agents at once and the problem stops being how smart they are and becomes how little your downstream can absorb. Here is a flow-control design — bounded queue, semaphore, token bucket, backpressure, dead-letter — with TypeScript and real numbers.
Agents & Manager2026-05-30
Build for the Day the Agent Breaks Something: Keeping Blast Radius Small
Once you let an Antigravity agent touch production, the problem stops being how smart it is and becomes how much it wrecks when it slips. Here is a four-layer containment design that shrinks blast radius, with TypeScript and real numbers.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →