agent-zero icon indicating copy to clipboard operation
agent-zero copied to clipboard

Remote Control Cloudflare links often fail on first try: URL is reported before the tunnel hostname is reachable

Open bdunn77 opened this issue 2 months ago • 0 comments

Summary

About half the time, a freshly created Remote Control link (Cloudflare quick tunnel) does not open on the first try. Creating the link again once or twice produces a working URL. This is not random flakiness in Cloudflare itself: Agent Zero reports the URL before the tunnel hostname is actually resolvable, so the link that is shown is frequently not reachable yet, and the client resolver can negatively cache the fresh hostname.

Steps to reproduce

  1. Open Settings -> Remote Control, provider Cloudflare Tunnel, click create.
  2. The UI shows a https://<random>.trycloudflare.com link as soon as it is printed by cloudflared.
  3. Open the link immediately. It often fails to load (DNS not found / connection error).
  4. Retry after a while: sometimes it works, sometimes the same URL keeps failing and a new link is required.

Root cause

helpers/tunnel_common.py -> FlaredanticTunnelHelper.start() reports the URL as soon as the underlying flaredantic tunnel exposes tunnel_url, with no reachability check:

self.tunnel.start()
self.tunnel_url = getattr(self.tunnel, "tunnel_url", None)
if self.tunnel_url:
    self.notify_url_ready(self.label, self.tunnel_url)  # reported immediately

flaredantic parses the URL straight out of the cloudflared stdout banner, which cloudflared itself flags as "it may take some time to be reachable".

Measured evidence (this container, v2.12, cloudflared 2026.9.1)

End-to-end through Agent Zero's own tunnel API (POST / on the tunnel service, port 55520, provider cloudflared):

create() returned after 3.7s success=True url=https://integer-...-deny.trycloudflare.com
  t+  3.8s dns=NXDOMAIN
  t+  5.9s dns=NXDOMAIN
  t+  7.9s dns=NXDOMAIN
  t+ 10.3s reachable (302 -> /login)

cloudflared log ordering confirms the gap:

20:43:27 INF | Your quick Tunnel has been created! Visit it at (it may take some time to be reachable):
20:43:27 INF | https://salvador-...-flower.trycloudflare.com
20:43:27 INF Registered tunnel connection ... protocol=http2

The banner URL is what Agent Zero reports, several seconds before the edge serves it.

Why a new link is often required instead of just waiting

trycloudflare.com SOA minimum is 1800 seconds:

SOA: kevin.ns.cloudflare.com. dns.cloudflare.com. 2415250093 10000 2400 604800 1800

A resolver that queries the hostname during the NXDOMAIN window can cache the negative answer, so the same fresh hostname keeps failing for that resolver long after the tunnel becomes healthy. Generating a new hostname sidesteps the cached negative answer, which matches the reported "make a new link once or twice" behaviour.

Impact

Affects all users of the Cloudflare (and generally flaredantic-backed) Remote Control provider: the UI declares "Remote Control is ready" and shows a QR code for a URL that is not yet reachable, and the first attempt frequently fails.

Notes on other candidates (checked, not root cause)

The Docker resolver (nameserver 192.168.65.7) is slower than public resolvers, but public DoH (1.1.1.1, dns.google) shows the same NXDOMAIN window for a fresh hostname, so this is not Docker-only. Tunnel service health and HTTP responses on the local tunnel API were fast (~2ms), so the 0.35s timeout in origin lookup is not the cause here.

Suggested fix

Wait for the tunnel URL to actually resolve/answer before announcing it as ready (with a bounded timeout and a clear 'pending' state when it does not answer in time). A pull request implementing this is linked below.


Pull request with the fix: https://github.com/agent0ai/agent-zero/pull/1905

bdunn77 avatar Sep 18 '26 21:09 bdunn77