Connect the Cloudflare Worker so the brain runs even when this tab is closed. One-time setup, free tier covers everything.
๐ฏ What this solves
The browser brain only runs while a tab is open. Close Chrome โ brain stops. Re-open โ brain starts from scratch (only learns from new captures going forward).
The worker fixes this:
Runs 24/7 on Cloudflare's edge โ every minute, polls Finnhub, runs capture/resolve/train, persists state in KV.
Historical bootstrap works โ no CORS limits server-side. Finnhub's /stock/candle works from the worker even though it's blocked from your browser.
wrangler kv:namespace create BRAIN_KV
# Output gives you an `id = "..."` โ copy that
# Paste it into wrangler.toml (replace REPLACE_WITH_KV_ID_FROM_WRANGLER_OUTPUT)
4. Set secrets
wrangler secret put FINNHUB_API_KEY
# (paste your Finnhub key when prompted โ same one you use in settings.html)
wrangler secret put ADMIN_TOKEN
# (make up a random long string โ used to trigger bootstrap)
5. Deploy
wrangler deploy
# Returns a URL like:
# https://bpleone-brain-worker.YOUR-SUBDOMAIN.workers.dev
# Copy that URL.
6. Trigger the initial bootstrap
Pulls 250 days of Yahoo Finance daily bars across 71 symbols, computes rich features (RSI, ATR, momentum, range position, SMA distance), and trains the model for 5 epochs. Takes 30-90 seconds depending on Cloudflare plan (Pro = 30s CPU/req).
curl -X POST -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
https://bpleone-brain-worker.YOUR-SUBDOMAIN.workers.dev/brain/bootstrap
7. Connect this browser to the worker
Paste the worker URL below and click connect. From this moment, every page reads brain state from the worker.
๐ก Live worker status
Connected
โ
Last tick
โ
Journal (server)
โ
Model n_trained
โ
Auto-refreshes every 15 seconds. Expected worker version: pass-301.
๐ก๏ธ Scale + abuse protection โ built in (pass 296โ297)
Legitimate load (pass 296): per-colo KV read caching, stale-while-revalidate quotes, sampled analytics writes, short response caches; the browser gates polling to visible tabs on a jittered 30โ45s cadence. Thousands of real tabs behave like dozens โ cost scales with attention, not open tabs.
Malicious load (pass 297): a per-IP rate limit is built into the worker itself โ GET /brain/* is capped at ~12 req/s per IP (in-memory sliding window, zero KV writes, so it doesn't undo the caching above). This is the right layer because the brain is served from *.workers.dev, which is not behind the zone WAF โ a dashboard rate-limit rule wouldn't even apply. Isolates are per-colo, so a single abusive IP is stopped cold; a distributed botnet is handled by Cloudflare's always-on L3/L4 DDoS protection underneath. Nothing to configure.
Only remaining checklist item: confirm the Worker is on the Paid plan ($5/mo) before a large traffic spike โ the free tier's 100k requests/day is fine for a soft launch but a worst-case fully-visible fleet can exceed it.
๐ Disconnect
Falls back to browser-only brain. Worker keeps running in Cloudflare โ you just stop reading from it.