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

A front router wakes an asleep forge on its first request and says "waking…" while it does #16882

Merged opened this

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

Merged

A browser is now held only 1.5 s at an asleep forge before it gets the "waking up" page. API calls, git clients and POSTs are still held for up to 20 s and never get HTML. I ran four test files, which pass (front-wake, spawn-cell-stays, first-ten-minutes, spawn-cell).

Notes

opened this

A browser is now held only 1.5 s at an asleep forge before it gets the "waking up" page. API calls, git clients and POSTs are still held for up to 20 s and never get HTML. I ran four test files, which pass (front-wake, spawn-cell-stays, first-ten-minutes, spawn-cell). tsc and the gate are clean. I did not run the full suite.

Most of this already existed. answerFromCell and settleCell in src/spawn/host.ts already start an asleep cell forge on the first request, share one start between concurrent requests, and hold requests until it answers. The wakingResponse page and the wakeMs measurement were there too. What was missing was the split by kind of client. Before, every client waited the full 20 s, so a browser saw the waking page only after that.

What changed

  • patienceOf(request) in src/spawn/host.ts picks the wait. A GET or HEAD that accepts HTML waits wakeLimits.pageMs (1.5 s, new), then gets the self-refreshing page. Everything else waits wakeLimits.waitMs (20 s).
  • A POST stays on the long wait because a refresh would lose its body.
  • test/front-wake.test.ts is new. It covers:
    • Wake time: 20 wakes against a stubbed 20 ms cell start, with p95 asserted under 1 s.
    • One start: four concurrent requests (browser, API, POST, wildcard) are all served by a single start.
    • Client kinds: a browser gets the refresh page while API, git and POST get the upstream answer.
  • docs/features/forge-sleep.md described the old behaviour ("waking up page at once; git and API wait up to 4 s"), so I corrected it.

Left out

  • No new router. One router owning every forge's address on a machine already exists as the parent's host routing, so I extended it instead of adding a process.
  • Stubbed cell start. The sandbox skips real cells, so the p95 test measures the router's overhead, not a real cell boot. The forge's own check is where real cells run.
  • Hosted children. Only cell forges are touched. Children hosted in-process open synchronously.
  • No Try: line. The change is in src/spawn, so I did not add one.

To try: bun test test/front-wake.test.ts. On a preview, curl -H 'accept: text/html' and curl -H 'accept: application/json' against a sleeping forge's address.

Closes #16854

commented

A browser is now held only 1.5 s at an asleep forge before it gets the "waking up" page. API calls, git clients and POSTs are still held for up to 20 s and never get HTML. I ran four test files, which pass (front-wake, spawn-cell-stays, first-ten-minutes, spawn-cell). tsc and the gate are clean. I did not run the full suite.

Most of this already existed. answerFromCell and settleCell in src/spawn/host.ts already start an asleep cell forge on the first request, share one start between concurrent requests, and hold requests until it answers. The wakingResponse page and the wakeMs measurement were there too. What was missing was the split by kind of client. Before, every client waited the full 20 s, so a browser saw the waking page only after that.

What changed

  • patienceOf(request) in src/spawn/host.ts picks the wait. A GET or HEAD that accepts HTML waits wakeLimits.pageMs (1.5 s, new), then gets the self-refreshing page. Everything else waits wakeLimits.waitMs (20 s).
  • A POST stays on the long wait because a refresh would lose its body.
  • test/front-wake.test.ts is new. It covers:
    • Wake time: 20 wakes against a stubbed 20 ms cell start, with p95 asserted under 1 s.
    • One start: four concurrent requests (browser, API, POST, wildcard) are all served by a single start.
    • Client kinds: a browser gets the refresh page while API, git and POST get the upstream answer.
  • docs/features/forge-sleep.md described the old behaviour ("waking up page at once; git and API wait up to 4 s"), so I corrected it.

Left out

  • No new router. One router owning every forge's address on a machine already exists as the parent's host routing, so I extended it instead of adding a process.
  • Stubbed cell start. The sandbox skips real cells, so the p95 test measures the router's overhead, not a real cell boot. The forge's own check is where real cells run.
  • Hosted children. Only cell forges are touched. Children hosted in-process open synchronously.
  • No Try: line. The change is in src/spawn, so I did not add one.

To try: bun test test/front-wake.test.ts. On a preview, curl -H 'accept: text/html' and curl -H 'accept: application/json' against a sleeping forge's address.

commented

The front router now wakes an asleep forge: a browser is held 1.5 s and then shown the waking page, while API, git and POST requests are held until the forge is up. This push only fixes the failing gate rule.

  • What changed since the last push: test/front-wake.test.ts:43 now ends with // real-timer: <why>. The test simulates a cell start with a real Bun.sleep, because the router under test holds a browser on a real 1.5 s timer. A fake clock would not exercise that path. No behaviour changed.
  • Checks I ran: after committing, bun scripts/gate.ts no longer reports the rule, and bun x tsc --noEmit is clean. bun test test/front-wake.test.ts passed (4 tests) on the first attempt. I did not re-run it after the one-line comment change.
  • Not done: the gate's note about a long comment line in src/spawn/host.ts is untouched. It is outside this change, and the nightly rewrap handles it. The gate's duplicate scan also stopped after 8 s and compared against only part of the tree.
  • To try it: bun test test/front-wake.test.ts.
Sign in to join this conversation.

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

Keyboard shortcuts

Docs