Skip to content

fix(gateway): degrade when a provider is down - #5

Open
fabianzimber wants to merge 3 commits into
mainfrom
cursor/gateway-upstream-degrade-3154
Open

fabianzimber wants to merge 3 commits into
mainfrom
cursor/gateway-upstream-degrade-3154

Conversation

@fabianzimber

@fabianzimber fabianzimber commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A stored provider answer is served when FrankerFaceZ, 7TV, BTTV, or IVR fails, including a copy older than the usual stale window.
  • A real provider 404 stays a negative cache. A 404 of a list that always exists stays an error.
  • GET and HEAD /health read only the version binding. No KV, hub, or provider call.
  • Upstream failures log once per provider per minute. A hub that does not accept /api/irc logs the shard and a scrubbed cause.

Changes

  • Backoff or a failed refresh returns the stored copy as STALE instead of 502/503.
  • With nothing stored, the gateway still returns 502. The overlay's direct request uses the same 8s limit, including while the body is read.
  • Provider failure reasons live in UpstreamReason. Cloudflare platform failures go through PlatformError, which drops URLs and query strings.
  • Logs are one JSON object: upstream_unavailable or hub_unavailable, with no channel id.

Testing

  • pnpm typecheck
  • pnpm exec biome ci
  • pnpm test (88 tests)

Deployment notes

  1. Merge to main. Workers Builds runs pnpm run build:cloudflare, then npx wrangler@4 deploy. No new binding or secret.
  2. Open /health on petal.shiftbloom.studio and chat.shiftbloom.studio. Expect { ok: true, version }.

Access / Zero Trust

Not needed. This repo does not define a Cloudflare Access application for either hostname.

If an Access application is later attached to petal.shiftbloom.studio or chat.shiftbloom.studio, it covers /health with the rest of that host. Then:

  1. Add a Bypass or Service Auth policy scoped only to the path /health.
  2. For Service Auth, send CF-Access-Client-Id and CF-Access-Client-Secret from the checker.
  3. Leave the body as { ok: true, version }, with no tokens, channel names, or account data.
  4. Rate-limit that path so a bypass cannot be polled without a bound.
Open in Web Open in Cursor 

A cache miss that times out against FrankerFaceZ or IVR was returned as
502, and the next request during backoff as 503. Serve any copy still
held, keep provider 404s as negative cache, and log upstream failures
apart from Worker faults. Add /health for a check that does not call a
provider.

Co-authored-by: Fabian Zimber <[email protected]>
@cursor
cursor Bot force-pushed the cursor/gateway-upstream-degrade-3154 branch from 7a17960 to 9459372 Compare November 13, 2026 22:55

@fabianzimber fabianzimber left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deployment notes way too large and no proper format. please include also steps regarding access safety for cloudflare one zto if needed regarding health checkpoint from clientside. please also pay more attention to using clean code.
https://labs42io.github.io/clean-code-typescript/#comments

Comment thread test/worker/gateway/gateway.test.ts Resolved
Comment thread src/worker/api.ts Resolved
Comment thread src/worker/gateway/gateway.ts Resolved
Comment thread src/worker/gateway/gateway.ts Resolved
Comment thread src/lib/chat/gateway.ts Resolved
cursoragent and others added 2 commits November 13, 2026 23:03
One helper writes Worker log lines. Provider failure reasons are a
const, and the 7TV test id prefix is named.

Co-authored-by: Fabian Zimber <[email protected]>
Name upstream reasons, log Cloudflare platform failures through one
error type, and let the cache path read as early returns.

Co-authored-by: Fabian Zimber <[email protected]>
@cursor

cursor Bot commented Nov 13, 2026

Copy link
Copy Markdown

Rewrote the description into Summary, Changes, Testing, Deployment notes, and Access / Zero Trust. No Access application is defined in this repo; the Access section says what to add if one is attached later. The degrade path is named functions and constants, without the narrative comments.

This branch has not been deployed

No deployments
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.

2 participants