Bridge A: whitespace-heartbeat on /api/agent/ask to survive Cloudflare's 120s cap

↗ view on GitHub · emileriksenkeev · 2026-07-16 · 600e5283

Syd's agent loop runs 1-2 min headless, but api-legal.rxventures.co is fronted by
Cloudflare, whose 120s edge Proxy-Read-Timeout kills the connection with Error 524
before Syd finishes - Bry's ask_syd hop then reports "Syd answered 524". The zone is
Free-plan and api-legal is a cloudflared tunnel, so the timeout can't be raised and
grey-clouding isn't available.

Cloudflare resets that read timeout on every byte from the origin, so trickle a
whitespace keepalive to the client while the loop runs, then send the JSON at the end.
JSON.parse ignores leading whitespace, so Bry's `await res.json()` parses it unchanged
- no Finance OS change needed. Lazy by design: only streams if the work passes ~90s,
so fast responses and errors keep their normal status codes. Calls res.flush() after
each write because the app gzips JSON (compression middleware would otherwise buffer
the keepalive, same reason the SSE path skips compression).

Keeps the cloudflared tunnel and CF WAF intact - no droplet exposure, no plan upgrade.
Deploy: git pull && npm --prefix backend run build && restart node dist/index.js.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Repository emileriksenkeev/sydOS
Author emileriksenkeev <emil@keev.co>
Authored
Parents 3ffb886a
Stats 2 files changed , +111 , -3
Part of Agent-to-agent bridge to Bry (Finance OS)

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-600e5283.md from inside the repo you want the change in.

⬇ Download capture-commit-600e5283.md