Skip to content

fix(link): proxy_no_first_frame resilience — per-slot backoff + request-leg republish - #3704

Merged
tlgimenes merged 1 commit into
mainfrom
tlgimenes/proxy-no-first-frame-debug
Jun 8, 2026
Merged

tlgimenes merged 1 commit into
mainfrom
tlgimenes/proxy-no-first-frame-debug

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes dropped dispatches on the pull proxy channel when the daemon has transient subscriber gaps.

Root cause:

  • Shared errorStreak across proxy-poller concurrency slots: one systemic error (Cloudflare 520 on the 28s long-poll) backs off BOTH slots → 1–30s zero-subscriber window.
  • Fire-and-forget core-NATS request leg with no buffer: publish into a gap is silently lost.
  • Claim re-armed only by /work (not /proxy), so presence-loss fail-fast can't catch a dead proxy-poll while the link looks "connected."

Result: chat messages fail with [remoteDispatch] proxy_no_first_frame: no reply frame within first-frame timeout because the cluster's RequestFrame publish lands in a gap and is dropped. Cluster waits 15s with no reply, fails fast instead of hanging.

Changes

PART #1 — Per-slot backoff

apps/mesh/src/link-daemon/proxy-poller.ts

  • Moved errorStreak from shared scheduler scope into each slot() closure.
  • Each slot now backs off only its OWN consecutive failures; one slot recovering and re-polling immediately while another retries keeps ≥1 live subscriber through intermittent errors.
  • TDD: new test "backs off per-slot" asserts seenStreaks=[0,0] not [0,1] under concurrency:2 with both slots failing.

PART #2 — Request-leg tolerance

apps/mesh/src/api/routes/decopilot/link-proxy-routes.ts

  • Added bounded republish of the RequestFrame every 1s (injectable republishIntervalMs, default=1000, 0=off) until first reply frame arrives.
  • Republish stops at first reply/presence-loss/abort/first-frame-timeout (never outlives dispatch, bounded by 15s window).

apps/mesh/src/link-daemon/proxy-abort-registry.ts + apps/mesh/src/link-daemon/proxy-poller.ts

  • register(reqId) now returns AbortController | null — null if reqId already in-flight (dedup for republish duplicates).
  • handleProxyRequest bails on null before try/finally, so duplicate copy is skipped without unregistering the original's controller.
  • TDD: new registry test "idempotent-delivery dedup" asserts second register returns null, id freed after unregister.
  • TDD: new cluster test "re-publishes...then stops" asserts frame is published >1× before reply, then republishing ceases.

Test Plan

  • bun test apps/mesh/src/link-daemon/proxy-abort-registry.test.ts — 7 pass (including new dedup test)
  • bun test apps/mesh/src/link-daemon/proxy-poller.test.ts — 14 pass (including new per-slot test)
  • bun test apps/mesh/src/api/routes/decopilot/link-proxy-routes.test.ts — 16 pass (including new republish test)
  • Broader suite: 110 pass across link-daemon + link routes
  • bun run fmt — clean (no fixes)
  • bun run check — all workspaces exit 0
  • bun run lint — 0 warnings / 0 errors

Notes

⚠️ Daemon shipping caveat: proxy-abort-registry.ts marked "SHIPPED DAEMON — needs human review before merge." The change is small and well-tested (7 existing + 1 new test), but shipped in the decocms CLI binary, so users must update their deco link for Part A's dedup to take effect. This is safe (the change is purely defensive — returns null instead of a controller) but worth careful review.

Remaining work:

  • Chore: migrate chat and agent-settings #3: Tie proxy-readiness to the claim. The doc at link-proxy-routes.ts:407 claims work/control/proxy all re-arm the 60s claim TTL, but only /work does — a real doc-vs-code defect. Once Chore: migrate chat and agent-settings #3 is done, a dead proxy-poll surfaces a clean link_unavailable instead of a 15s hang.
  • Infra: Fix the Cloudflare 520 itself (long-poll idle timeout, eks-serverless pod churn, or HTTP/2 GOAWAY on drain). Cluster-side retry (this PR) buys time, but the 520 is the trigger.
  • Dedup pattern: The reqId dedup pattern in this PR may apply to run-abort-registry in thread-gate-workflow.ts if similar republish lands there.

🤖 Generated with Claude Code


Summary by cubic

Makes the link proxy resilient to transient subscriber gaps by adding per-slot backoff in the daemon and bounded request-leg republishing with reqId dedup. Prevents dropped request publishes that triggered proxy_no_first_frame timeouts.

  • Bug Fixes

    • Per-slot backoff: each poller slot tracks its own error streak, so one slot can re-poll while another retries.
    • Request-leg tolerance: republishes the RequestFrame every 1s until the first reply, then stops; configurable via republishIntervalMs (0 disables).
    • Dedup on the daemon: register(reqId) returns AbortController | null; duplicates are skipped to avoid double execution.
  • Migration

    • Update the shipped daemon in the decocms CLI (update deco link) so the dedup change takes effect.

Written for commit a4bac51. Summary will update on new commits.

Review in cubic

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

…st-leg republish (TDD, all gates green)

Fixes #3698-follow: cluster-daemon proxy channel now tolerant of transient subscriber gaps.

PART #1 — Per-slot backoff (proxy-poller.ts)
- Root cause: shared errorStreak across proxy concurrency slots. One systemic error (e.g.
  Cloudflare 520 on the 28s long-poll) backed off BOTH slots → 1–30s zero-subscriber gap
  → dispatch publish to links.proxy.req.<userSub> dropped → proxy_no_first_frame 15s later.
- Fix: move errorStreak into each slot(). Each slot backs off only its own failures; one
  recovering slot re-polls immediately while another retries, keeping ≥1 live subscriber
  through intermittent errors.
- Test: new "per-slot backoff" test with concurrency:2 asserts seenStreaks=[0,0] not [0,1].

PART #2 — Request-leg tolerance (link-proxy-routes.ts, proxy-poller.ts)
- Root cause: fire-and-forget core-NATS publish with no buffer. A single blind publish
  is lost if it lands in a daemon poll/backoff gap; no retry, no durability.
- Fix: cluster-side bounded republish + daemon reqId dedup.
  (A) proxy-abort-registry.register() now returns AbortController|null; null if reqId
      already in-flight (duplicate delivery dedup). handleProxyRequest bails on null
      before try/finally, so duplicate copy doesn't unregister the original.
  (B) createProxyDispatch republishes RequestFrame every 1s (injectable republishIntervalMs,
      0=off) until first reply frame. Stopped by markFirstFrame/cleanup/first-frame-timeout
      (never outlives dispatch, bounded by 15s window). Daemon dedup makes double-execution
      impossible (emits first frame only after upstream responds).
- Tests: registry dedup test + "re-publishes...then stops" cluster test.

Verification: 36 affected-test pass, 110 link tests pass, fmt/lint/typecheck clean.

⚠️ Daemon caveat: proxy-abort-registry.ts marked "SHIPPED DAEMON — needs human review
before merge." Small change, well-tested, but shipped in `decocms` CLI.

Remaining: #3 tie proxy-readiness to claim (doc-vs-code defect), infra fix for CF 520,
plus this dedup safety pattern may apply elsewhere (runAbortRegistry in thread-gate-workflow).

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
@tlgimenes
tlgimenes force-pushed the tlgimenes/proxy-no-first-frame-debug branch from a4bac51 to e49aa9e Compare June 8, 2026 13:58
@tlgimenes
tlgimenes merged commit 2ce7b1f into main Jun 8, 2026
17 checks passed
@tlgimenes
tlgimenes deleted the tlgimenes/proxy-no-first-frame-debug branch June 8, 2026 14:30
decocms Bot pushed a commit that referenced this pull request Jun 8, 2026
PR: #3704 fix(link): proxy_no_first_frame resilience — per-slot backoff + request-leg republish
Bump type: patch

- decocms (apps/mesh/package.json): 2.398.1 -> 2.398.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant