Skip to content

Move the settings service into the Cloudflare Worker - #75

Draft
wafo wants to merge 4 commits into
masterfrom
feat/73-worker-settings-proxy
Draft

wafo wants to merge 4 commits into
masterfrom
feat/73-worker-settings-proxy

Conversation

@wafo

@wafo wafo commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #73. Refs #74: a fresh browser now defaults to the current active generator version.

Staging: https://staging.hashfrog-tracker.com runs this branch (3439f58).

Summary

The settings service moves out of the separate Koa + Redis backend and into the Worker that already serves the site. See ADR 0001.

sequenceDiagram
    participant Tracker
    participant Worker as Worker (/api/settings/string)
    participant Cache as Cloudflare cache
    participant Generator as ootrandomizer.com
    Tracker->>Worker: GET ?version&settingsString
    Worker->>Cache: match v1:version+settingsString
    alt HIT
        Cache-->>Worker: decoded settings
    else MISS (rate limited, 20/min per IP)
        Worker->>Generator: /settings/get (8s timeout)
        Generator-->>Worker: decoded settings, or a traceback
        Worker->>Cache: store successful decodes for 7 days
    end
    Worker-->>Tracker: {settings} + X-Cache, or JSON 400/429/502/504
Loading
 worker/
+├── index.js            # settings service + hand-off to static assets
+└── index.test.mjs      # node --test, at fetch(request, env, ctx)
 src/
 ├── hooks/useLogicInitialization.js   # calls /api, per-status messages
 ├── scenes/TrackerChecks.js           # no generic hint for decode errors
 ├── context/trackerContext.js         # fresh browser → current active version
 └── versions/
+    └── dev-branches.js               # dev branch prefixes, shared with the Worker
 wrangler.jsonc   # main, run_worker_first /api/*, rate limiter, logs, env.staging
 package.json     # dev, preview, worker, deploy:staging, test:worker
-REACT_APP_API_URL

Also included: AGENTS.md and docs/agents/ (agent skills setup), GLOSSARY.md, and ADR 0001.

Evidence

  • Before: tracker → api.hashfrog-tracker.com (a server and Redis we run). Locally, check tracking is broken unless REACT_APP_API_URL points at production. Every failure says "check your settings string".
    After: on staging, against the real generator:
    9.1.0  new string    200  X-Cache: MISS  0.51s
    9.1.0  same string   200  X-Cache: HIT   0.12s
    9.1.0 string as 9.0.0  400  invalid_settings_string (traceback only in the logs)
    malformed version    400  invalid_request
    /api/nope           404     POST → 405     /tracker/checks → 200
    
  • Tracker in a browser (Brave + Playwright), locally and on staging:
    fresh browser + pasted string → version 9.1.0, check tracking loads
    mangled string, or wrong generator version → "The generator could not decode this settings string for this generator version. Check …"
    generator down (502)          → "The generator is having trouble right now. Try again in a moment."
    rate limited (429)            → "… Wait a minute and try again."
    
  • Tests: npm run test:worker 35/35 and npm test 243/243. Lint and build pass, and CI now runs the Worker tests.

How to test on staging

  • Launch check tracking with a preset on https://staging.hashfrog-tracker.com; it loads.
  • Load the same settings string twice; DevTools shows X-Cache: MISS, then HIT.
  • Mangle the settings string; the error blames the settings string or generator version.
  • Watch npx wrangler tail --env staging while testing; there is one cache_miss line per miss, and no full settings strings.

To redeploy staging after new commits, run npm run deploy:staging. See the README for details.

Merge Danger

Door: two-way

The old backend keeps running for 2 weeks after the deploy. Rolling back means reverting this PR or running wrangler rollback. Nothing is migrated or deleted.

Blast Radius: check-tracking

If the Worker misbehaves, check tracking fails to load. The basic tracker without check tracking doesn't touch /api. Watch for:

  • Generator latency: right after staging first went up, the generator took more than 8s for a few minutes and the Worker returned 504. A follow-up run of 21 misses across every preset and generator version took 0.5–1.7s, the same as calling the generator directly. If "status":504 shows up in Workers Logs, raise the Worker's timeout (the client allows 10s).
  • Old browser tabs keep calling api.hashfrog-tracker.com until they reload, which is why the old API stays up.

After merge

  1. Check X-Cache and Workers Logs on https://hashfrog-tracker.com.
  2. Two weeks later, decommission:
    1. Delete the REACT_APP_API_URL Cloudflare build variable.
    2. Stop the backend container and Redis.
    3. Delete the api.hashfrog-tracker.com DNS record.
    4. Archive hashfrog_tracker_backend with a pointer to ADR 0001.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GxexzDRe9BU7mHmH5mLphe

wafo and others added 4 commits November 2, 2026 19:17
Configure the engineering skills (GitHub issue tracker, default triage
labels, single-context domain docs), start the domain glossary, and
record ADR 0001: settings decoding moves from the Koa/Redis backend into
the Cloudflare Worker, cached per data center. Spec: #73.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxexzDRe9BU7mHmH5mLphe
The Worker that serves the SPA now answers GET /api/settings/string:
it validates the generator version and settings string, asks the
generator, caches successful decodes in the Cloudflare cache for a week,
rate-limits cache misses per IP, and translates generator failures into
JSON errors (400/429/502/504) without leaking tracebacks.

The frontend calls /api on its own origin, so REACT_APP_API_URL is gone,
and tells a bad settings string apart from a service problem.

npm run dev starts the dev server and the Worker together; npm run
preview serves the production build through the Worker. Worker tests
run with node --test in CI. Dev branch prefixes move to their own
module so the Worker and the frontend share them.

Closes #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxexzDRe9BU7mHmH5mLphe
- Log every cache miss once, with its status; dedupe the generator
  failure paths; fix Prettier formatting in the Worker.
- Blame the generator (not "the settings service") for its own outages,
  and mention the generator version in the 400 message.
- Hide the error page's generic hint for settings decode errors, which
  now carry their own advice; logic-file errors keep it.
- Default a fresh browser to the generator's current active version
  instead of the 9.0.0 fallback (part of #74).
- Add "settings service" to the glossary.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxexzDRe9BU7mHmH5mLphe
`npm run deploy:staging` builds and deploys to hashfrog-tracker-staging
at staging.hashfrog-tracker.com, with its own rate limiter and its own
settings cache namespace (staging shares the zone's cache with
production). README documents the manual deploy and who can run it.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxexzDRe9BU7mHmH5mLphe
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
hashfrog-tracker 3439f58 Commit Preview URL

Branch Preview URL
Nov 03 2026, 05:11 AM

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.

Move settings decoding from the Koa/Redis backend into the Cloudflare Worker

1 participant