To recover an agent publishing pipeline when external CI never registers a build check, verify that the merge commit reached the target branch and push an empty rescue commit to trigger a fresh build. This workflow replaces failure-only error handlers with an ancestry check and an arrival timeout, preventing orchestrators from hanging indefinitely on dropped webhooks or looping on closed preview branches.
The workflow at a glance
flowchart LR
M[Merge preview to main] --> S[Record merge SHA]
S --> W[Wait for build check registration]
W --> C{Check registered within timeout?}
C -- yes --> B{Check status}
B -- success --> D[Mark post published]
B -- failed --> R[Inspect failure]
C -- no --> A{Is merge SHA on main?}
A -- yes --> E[Push empty rescue commit]
E --> W
When to use it
- Git-driven publishing pipelines where external platforms, such as Cloudflare Workers Builds or Cloudflare Pages, deploy production code from merge commits.
- Agent workflows that poll GitHub check runs or commit statuses before marking content live.
- Pipelines where webhook drops or platform hiccups leave orchestrators stalled without a failure signal.
Skip it when deployments run synchronously inside the pipeline runner itself, where commands exit with immediate success or failure codes.
Step 1: Capture the merge commit
- Do: When the agent finishes preview verification and merges into
main, capture the resulting merge commit SHA ($MERGE_SHA) immediately in the pipeline state. - Output: A recorded
$MERGE_SHAstring passed to your deployment watchdog.
Step 2: Poll for check registration with a timeout
- Do: Poll the GitHub Check Runs API for
$MERGE_SHAon a fixed interval (such as every 15 seconds) looking for the deployment check, such asWorkers Builds. Set a strict registration timeout between 90 and 180 seconds. - Output: A resolved status:
success,failed, ormissingif the registration deadline passes without an event.
Step 3: Verify target branch ancestry
- Do: If the check status is
missingorfailed, do not attempt to rerun the preview branch. Instead, verify that the recorded SHA is an ancestor of the production branch usinggit merge-base --is-ancestor "$MERGE_SHA" origin/main. - Output: Cryptographic confirmation that the code is merged into
mainand that recovery must happen onmain.
Step 4: Push an empty rescue commit
- Do: Check out
main, pull the latest ref, and create an empty commit to prompt the external builder into picking up the branch:
Extract the new commit SHA and update the pipeline watchdog to monitor the rescue commit instead.git commit --allow-empty -m "chore(ci): kick stalled build for ${MERGE_SHA:0:7} [agent-rescue]" git push origin main - Output: A fresh push event on
mainthat forces CI to register and run the build.
Why our publish flow stalled
Our publish pipeline merges an approved preview into main, then waits for Cloudflare's production build event to mark the post published. During one run, Cloudflare silently dropped the build for the merge commit: no Workers Builds check registered on GitHub at all.
Our rescue button was hard-coded to check only for explicit build failures (status == "failure"). Because no failure had arrived, pressing rescue fell back to re-running the preview branch. GitHub Actions skipped the preview run because the branch was already merged, trapping the orchestrator in an endless dead end.
Keying the rescue on whether $MERGE_SHA exists on main rather than waiting for an explicit failure signal resolved the loop. As explored in AI Agent Oversight: Why Passive Approval Fails Systems, automated systems fail when they passively wait for signals that third-party services drop under load.
Variations
- Cloudflare Deploy Hooks: If branch protection rules prohibit automated pushes to
main, trigger production builds out of band with an HTTP POST to a Workers Builds Deploy Hook or Cloudflare Pages Deploy Hook. - Direct CLI deployment: Eliminate third-party webhook flakiness altogether by having the CI runner build assets locally and deploy directly via Wrangler.
- Autonomous agent runners: For agent pipelines that execute code directly inside GitHub Actions, follow How to Run Coding Agents in CI with gh-aw and Aider to isolate push credentials.
Frequently asked questions
Why did the build never start in the first place?
External platforms occasionally fail to receive or parse GitHub webhook payloads during API latency spikes or rate limits. When Cloudflare never receives the push event, it never registers a check run on GitHub. Because the commit registers neither success nor failure, polling loops that lack a registration deadline hang forever.
Why not re-run the preview branch when a build goes missing?
Once a preview branch is merged into main, re-triggering CI on that branch produces a preview environment build or exits as a no-op. It cannot deploy production assets to your main domain. To deploy changes that have landed on main, the build must execute against main.
How do I prevent rescue commits from triggering infinite loops?
Add a clear marker such as [agent-rescue] or [skip ci] to the commit message. Configure your agent orchestrator to ignore commits containing that tag, and ensure your rescue script verifies that a previous rescue run is not already pending before pushing a new empty commit.