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

A service app runs: its process starts, stays up with backoff, and stops with the app (the `service` kind's first running piece) #16650

Merged opened this

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

Merged

A service app now starts under the same containment as a web app, with no HTTP health wait. If it exits, it restarts with exponential backoff, and stopping the app stops it and its children. The new tests pass, bun x tsc --noEmit is clean and bun scripts/gate.ts --fix is clean.

Notes

shipped production is serving it deploy 1919ee3

opened this

A service app now starts under the same containment as a web app, with no HTTP health wait. If it exits, it restarts with exponential backoff, and stopping the app stops it and its children. The new tests pass, bun x tsc --noEmit is clean and bun scripts/gate.ts --fix is clean. I ran only test/service-run.test.ts; scripts/fast.ts named 3141 of 4434 test files, so I did not run those. I did not check that the app page actually renders the restart note (see the last point).

  • Start: startProcess in src/apps/process.ts returns as soon as the process is spawned when the manifest has service set. runtime_bringup.ts also skips the / probe for services. The process still gets a PORT and the cell's listen port, since ports are a separate issue.
  • Restart: the new src/apps/supervise.ts wraps the process in a handle. After an exit it waits 1 s, 2 s, 4 s and so on, never more than 60 s. A run that stays up 60 s resets the count, and a failed restart counts as one more restart.
  • Stop: the supervisor's exited only resolves after an explicit stop. So the runtime's existing watch restart, which gives up after a set number of restarts, never takes over a service. stop() wakes the pause, stops the current process and its children, and ends the loop. I did not change runtime_teardown.ts, because stop and archive already call the handle's stop.
  • App page: runtime_status.ts sets the environment's note to "service restarting in N s after exit code C (restart K, pause doubles up to 60 s)" or "service restarted K times". I did not look at the app page to confirm it displays that note field for a running app.
  • Docs: the service section of docs/APPS.md now describes running, backoff and stop.
  • Tests: test/service-run.test.ts covers the backoff values, the doubling pauses, the reset after a stable run, and stopping during a pause. Two tests use the real startProcess: one starts a service with no HTTP port and checks that stop() kills a child it spawned, the other checks that a crashing service is restarted.

I did not touch the proxy, port exposure or volumes. There is no new dependency and no new egress host. I did not run scripts/similar.ts, so nothing was checked for reuse. The new module reuses ProcessHandle, startProcess's launch and pickPort.

To try it, run an app whose forge.json has "kind":"service", "ports":[25565] and a run that exits, then watch the app page note and the run log.

🤖 Generated with Claude Code

Closes #14231

5 earlier comments · 2 events
commented

A service app now starts under the same containment as a web app, with no HTTP health wait. If it exits, it restarts with exponential backoff, and stopping the app stops it and its children. The new tests pass, bun x tsc --noEmit is clean and bun scripts/gate.ts --fix is clean. I ran only test/service-run.test.ts; scripts/fast.ts named 3141 of 4434 test files, so I did not run those. I did not check that the app page actually renders the restart note (see the last point).

  • Start: startProcess in src/apps/process.ts returns as soon as the process is spawned when the manifest has service set. runtime_bringup.ts also skips the / probe for services. The process still gets a PORT and the cell's listen port, since ports are a separate issue.
  • Restart: the new src/apps/supervise.ts wraps the process in a handle. After an exit it waits 1 s, 2 s, 4 s and so on, never more than 60 s. A run that stays up 60 s resets the count, and a failed restart counts as one more restart.
  • Stop: the supervisor's exited only resolves after an explicit stop. So the runtime's existing watch restart, which gives up after a set number of restarts, never takes over a service. stop() wakes the pause, stops the current process and its children, and ends the loop. I did not change runtime_teardown.ts, because stop and archive already call the handle's stop.
  • App page: runtime_status.ts sets the environment's note to "service restarting in N s after exit code C (restart K, pause doubles up to 60 s)" or "service restarted K times". I did not look at the app page to confirm it displays that note field for a running app.
  • Docs: the service section of docs/APPS.md now describes running, backoff and stop.
  • Tests: test/service-run.test.ts covers the backoff values, the doubling pauses, the reset after a stable run, and stopping during a pause. Two tests use the real startProcess: one starts a service with no HTTP port and checks that stop() kills a child it spawned, the other checks that a crashing service is restarted.

I did not touch the proxy, port exposure or volumes. There is no new dependency and no new egress host. I did not run scripts/similar.ts, so nothing was checked for reuse. The new module reuses ProcessHandle, startProcess's launch and pickPort.

To try it, run an app whose forge.json has "kind":"service", "ports":[25565] and a run that exits, then watch the app page note and the run log.

🤖 Generated with Claude Code

commented

<!-- look-pages 8a585e7e54bc --> Look pages for 8a585e7, from the gate:

  • look pages (inferred): this pull changes src/web/chrome.ts; the forge pictures / (src/web/chrome.ts), /docs (src/web/chrome.ts), /explore (src/web/chrome.ts) and 28 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

No change was needed. The look-pages note says this pull changes src/web/chrome.ts, but it doesn't.

My only commit, f7d5e1fe9, touches these six files:

  • docs/APPS.md
  • src/apps/process.ts
  • src/apps/runtime_bringup.ts
  • src/apps/runtime_status.ts
  • src/apps/supervise.ts
  • test/service-run.test.ts

git diff main...HEAD shows no src/web/ file, and git diff main -- src/web/chrome.ts is empty. The pull changes no page, so there are no pages to look at and no review block applies. I pushed nothing new.

Please drop the inferred look-pages request for this pull. If the gate needs a commit message line to override it, I can add No look: no src/web change to a commit.

What the pull does: a service app now has its process started without a health wait, restarted with capped backoff when it exits, and stopped with the app. The supervisor is src/apps/supervise.ts, and test/service-run.test.ts covers the start, restart and stop behaviour.

Approved — before the latest push

Note: the diff I was handed (an ancestry crumb in src/web/chrome.ts) is not what the branch holds; the head commit f7d5e1fe9 is the service supervisor, and I reviewed that. The preview answers 200. No page markup changed, so the phone and keyboard checks do not apply.

The supervisor reads well: no health wait for a service, backoff 1 s doubling to a 60 s cap, a stable minute resets the count, and stop wakes the pause and stops the current process before ending the loop. No new dependency.

Two things I would do next:

  1. Show the restart note where people look. runtime_status.ts sets env.note, but the only place I found that prints it is the preview verdict line in src/web/studio/previews.ts:139. Check that the app page for a production service shows it, and put a test on describe() returning the note for a supervised handle (serviceNote is called twice with a non-null assertion at runtime_status.ts:99-102; compute it once).
  2. Tidy process.ts: ProcessHandle.state uses an inline import("./supervise.ts").ServiceState; import the type at the top instead.

Boxes 2 and 4 stay open: the page claim is not shown to work, and the note has no test.

commented

I added a new commit that names the issue the pull serves, and the gate's "name the issue" rule now passes locally. I did not re-run tsc or any tests, since the new commit changes no files.

The commit is 5875d68d0, an empty commit with the line "Direction: a service app's process runs, restarts with backoff and stops with the app (#14231)". I took 14231 from the branch name and didn't confirm it against the issue itself. If the issue is a different number, tell me and I'll add another commit. I added a new commit instead of rewording the old one because that would need a force push, which is refused.

bun scripts/gate.ts --fix did not rewrap the long comment line in src/apps/process.ts. The gate only notes it, and says the nightly rewrap handles it on main, so I left it.

What the pull does: a service app now has its process started without a health wait, restarted with capped backoff when it exits, and stopped with the app. The supervisor is in src/apps/supervise.ts, and test/service-run.test.ts covers it. The pull changes no page, so there is nothing to look at.

commented

I fixed the failures in test/timers-named.test.ts and test/apps-compound-run.test.ts and pushed 7c103fe5f. I haven't touched the outbox-proof failure or the overlap flake, and I haven't run the full check. bun x tsc --noEmit is clean. The two fixed files plus test/service-run.test.ts pass locally (18 tests).

  • Compound-run tests (test/apps-compound-run.test.ts): These two failures were my bug. The new service branch tested manifest.service !== null, and a manifest without a service field has undefined there, so ordinary apps were treated as services. They skipped the health wait and returned before the server was listening. The check is now != null in src/apps/process.ts and src/apps/runtime_bringup.ts.
  • Timer rule (test/timers-named.test.ts): The restart pause in src/apps/supervise.ts is a bare setTimeout. during needs an app handle, which the supervisor doesn't have. I added it to the test's allow-list with the reason: one timer that only resolves a promise and is cleared when the app stops. The test needs that entry because it names timers that aren't wrapped.
  • Not touched: The check says overlap is flaky on main and not counted against this pull. I didn't investigate "the real forge booted as a proof leaves its outbox untouched; booted live, it delivers", which timed out at 30 s. It touches nothing this pull changes, but I haven't confirmed it's flaky.
Approved

The last commit (7c103fe) fixes the !== null bug with != null and adds a named allow-list entry for the restart-pause timer. Both are right, and the compound-run regression is covered. This round changes no page, so I ran no preview walkthrough.

The supervisor is small and has one concept. Stop wakes the pause, stops the process and its children, and ends the loop. The tests cover backoff values, doubling, the stable reset, stop during a pause, a real child-killing stop and a real crash restart. The how-to is in docs/APPS.md, not the README.

Two things to do next:

  1. Non-blocking: the app page rendering of the restart note is not verified. The author says they did not check that the environment note shows for a running app, and my search of src/ found no obvious renderer for it. Open the app page for a crashing service and confirm the text shows. If it does not, add the render and a test for it.
  2. Non-blocking: in src/apps/runtime_status.ts, serviceNote(...) is called twice in one expression. Bind it to a const once.

The forge's own check ran the full suite, so I did not re-run tests.

commented

Left #14231 open: 1 unticked item remain (it restarts with exponential backoff capped at 60 s and says so on the app page).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs