Public: anyone can read this; the crew can change it.

The edge keeps the last Resilience page and serves it, marked as a copy, while the forge is down #16793

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The Worker now keeps the last Resilience map the forge pushed. While the body is unreachable, it serves that map at /settings/resilience as a copy with its age.

Notes

opened this

The Worker now keeps the last Resilience map the forge pushed. While the body is unreachable, it serves that map at /settings/resilience as a copy with its age. The type check is clean and the tests I ran pass: the two new files plus test/maintain-edge-kept.test.ts, 8 other maintain* tests, hollow, feature-doors and check-list. I did not run the full gate or the rest of the suite. scripts/fast.ts named 3,701 test files, too many to run, so the forge's check does that on push.

What changed

  • Worker (infra/forge-cloudflare/worker.js):
    • Push: PUT /_edge/resilience stores the map in the Durable Object. It needs a bearer token equal to the Worker secret COPY_TOKEN. A wrong token gets 403 and a body over 256 KB gets 400.
    • Serve: when the fetch to the body throws, a browser GET of /settings/resilience gets the stored copy. It sits under a "This is a copy" box that gives its age ("3 minutes ago") and a datetime. The response carries Age and X-Forge-Edge-Copy headers and a no-script CSP. With no copy stored, or on any other path, the restarting page appears as before.
  • Forge side:
    • Rendering: src/maintain/edge_copy.ts renders the protections and the backups line as one escaped fragment. It pushes only when the fragment differs from what the Worker last took.
    • Duty: the edge-resilience duty runs every minute and does the push. It pushes on the first run after each boot, then again whenever the map changes (a change shows up within a minute). With FORGE_EDGE_COPY_URL or FORGE_EDGE_COPY_TOKEN unset it does nothing.
    • Lazy imports: the duty loads checks/resilience and backups_line inside run, because the roster loads duty files with require, which refuses a top-level await in their import chain.
  • Tests: test/forge-cloudflare.test.ts covers the copy, its age, the 403, and no copy served on other paths. test/maintain-edge-resilience.test.ts covers the escaping, push-on-boot, push-on-change, the refused push, and the duty on the roster. bun scripts/gate.ts --explain reported all 32 rules satisfied.
  • Docs: docs/features/edge-resilience-copy.md is new, and the infra README has a short section on the copy.

Left out or to check

  • Egress: the host is configured at runtime, not a literal in the code. The operator must add the Worker's host to forge.json egress. I did not, because the host isn't known here.
  • Settings route: the forge's own /settings/resilience still redirects to /settings/backups#domains. The copy only appears at the edge, as the issue asks.
  • Terminal side: there is no change under src/tui/, since this adds no page, action or tool.
  • What the copy leaves out: nightly output and anything that needs the body.
  • Unreachable only: only an unreachable body triggers the copy, not a 5xx answer from the body.
  • Reuse: I reused readResilience, backupsLine, escapeHtml, and the Worker's existing CSP and wantsPage. I did not run scripts/similar.ts.
  • Plan: I did not call keep_plan.

Try it: set COPY_TOKEN on the Worker with wrangler secret put COPY_TOKEN, and set FORGE_EDGE_COPY_URL and FORGE_EDGE_COPY_TOKEN on the forge. Stop the body and open <worker>/settings/resilience.

🤖 Generated with Claude Code

Closes #16260

3 earlier comments
commented

The Worker now keeps the last Resilience map the forge pushed. While the body is unreachable, it serves that map at /settings/resilience as a copy with its age. The type check is clean and the tests I ran pass: the two new files plus test/maintain-edge-kept.test.ts, 8 other maintain* tests, hollow, feature-doors and check-list. I did not run the full gate or the rest of the suite. scripts/fast.ts named 3,701 test files, too many to run, so the forge's check does that on push.

What changed

  • Worker (infra/forge-cloudflare/worker.js):
    • Push: PUT /_edge/resilience stores the map in the Durable Object. It needs a bearer token equal to the Worker secret COPY_TOKEN. A wrong token gets 403 and a body over 256 KB gets 400.
    • Serve: when the fetch to the body throws, a browser GET of /settings/resilience gets the stored copy. It sits under a "This is a copy" box that gives its age ("3 minutes ago") and a datetime. The response carries Age and X-Forge-Edge-Copy headers and a no-script CSP. With no copy stored, or on any other path, the restarting page appears as before.
  • Forge side:
    • Rendering: src/maintain/edge_copy.ts renders the protections and the backups line as one escaped fragment. It pushes only when the fragment differs from what the Worker last took.
    • Duty: the edge-resilience duty runs every minute and does the push. It pushes on the first run after each boot, then again whenever the map changes (a change shows up within a minute). With FORGE_EDGE_COPY_URL or FORGE_EDGE_COPY_TOKEN unset it does nothing.
    • Lazy imports: the duty loads checks/resilience and backups_line inside run, because the roster loads duty files with require, which refuses a top-level await in their import chain.
  • Tests: test/forge-cloudflare.test.ts covers the copy, its age, the 403, and no copy served on other paths. test/maintain-edge-resilience.test.ts covers the escaping, push-on-boot, push-on-change, the refused push, and the duty on the roster. bun scripts/gate.ts --explain reported all 32 rules satisfied.
  • Docs: docs/features/edge-resilience-copy.md is new, and the infra README has a short section on the copy.

Left out or to check

  • Egress: the host is configured at runtime, not a literal in the code. The operator must add the Worker's host to forge.json egress. I did not, because the host isn't known here.
  • Settings route: the forge's own /settings/resilience still redirects to /settings/backups#domains. The copy only appears at the edge, as the issue asks.
  • Terminal side: there is no change under src/tui/, since this adds no page, action or tool.
  • What the copy leaves out: nightly output and anything that needs the body.
  • Unreachable only: only an unreachable body triggers the copy, not a 5xx answer from the body.
  • Reuse: I reused readResilience, backupsLine, escapeHtml, and the Worker's existing CSP and wantsPage. I did not run scripts/similar.ts.
  • Plan: I did not call keep_plan.

Try it: set COPY_TOKEN on the Worker with wrangler secret put COPY_TOKEN, and set FORGE_EDGE_COPY_URL and FORGE_EDGE_COPY_TOKEN on the forge. Stop the body and open <worker>/settings/resilience.

🤖 Generated with Claude Code

commented

The edge now keeps the last Resilience page and serves it as a copy, with its age, while the body is down (#16260). This push fixes the failed check.

What changed in this push: test/maintain-edge-resilience.test.ts no longer casts with as never. It builds a typed Row[] for the fragment test, a real ForgeConfig ({ dataDir, port: 0 }) for createApp, and a typed DutyContext for the duty. The test checks the same things as before.

Checks run: bun scripts/gate.ts is clean after the commit. bun x tsc --noEmit is clean. The file's 3 tests pass.

Left out: I did not run the full suite. The forge runs it on push.

To try it: bun test test/maintain-edge-resilience.test.ts.

commented

The edge keeps the last Resilience page and serves it as a copy, with its age, while the body is down (#16260). This push fixes two of the three failures from the last check.

  • Outbound sweep: src/maintain/duties/edge_resilience.ts makes one fetch to the edge copy URL the operator configured, never a host from a request. I listed it in the ALLOWED table in test/outbound-sweep.test.ts with that reason. test/outbound-sweep.test.ts and test/unused-exports.test.ts now pass.
  • Dead-code check: forgetPushed is exported only so the test can reset the "last pushed" state. I added it to scripts/unused-exports-allow.json.
  • test/fork-drift-cache.test.ts ("a second read spawns no git…"): it failed with git_failed in the forge's shard run, but it passes when I run it here and nothing I changed touches git. I think it is a flake under shard load and left it alone, so it may fail again.

bun scripts/gate.ts and bun x tsc --noEmit are clean. I did not run the full suite.

To try it: bun test test/outbound-sweep.test.ts test/unused-exports.test.ts test/maintain-edge-resilience.test.ts.

commented

All three review items are fixed on the branch, and the new tests pass. gate, tsc and design-lint are clean, and the unused-exports and outbound-sweep tests pass.

1. Who sees the copy. The Worker cannot tell an admin from anyone else, and I chose not to add identity checks there. Instead the copy now carries only what the docs already publish. It lists each protection as THREATS.md words it (text and adversary), with a count. It leaves out the standings, test file names, the backups line and the nightly output. A red standing names what to attack, so that stays on /resilience, which still needs a signed-in admin. The page says so.

  • The tradeoff is that the copy no longer shows green or red during an outage. If the copy should keep standings, the alternative is a signed identity the Worker can verify, which is a larger change. Say if you want that.
  • The test is in test/forge-cloudflare.test.ts: an unauthenticated browser gets the copy, and test/maintain-edge-resilience.test.ts checks the pushed fragment has no standing, test file or backups text. The change is in copyFragment and the edge_resilience duty.

2. Byte cap.

  • Cap: Forge.keep now reads the stream through readCapped. It keeps a running count of bytes and stops reading at 256 KB. Oversize and empty pushes both answer 400 bad size.
  • Tests: an oversize push is tested with 90,000 three-byte characters, which is under 256 K characters but about 270 KB as bytes. It is refused and stores nothing. A non-PUT (GET, POST, DELETE) to /_edge/resilience gets 405 with allow: PUT.

3. Egress and age.

  • Egress: production's forge.json does not need an entry. The Worker's host is the operator's own, set in FORGE_EDGE_COPY_URL, so I can't write a literal for it. It has to be added in whichever deployment sets that variable, or on the app's settings page. docs/features/edge-resilience-copy.md says this now. The duty's single fetch is listed in test/outbound-sweep.test.ts.
  • Age test: a copy stored 185 seconds ago reads "3 minutes ago" and gets age: 185.

I could not run the Worker here, so the served page is tested against the source only.

A third failure from the last check, test/fork-drift-cache.test.ts, passes here and doesn't touch this change, so I left it alone.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs