◉ANTIGRAVITY LABJP
Articles/Agents & Manager
◈ Agents & Manager/2026-07-06Advanced

Never Miss a Managed Agent Completion: Pairing a Serverless Receiver with Polling Reconciliation

A cloud Managed Agent can finish while you are not watching, and the webhook that should tell you can quietly fail. Here is a serverless receiver on Cloudflare Workers paired with polling reconciliation, and a state machine that recovers every completion within minutes.

antigravity458managed-agents3cloudflare-workers9webhook3idempotency11

✦ Premium Article

The week Managed Agents landed in public preview on the Gemini API, my first reaction was not excitement but a small worry. A long-running job on the cloud finishes while I am not looking at the screen. So how, exactly, does that fact of "it finished" travel back to me?

As an indie developer who runs unattended work across several sites on Cloudflare Workers, this was not somebody else's problem. Because I have decided not to keep an always-on server, my completion receiver has to be serverless too. And push-style notifications — webhooks — are convenient, but they fail quietly. Not even noticing that one was lost is the scariest part.

What follows builds the receiver-side design for never missing a Managed Agent completion, together with code that actually runs. The core idea is to pair push (webhook) and pull (polling) from the start, so that even if one channel goes silent, the final state still converges.

Where "it finished but I never knew" actually happens

Let me break down the failure modes concretely. The path from a cloud Managed Agent to your receiver has more gaps than you might expect.

The first is plain delivery loss. Your receiver returned a 5xx for a moment, or it was down for a few hundred milliseconds during a deploy, or the network gave up on the delivery. Even platforms that promise at-least-once have a retry cap. Exceed it, and the notification vanishes silently.

The second is duplicate delivery. If your receiver succeeds but the connection drops just before it returns a response, the sender concludes "that failed" and resends. You end up receiving the same completion event twice. If you naively run a side effect like a charge or a file publish twice, real damage follows.

The third is reordering. Two transition notifications, running then succeeded, can arrive in the opposite order. When network paths differ, overtaking is ordinary. Write "adopt the state of the last notification that arrived" and a finished job rolls back to running.

The fourth is the race that actually bit me hardest. You start a job, and the completion webhook arrives before you have written its job_id to KV. When the cloud side is fast, "it finished" arrives before your own "record the start" write completes. The receiver sees an unknown job_id and discards it as "a job I don't know." This is neither load nor an outage, just an ordering problem, which makes it hard to reproduce and hard to explain.

Fixing these one bug at a time turns into a pile of patches. I have come to believe it is more robust, in the end, to duplicate the path itself so the structure becomes "as long as one of them carries the truth, we're fine."

The premise: make push and pull two wheels from the start

Prepare two receiving paths.

One is the push path. The instant the Managed Agent finishes, it fires a webhook, and your Cloudflare Worker receives it. Fast, but as noted, it drops.

The other is the pull path. You periodically ask the cloud, "is that job done yet?" and reconcile the state. Slow, but it does not drop. As long as you keep asking, you will eventually read the correct state.

The place where these two merge is the job record you keep in KV. Whether via push or pull, both aim at the same state transition on the same record. Which one wins when they conflict is decided by the state machine's rules. The key is to preserve monotonicity: adopt "the more advanced state," not "the one that arrived last."

Put differently, the webhook is a fast shortcut, not the sole truth. Polling holds the ultimate guarantee of truth, and the webhook is positioned as an optimization that makes that truth arrive sooner. Decide this division of roles up front, and the implementation that follows will not wobble.

✦

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
✦You can eliminate the fragility of a cloud Managed Agent finishing in the background without its notification reaching you, by pairing a webhook receiver with polling reconciliation
✦You'll build an idempotent receiver on Cloudflare Workers and KV that survives duplicate deliveries, out-of-order events, and the race where a callback arrives before your job record is committed
✦As an indie developer with no always-on server, you'll design a state machine that reliably recovers unattended job completions within minutes
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 $15 for lifetime access
View Membership →

Related Articles

◈ Agents & Manager2026-05-26
Antigravity Multi-Agent State Tiers — A Three-Layer Design with Ephemeral, Journal, and Canonical
Before your Antigravity Background Agents and Sub-agents start mixing up their memory, split agent state into three lifetimes — ephemeral, journal, canonical — and map each to the right Cloudflare store. Includes a TypeScript approval gate for write-back, and what changed when headless runs stopped silently auto-approving.
◈ Agents & Manager2026-09-04
Snapshot Your Agents' Effective Scope So You Notice the Day a Default Changes
Antigravity 1.1.25 made Markdown-defined custom agents inherit the surrounding skills, rules, and subagents by default. Here is the snapshot-and-diff routine I now use to check whether an agent I meant to keep narrow quietly got wider after an update.
◈ Agents & Manager2026-08-21
Why I Check Description Overlap Before Turning On inheritCustomizations
CLI 1.1.14 collapsed markdown agent inheritance into a single inheritCustomizations switch. Here is what happened when I actually inventoried the 47 skills in my workspace and decided the switch on description overlap rather than on context size.
📚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