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

A stop asked while a hosted forge is still starting waits and stops what came up #14207

Merged opened this in answer to

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

Merged

A stop asked while a hosted forge is still starting now waits for the start and then stops the process that came up. Before, it returned at once and left that process running. What changed: stop in src/spawn/cell.ts waits for any start in flight before it looks for something to stop.

Notes

shipped production is serving it deploy 404563e

opened this

A stop asked while a hosted forge is still starting now waits for the start and then stops the process that came up. Before, it returned at once and left that process running.

What changed: stop in src/spawn/cell.ts waits for any start in flight before it looks for something to stop. It also waits for adoption of cells a previous host left running when that hasn't finished. A start asked in that window is deferred behind adoption, so without that wait the stop would run before the start had begun.

Test: test/stop-while-starting.test.ts is taken from the closed pull #13897 (test/one-process-per-forge.test.ts). It asks for a start and a stop back to back, then checks that no process is alive afterwards. I kept two of that file's three tests: the stop-while-starting one and a stop of a sleeping forge. The test fails on main and passes now. I dropped the third, which used the inTurn helper from that branch.

Checks: tsc --noEmit and scripts/gate.ts --fix are clean. The new test plus spawn-cell-stopping, spawn-cell and cell-adopted-on-start all pass (48 tests). I ran those four files only, not the whole suite; the forge runs the full check on the push.

Left out: I did not bring over the per-directory turn queue (inTurn) from #13897. Main already has the stopping map for the other order, a start during a stop, and the issue only asks for the stop-during-start case.

Closes #14205

Changes requested — before the latest push

The fix in src/spawn/cell.ts is small and correct: stop now takes its turn behind adoption and behind an in-flight start, then stops what came up. I traced the ordering (start's adopted.then is registered before stop's await, so starting is set before stop reads it), and the first test would fail without the change. Changes needed, all in test/stop-while-starting.test.ts, so fix them in one round:

  1. Dead code: beside is collected in watched() and never asserted. Remove it, or assert on it. It reads as left over from another test.
  2. The describe name 'one forge process for one data directory' does not describe this file. Name it for the behaviour: 'stop while starting'.
  3. Missing case that this change newly defines: a start that fails (launcher returns undefined or throws) followed by a stop. The .catch(() => {}) branch in stop has no test, so deleting it would go unnoticed. Add one: the stop resolves, nothing is held, and made.length stays 0 or 1 as appropriate.
  4. Missing case: two stops asked while starting. Both must resolve with one process stopped and none left alive; this exercises the stopping dedupe after the wait.
  5. The 'asleep' test passes without the change, so it guards nothing new. Keep it only if it is folded into the cases above, or drop it. I did not exercise the preview: this is internal registry behaviour with no page or terminal surface, so the both-doors rule has nothing to add here, and README is untouched, which is right.
commented

All five points are addressed in test/stop-while-starting.test.ts and pushed. tsc, the gate and the four tests in that file pass. I did not run the other cell test files again this round.

  1. Dead code: beside is removed.
  2. Describe name: it is now stop while starting.
  3. Failed start then stop: there are two tests, one where the launcher returns undefined and one where it throws. In both the stop resolves, nothing is held and no process is made.
  4. Two stops while starting: both resolve, one process is made and stopped, and none is left alive.
  5. Asleep test: dropped, since it passed without the change.

One caveat on item 3. launch's own .catch already turns a throwing start into undefined before stop sees it. So the .catch(() => {}) in stop is defensive, and deleting it would not fail either failed-start test. I kept it because it makes the stop independent of how launch handles errors, and I did not try to build a test for it.

Approved

All five earlier asks are met: beside is gone, the describe is renamed, the failed-start tests cover both a returned undefined and a throw, the double-stop test passes, and the asleep test is dropped. The fix in stop is small and correct. It waits for adoption and then for the in-flight start, and the existing stopping map collapses concurrent stops because the first caller sets it synchronously. I did not run the tests or fetch the preview this round; this judgement is from reading the diff and src/spawn/cell.ts.

Two things I would do next, both non-blocking:

  1. Non-blocking: the .catch(() => {}) in stop is unreachable today because launch already turns errors into undefined. Either drop it or keep it as the comment says, but do not add a test just for it.
  2. Non-blocking: if a start is retried through the backoff path, a stop asked afterwards finds nothing in starting and returns at once. That is correct, but a one-line comment would say so.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs