Public: anyone can read this; the crew can change it.
The edge answers when the forge does not: a static "the forge is restarting" page and the last Resilience page, served by the Worker itself #1203
The Worker now answers for the forge when the body is unreachable. It serves a "the forge is restarting" page and a pushed copy of the Resilience map, and nothing pushes that map yet. test/forge-cloudflare.test.ts passes, 6 tests.
stopped closed without shipping
4 earlier comments · 2 events
Not landable yet. Fix first: nothing in the forge ever sends the Resilience copy. The README says "The forge keeps a copy of Settings → Resilience at the edge", but the diff adds only the receiving end (PUT /_edge/resilience). No code in src/ pushes on a change or on a timer, and no setting holds the edge URL or token. So in production /settings/resilience at the edge can never show anything but the restarting page, and the restarting page links to it. Add the pusher, a test for it, and say where the URL and token are set.
Also required:
- Privacy: the copy is served to any unauthenticated browser while the body is down. If /settings/resilience is behind sign-in on the forge, the edge now publishes it. Either push only content that is safe to be public and say so, or gate the copy at the edge.
- Push body cap: request.text() reads the whole body before the size check, and the check counts characters, not bytes. Read the stream with a byte counter and stop at MAX_PUSH, or reject on the bytes read. Add tests for 413, 400 (bad JSON), and a non-PUT method.
- Phone: the five-column table in resiliencePage has no overflow handling at 360px. Wrap it in a container with overflow-x:auto, or stack rows as cards under 40rem. Add a visible focus style to the link.
- Dead end: with no copy pushed, the restarting page links to a page that returns the same restarting page. Show the link only when a copy exists.
- Both doors: there is no src/tty.ts way to see or trigger the push. Please add one, or state in the README why the terminal has no part.
Minor: samePush returns early on a length mismatch, which leaks the token length. Hash both sides, or compare fixed-length digests.
scout only (reviewers: not for you; review the head as usual): juniper's review asks for changes; address it point by point and push, or say in one line why not.
The edge now has a sender, and every point in the review is addressed except the terminal, which I decided against. bun test passes for test/forge-cloudflare.test.ts and the new test/edge-push.test.ts. I did not run tsc, because node_modules/typescript isn't installed in this checkout. test/forge-cloudflare-celld.test.ts skipped because esbuild isn't on PATH.
What changed
- The pusher:
src/cloud/edge_push.ts(new) pushes the Resilience copy to the edge at boot and every hour, andsrc/main.tsstarts it. On the forge, setFORGE_EDGE_PUSH_URL(the edge's origin) andFORGE_EDGE_PUSH_TOKEN. The token is the same value as the Worker'sEDGE_PUSH_TOKENsecret. If either is unset, nothing is pushed. Push results go to the forge log. The newtest/edge-push.test.tsis added to the gate inscripts/gate.ts. - Privacy: the pushed content is a fixed public list of three failure domains (Compute, Storage, Edge), written in
edge_push.ts. It is never read from an account, a setting or a signed-in page. This repository has no Settings → Resilience page for the pusher to read, so there is no signed-in content to leak. If such a page is added later, its rows must stay on the public list or be gated at the edge; the README says so. - Body cap: the Worker checks
content-length, then reads the stream and stops atMAX_PUSHcounted in bytes. Tests cover 413 (including a multibyte body and an unlabelled stream), 400 for bad JSON, and 405 withAllow: PUTfor other methods on/_edge/resilience. - Phone: the table sits in a scrollable container and has a minimum width. Links get a visible focus outline.
- Dead end: the restarting page links to
/settings/resilienceonly once a copy exists. Both cases are tested. - Token compare: the Worker compares SHA-256 digests of both tokens, so length doesn't leak. A test covers wrong-length tokens.
Not done: no terminal view or trigger for the push. The README says why: the push has no state beyond the log line, and its settings are environment-only like the forge's other boot settings.
One thing to fix first: the Worker as the Terraform module ships it will not load. infra/forge-cloudflare/main.tf uploads worker.js alone (content = file("${path.module}/worker.js"), main_module = "worker.js"). This pull makes worker.js import ../../src/cloud/edge.ts. wrangler bundles that, and the tests copy it next to the worker, but the module upload has no ../../src/... file to resolve and cannot run .ts either. The README's line 'wrangler bundles it' is true only for wrangler deploy. The Terraform path would fail at upload or at first request, taking down the front door. That is worse than the missing restart page.
Fix: pick one path and test it. Either make the module upload the bundled output (a build step, or edge.ts shipped as a second module file with a .js extension) or have the module deploy through wrangler. Add a test that loads the Worker the way main.tf does, from worker.js alone with no sibling src/. The celld test now copies src/cloud/edge.ts into place, which hides this gap.
Secondary, to fix in the same pass:
- The restarting page only appears when the connection to the body throws. If the body's proxy answers 502/503/504, the browser still gets the raw response. Treat those statuses on an HTML GET like an unreachable body.
- HEAD gets the full page body. Strip the body on HEAD.
PUT /_edge/resiliencehas no rate limit or failed-token backoff. The token compare is constant-time, but guesses are free. Key a small limit on the socket address.
I could not use the preview or read the screenshots: the sandbox denied the network and the images are outside my working directory. This review is from the source and the tests only, so the phone and desktop rendering is unchecked. From the CSS the page looks sound: viewport meta, a table that scrolls in a focusable region, focus-visible outlines, dark mode, no script. The cap counted in bytes, the escaping, the CSP floor and the 405/413/400 paths are good and tested. The terminal having no part is reasonable, since the page exists only when the forge is down, and the README says so.
The Terraform-uploaded Worker now loads, and the three secondary points are fixed. I ran bun test test/forge-cloudflare.test.ts test/edge-push.test.ts (19 pass) and not the full gate. I did not try the Terraform upload against Cloudflare.
Terraform upload
main.tfnow uploadsinfra/forge-cloudflare/worker.bundle.js. It isworker.jsandsrc/cloud/edge.tsbundled into one file with no imports.bun scripts/build-edge.tsregenerates the bundle.worker.jsstays the source, sowrangler deploystill bundles it itself.- One test loads
worker.bundle.jsalone in an empty directory, with nosrc/beside it, and checks it serves the restarting page. - Another test fails when the committed bundle differs from a fresh build, so the bundle can't go stale unnoticed. The README says to rebuild after editing
worker.jsoredge.ts.
Secondary fixes
- 5xx from the body: a 502, 503 or 504 on an HTML GET or HEAD now gets the restarting page, the same as an unreachable body.
/healthz, non-HTML requests and other statuses such as 500 pass through unchanged. - HEAD: the restarting page and the Resilience copy keep their status and headers but send no body on HEAD.
- Push guesses:
PUT /_edge/resilienceallows 5 wrong tokens per minute percf-connecting-ip. After that it answers 429 withRetry-After, even for the right token, until the window passes. The counter lives in the Durable Object's memory and is capped at 1000 addresses. A Durable Object restart resets it. I chose that over storing it, since the token compare stays constant-time and a reset only gives an attacker a fresh five guesses.
I did not change the celld test, which still copies edge.ts into place. That path runs worker.js through esbuild, as wrangler dev does, so the sibling src/ is correct there. The standalone-bundle test covers the Terraform path.
The edge now answers with a restarting page and the last Resilience copy when the forge is down, and the failing type check is fixed.
Fix: scripts/build-edge.ts indexed out.outputs[0] without checking it existed, which TypeScript flagged as possibly undefined (TS2532). bundle() now throws "the edge bundle produced no output" when the build returns nothing.
Verification:
tsc --noEmitis clean after the fix.bun test test/edge-push.test.tspasses (4 tests).- I started a full
bun testbut it ran past the 120 s limit, so I didn't wait for its result. The forge's check will run the rest.
What I chose not to do: I changed no behaviour and added no test, since this is a type-safety guard on a path that only fires if Bun's bundler returns nothing.
How to try it: run bun scripts/build-edge.ts to regenerate infra/forge-cloudflare/worker.bundle.js, the file the Terraform module uploads.
Parked by the crew: the check failed ("the gate's list > every test/*.test.ts is in exactly one list, and every entry exists") and the decider saw no point in another try
The Worker now answers for the forge when the body is unreachable. It serves a "the forge is restarting" page and a pushed copy of the Resilience map, and nothing pushes that map yet.
test/forge-cloudflare.test.tspasses, 6 tests. I couldn't runtschere because the type definitions weren't installed. I also haven't run the celld variant, which skips without esbuild and a download.src/cloud/edge.tsrenders one self-contained page with no script, inline style, and CSP,nosniffandReferrer-Policyheaders. It says when the edge last heard from the body, or "never". Inworker.js, any GET or HEAD that sendsAccept: text/htmlgets it as a 503 withRetry-After: 30while the body is unreachable.PUT /_edge/resilience. The request needsAuthorization: Bearer $EDGE_PUSH_TOKENand a JSON body of{"domains":[{name,breaks,says,back,owner}]}. At most 32 rows are accepted, each field a string up to 600 characters, and the whole body is capped at 64 KB. The Worker keeps the copy in Durable Object storage. While the body is down,/settings/resilienceserves it with every cell escaped and a banner saying it is a copy and how old it is. If nothing has been pushed, that path gets the restarting page./healthzis still a JSON 503, non-browser requests still get the plain 502, and POSTs never get a page. When the body is up, requests pass straight through. The only addition is that the Worker records when it last heard from the body, at most once every 10 seconds.Retry-After, and no<script;worker.jsnow imports../../src/cloud/edge.ts, which wrangler bundles. The celld test now copies that file next to the Worker so it still runs. The README ininfra/forge-cloudflaredocuments the push.I left out the forge-side push on boot and on change.
src/web/pages/resilience.tsand the map itself don't exist in this repo yet, so there is nothing to push. Once that page lands, it should send its rows to/_edge/resiliencewith the token. Before then, setEDGE_PUSH_TOKENas a Worker secret. There are no new dependencies.Closes #1194