diff --git a/crates/gateway/app/src/main.rs b/crates/gateway/app/src/main.rs index 97452947..2c588343 100644 --- a/crates/gateway/app/src/main.rs +++ b/crates/gateway/app/src/main.rs @@ -155,7 +155,7 @@ fn main() -> ExitCode { ShutdownReason::Restart => "gateway restarting", }; - tracing::info!(log_message); + tracing::info!("{log_message}"); } shutdown_reason.exit_code() diff --git a/crates/gateway/app/src/runner.rs b/crates/gateway/app/src/runner.rs index d3775736..50f6d3ef 100644 --- a/crates/gateway/app/src/runner.rs +++ b/crates/gateway/app/src/runner.rs @@ -133,10 +133,20 @@ impl ServeOptions { self.preferred_port = port; self } + + /// The run directory: the one these options name, or the default under + /// the user's profile. `None` when there is no profile directory. + // TODO: Clean up rundir handling https://github.com/cppalliance/runvil-gateway/issues/2 + #[must_use] + pub fn resolved_run_dir(&self) -> Option { + self.run_dir + .clone() + .or_else(gateway_api_discovery::default_run_dir) + } } /// The parsed app options: the serve options plus how the main thread runs. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct AppOptions { /// What the launch does. pub command: LaunchCommand, diff --git a/crates/gateway/app/src/runner/thread.rs b/crates/gateway/app/src/runner/thread.rs index 501d9a0f..cffa15e7 100644 --- a/crates/gateway/app/src/runner/thread.rs +++ b/crates/gateway/app/src/runner/thread.rs @@ -274,7 +274,7 @@ fn serve_thread( // The gateway discovery file lands before the readiness signal so a spawned // gateway is discoverable the moment `spawn` returns; the guard removes // it on every exit path below, graceful shutdown included. - let _gateway_discovery_file = gateway_discovery_file_guard(&config, options, address); + let gateway_discovery_file = gateway_discovery_file_guard(&config, options, address); // Publication counts as a successful gateway start, so from // here the rollback config files become stale and should be removed. if let Some(config_path) = &rollback_config_path { @@ -313,10 +313,23 @@ fn serve_thread( "no user profile directory found; the cloud provider model sheet is unavailable" ); } + + let shutdown_signal = Arc::clone(&gateway.state.shutdown); + let result = runtime .block_on(gateway.serve(listener, shutdown_on_send(shutdown))) .map_err(StartupError::serve); runtime.shutdown_timeout(RUNTIME_SHUTDOWN_TIMEOUT); + + // A restarting gateway leaves its record for its supervisor, which may + // not have polled since the publication: the record tells it this child + // served, and on which port. The next child overwrites it. + if shutdown_signal.reason() == Some(ShutdownReason::Restart) + && let Some(file) = gateway_discovery_file + { + file.keep(); + } + result } @@ -347,10 +360,30 @@ fn cloud_models_cache_path(options: &ServeOptions) -> Option { struct GatewayDiscoveryFileGuard { run_dir: PathBuf, pid: u32, + remove_on_drop: bool, +} + +impl GatewayDiscoveryFileGuard { + fn new(run_dir: PathBuf, pid: u32) -> Self { + Self { + run_dir, + pid, + remove_on_drop: true, + } + } + + /// Leaves the file in place when the guard drops. + fn keep(mut self) { + self.remove_on_drop = false; + } } impl Drop for GatewayDiscoveryFileGuard { fn drop(&mut self) { + if !self.remove_on_drop { + return; + } + if let Err(error) = gateway_api_discovery::remove_if_mine(&self.run_dir, self.pid) { tracing::warn!("could not remove the gateway discovery file: {error}"); } @@ -395,5 +428,5 @@ fn gateway_discovery_file_guard( ); return None; } - Some(GatewayDiscoveryFileGuard { run_dir, pid }) + Some(GatewayDiscoveryFileGuard::new(run_dir, pid)) } diff --git a/crates/gateway/app/src/supervisor-tests.rs b/crates/gateway/app/src/supervisor-tests.rs new file mode 100644 index 00000000..a73ad82d --- /dev/null +++ b/crates/gateway/app/src/supervisor-tests.rs @@ -0,0 +1,12 @@ +use super::*; + +#[test] +fn the_restart_backoff_starts_at_250_ms_and_doubles() { + let waits: Vec<_> = (1..MAX_RESTART_LAUNCHES).map(backoff).collect(); + + assert_eq!( + waits, + [250, 500, 1000, 2000].map(Duration::from_millis), + "a restart waits before each of its launches after the first" + ); +} diff --git a/crates/gateway/app/src/supervisor.rs b/crates/gateway/app/src/supervisor.rs index 49f0e231..38152405 100644 --- a/crates/gateway/app/src/supervisor.rs +++ b/crates/gateway/app/src/supervisor.rs @@ -7,51 +7,224 @@ //! owns the log file. use std::io::{BufRead, BufReader, Read, Write}; -use std::process::{Command, ExitCode, ExitStatus, Stdio}; +use std::path::PathBuf; +use std::process::{Child, ChildStdin, Command, ExitCode, ExitStatus, Stdio}; use std::thread::JoinHandle; +use std::time::{Duration, Instant}; -use gateway::AppOptions; -use gateway_api_discovery::LaunchLock; +use gateway::{AppOptions, RESTART_REQUESTED}; +use gateway_api_discovery::{GatewayDiscoveryFile, LaunchLock}; + +/// How long a launched child has to publish its discovery file. +const PUBLICATION_TIMEOUT: Duration = Duration::from_secs(30); + +/// How often a launching child is checked for publication or exit. +const PUBLICATION_POLL: Duration = Duration::from_millis(25); + +/// The launches one restart may make before the supervisor gives up. +const MAX_RESTART_LAUNCHES: u32 = 5; + +/// The wait before a restart's second launch; it doubles for each launch after. +const BASE_BACKOFF_TIMEOUT: Duration = Duration::from_millis(250); /// Supervisor entry point: starts and manages the child gateway process, /// returning the process exit code when it ends. Holds the launch lock while /// the gateway process is running, so another launch attempt attaches to the /// live child instead of launching a new gateway. pub(crate) fn run(options: &AppOptions, _launch_lock: LaunchLock) -> ExitCode { - let mut child = match build_child_command(options).spawn() { - Ok(child) => child, - Err(error) => { - eprintln!("error: could not start the gateway: {error}"); - return ExitCode::FAILURE; - } + let Some(run_dir) = options.serve.resolved_run_dir() else { + eprintln!("error: no user profile directory for the gateway's run directory"); + return ExitCode::FAILURE; }; - // The child's stdin stays open, unused, for as long as this process - // lives. When the pipe closes, the child's watchdog stops it. - let _child_stdin = child.stdin.take(); + let mut browser = options.serve.browser; + + // The port the last child published. Every relaunch asks for it, so a + // restart keeps the Settings URL; the first child binds as configured. + let mut preferred_port = None; + + // Launches made for the pending restart: 0 on the first boot and while + // a child serves. + let mut restart_launch_count = 0; + + loop { + let child_options = { + let mut child_options = options.clone(); + child_options.serve = child_options + .serve + .with_browser(browser) + .with_preferred_port(preferred_port); + child_options + }; + + let mut child = match SupervisedChild::spawn(&child_options, &run_dir) { + Ok(child) => child, + Err(error) => { + eprintln!("error: could not start the gateway: {error}"); + return ExitCode::FAILURE; + } + }; + + // Only the first launch opens the browser (or not), subsequent restarts never should. + browser = false; + + let publication_result = match child.await_publication() { + Ok(Launch::Published(port)) => { + preferred_port = Some(port); + + match child.wait_for_exit() { + Ok(status) if status.code() == Some(i32::from(RESTART_REQUESTED)) => { + restart_launch_count = 1; + continue; + } + + Ok(status) => return exit_code(status), + + Err(error) => { + eprintln!("error: could not wait for the gateway: {error}"); + return ExitCode::FAILURE; + } + } + } + + // A child that exits 0 before publishing handed off to a Gateway + // it found serving; the supervisor ends with it. + Ok(Launch::Exited(status)) if status.success() => return ExitCode::SUCCESS, + + Ok(Launch::Exited(status)) => exit_code(status), + + Ok(Launch::TimedOut) => { + eprintln!( + "error: the gateway published no connection within {PUBLICATION_TIMEOUT:?}; stopping it" + ); + child.kill(); + ExitCode::FAILURE + } + + Err(error) => { + eprintln!("error: could not watch the gateway start: {error}"); + child.kill(); + ExitCode::FAILURE + } + }; + + // A failed first boot is never retried. A failed restart launch is, + // until the restart has used all its launches. + if restart_launch_count == 0 || restart_launch_count >= MAX_RESTART_LAUNCHES { + return publication_result; + } + + std::thread::sleep(backoff(restart_launch_count)); + restart_launch_count += 1; + } +} + +/// The wait after a restart's `failed`-th launch fails: 250 ms, then +/// doubling. +fn backoff(failed: u32) -> Duration { + BASE_BACKOFF_TIMEOUT * 2u32.pow(failed - 1) +} + +/// What a launched child did first. +enum Launch { + /// It published its discovery file on this port and is serving. + Published(u16), + + /// It exited before publishing. + Exited(ExitStatus), + + /// It published nothing within the timeout and is still running. + TimedOut, +} + +/// A running child Gateway, with its held-open stdin and the threads +/// forwarding its output. +struct SupervisedChild<'a> { + process: Child, + + #[expect( + dead_code, + reason = "Needs to be held for the child's lifetime or the child's watchdog will kill it. We never write to it, so its unused." + )] + stdin: Option, + + forwarders: Vec>, + + run_dir: &'a PathBuf, +} + +impl<'a> SupervisedChild<'a> { + fn spawn(options: &AppOptions, run_dir: &'a PathBuf) -> std::io::Result { + let mut process = build_child_command(options).spawn()?; + + let stdin = process.stdin.take(); + + let forwarders = [ + process + .stdout + .take() + .map(|pipe| OutputStream::Stdout.forward(pipe)), + process + .stderr + .take() + .map(|pipe| OutputStream::Stderr.forward(pipe)), + ] + .into_iter() + .flatten() + .collect(); + + Ok(Self { + process, + stdin, + forwarders, + run_dir, + }) + } - let child_stdout = child.stdout.take(); - let child_stderr = child.stderr.take(); + /// Waits until the child publishes its discovery file, exits, or runs + /// out of time. + fn await_publication(&mut self) -> std::io::Result { + let deadline = Instant::now() + PUBLICATION_TIMEOUT; - // Forward the child's stdout and std_error to this thread's output streams - let output_handles = [ - child_stdout.map(|pipe| OutputStream::Stdout.forward(pipe)), - child_stderr.map(|pipe| OutputStream::Stderr.forward(pipe)), - ]; + loop { + // Publication is checked first: a child that served and then + // exited to restart has left its record, so it reads as + // published even when it exited between two polls. + if let Ok(Some(file)) = GatewayDiscoveryFile::read(self.run_dir) + && file.pid == self.process.id() + { + return Ok(Launch::Published(file.port)); + } - let status = child.wait(); + // Checks if the process has already exited + if self.process.try_wait()?.is_some() { + return self.wait_for_exit().map(Launch::Exited); + } - // The pipes close when the child exits; joining flushes its last lines. - for handle in output_handles.into_iter().flatten() { - let _ = handle.join(); + if Instant::now() >= deadline { + return Ok(Launch::TimedOut); + } + + std::thread::sleep(PUBLICATION_POLL); + } } - match status { - Ok(status) => exit_code(status), - Err(error) => { - eprintln!("error: could not wait for the gateway: {error}"); - ExitCode::FAILURE + /// Waits for the child to exit and for its last output to be forwarded. + fn wait_for_exit(&mut self) -> std::io::Result { + let status = self.process.wait(); + + // The pipes close when the child exits; joining flushes its last lines. + for forwarder in self.forwarders.drain(..) { + let _ = forwarder.join(); } + + status + } + + /// Stops the child and waits for it. + fn kill(&mut self) { + let _ = self.process.kill(); + let _ = self.wait_for_exit(); } } @@ -82,6 +255,10 @@ fn build_child_command(options: &AppOptions) -> Command { command.arg("--browser"); } + if let Some(port) = options.serve.preferred_port { + command.arg("--preferred-port").arg(port.to_string()); + } + command .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -124,3 +301,7 @@ fn exit_code(status: ExitStatus) -> ExitCode { .and_then(|code| u8::try_from(code).ok()) .map_or(ExitCode::FAILURE, ExitCode::from) } + +#[cfg(test)] +#[path = "supervisor-tests.rs"] +mod tests; diff --git a/crates/gateway/app/tests/it/boot/supervisor.rs b/crates/gateway/app/tests/it/boot/supervisor.rs index 4482fc47..d2deaff9 100644 --- a/crates/gateway/app/tests/it/boot/supervisor.rs +++ b/crates/gateway/app/tests/it/boot/supervisor.rs @@ -2,12 +2,13 @@ //! through a `--supervised` child, ends with it, stops it when killed, and //! hands a second launch off to it. -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::time::{Duration, Instant}; use gateway_api_discovery::{GatewayDiscoveryFile, ValidatedConnection}; use super::race_config; +use crate::boot::write_config; use crate::support::{GatewayProcess, wait_for_connection}; const BOOT_TIMEOUT: Duration = Duration::from_secs(30); @@ -39,6 +40,66 @@ fn process_exited(pid: u32) -> bool { .is_none_or(|process| process.status() == sysinfo::ProcessStatus::Zombie) } +/// Launches the supervisor made, counted by the launch record each child +/// writes to stdout and the supervisor forwards. +fn launches(stdout: &str) -> usize { + let record = format!("runvil-gateway {} starting", env!("CARGO_PKG_VERSION")); + + stdout.matches(&record).count() +} + +/// Asks the gateway serving on `port` to restart. +fn request_restart(port: u16) { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + + let response = runtime + .block_on( + reqwest::Client::new() + .post(format!("http://127.0.0.1:{port}/admin/restart")) + .bearer_auth("test-token") + .send(), + ) + .expect("the restart request should send"); + + assert_eq!(response.status(), reqwest::StatusCode::ACCEPTED); +} + +/// Waits for a discovery file published by a process other than `old_pid`. +fn wait_for_new_child(run_dir: &Path, old_pid: u32) -> GatewayDiscoveryFile { + let deadline = Instant::now() + BOOT_TIMEOUT; + + loop { + if let Ok(Some(file)) = GatewayDiscoveryFile::read(run_dir) + && file.pid != old_pid + { + return file; + } + + assert!( + Instant::now() < deadline, + "a new child should publish within {BOOT_TIMEOUT:?}" + ); + std::thread::sleep(Duration::from_millis(25)); + } +} + +/// Kills `pid` from outside its supervisor. +fn kill(pid: u32) { + let pid = sysinfo::Pid::from_u32(pid); + let mut system = sysinfo::System::new(); + system.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[pid]), true); + + let killed = system + .process(pid) + .expect("the child should be running") + .kill(); + + assert!(killed, "the child should accept the kill"); +} + /// `POST /shutdown` stops the child, and the supervisor exits with the /// child's 0. #[test] @@ -134,3 +195,109 @@ fn a_second_launch_attaches_to_the_supervised_child() { first.stop(EXIT_TIMEOUT); } + +/// `POST /admin/restart` replaces the child: a new pid publishes on the +/// same port, and the supervisor keeps running. +#[test] +fn a_restart_request_relaunches_the_child_on_the_same_port() { + let temp = tempfile::tempdir().unwrap(); + let config = race_config(&temp); + let mut supervisor = GatewayProcess::spawn_headless_launch(&config, temp.path(), &[]); + + let first = wait_for_connection(&run_dir(&temp), BOOT_TIMEOUT); + + request_restart(first.port); + + let second = wait_for_new_child(&run_dir(&temp), first.pid); + + assert_eq!( + second.port, first.port, + "the relaunched child should bind the port the first published" + ); + assert!( + process_exited(first.pid), + "the first child should have exited" + ); + assert!( + supervisor.try_wait().is_none(), + "the supervisor should keep running across a restart" + ); + + supervisor.stop(EXIT_TIMEOUT); +} + +/// A config that cannot load fails the first boot, and the supervisor exits +/// with the child's code after that one launch. +#[test] +fn a_failed_first_boot_ends_the_supervisor_without_a_relaunch() { + let temp = tempfile::tempdir().unwrap(); + let config = write_config(&temp, "not a config".to_string()); + let mut supervisor = GatewayProcess::spawn_headless_launch_capturing(&config, temp.path(), &[]); + + let status = supervisor.wait_for_exit(BOOT_TIMEOUT); + + assert_eq!( + status.code(), + Some(1), + "a failed first boot should end the supervisor with the child's code, got {status}" + ); + assert_eq!( + launches(&supervisor.stdout()), + 1, + "a failed first boot should not be relaunched" + ); +} + +/// A serving child killed from outside is a crash, not a restart: the +/// supervisor exits non-zero after that one launch. +#[test] +fn a_child_killed_from_outside_ends_the_supervisor_without_a_relaunch() { + let temp = tempfile::tempdir().unwrap(); + let config = race_config(&temp); + let mut supervisor = GatewayProcess::spawn_headless_launch_capturing(&config, temp.path(), &[]); + + let connection = wait_for_connection(&run_dir(&temp), BOOT_TIMEOUT); + + kill(connection.pid); + + let status = supervisor.wait_for_exit(EXIT_TIMEOUT); + + assert!( + !status.success(), + "a killed child should end the supervisor with a failure, got {status}" + ); + assert_eq!( + launches(&supervisor.stdout()), + 1, + "a killed child should not be relaunched" + ); +} + +/// A restart whose every launch fails (the config is broken and no `.prev` +/// exists to roll back to) stops after five launches and ends the +/// supervisor with the last child's code. +#[test] +fn a_restart_whose_launches_all_fail_stops_after_five() { + let temp = tempfile::tempdir().unwrap(); + let config = race_config(&temp); + let mut supervisor = GatewayProcess::spawn_headless_launch_capturing(&config, temp.path(), &[]); + + let connection = wait_for_connection(&run_dir(&temp), BOOT_TIMEOUT); + + std::fs::write(&config, "not a config").expect("breaking the config should succeed"); + request_restart(connection.port); + + // Five failed launches with backoffs of 250 ms to 2 s in between. + let status = supervisor.wait_for_exit(BOOT_TIMEOUT); + + assert_eq!( + status.code(), + Some(1), + "an exhausted restart should end the supervisor with the last child's code, got {status}" + ); + assert_eq!( + launches(&supervisor.stdout()), + 6, + "the first boot and five restart launches" + ); +} diff --git a/crates/gateway/app/tests/it/support/process.rs b/crates/gateway/app/tests/it/support/process.rs index c9ede559..0e6a32bc 100644 --- a/crates/gateway/app/tests/it/support/process.rs +++ b/crates/gateway/app/tests/it/support/process.rs @@ -76,12 +76,37 @@ impl GatewayProcess { Self { child } } - /// Starts the production binary as an ordinary headless launch, which + /// An ordinary launch: the supervisor election, so the launched process /// supervises the serving Gateway as its `--supervised` child. Output is /// discarded: the supervisor forwards the child's, and an unread pipe /// would eventually block both. pub(crate) fn spawn_headless_launch(config: &Path, home: &Path, args: &[&str]) -> Self { + Self::headless_launch_command(config, home, args) + .stdout(Stdio::null()) + .spawn() + .map(|child| Self { child }) + .expect("the Gateway launch spawns") + } + + /// [`Self::spawn_headless_launch`] with stdout piped, so a test can read + /// what the supervisor forwarded once it exits. Nothing reads the pipe + /// before then, so the launch must stay brief: a full pipe would block + /// the supervisor's forwarder and then the child. + pub(crate) fn spawn_headless_launch_capturing( + config: &Path, + home: &Path, + args: &[&str], + ) -> Self { + Self::headless_launch_command(config, home, args) + .stdout(Stdio::piped()) + .spawn() + .map(|child| Self { child }) + .expect("the Gateway launch spawns") + } + + fn headless_launch_command(config: &Path, home: &Path, args: &[&str]) -> Command { let mut command = Command::new(env!("CARGO_BIN_EXE_runvil-gateway")); + command .arg("--config") .arg(config) @@ -92,13 +117,9 @@ impl GatewayProcess { .env_remove("RUST_LOG") .env_remove("RUNVIL_PROFILE") .stdin(Stdio::null()) - .stdout(Stdio::null()) .stderr(Stdio::null()); command - .spawn() - .map(|child| Self { child }) - .expect("the Gateway launch spawns") } fn spawn_command(config: &Path, home: &Path) -> Command { diff --git a/vibe/2026-10/2026-10-06-1-restart-to-apply.md b/vibe/2026-10/2026-10-06-1-restart-to-apply.md index 7d2d2286..8311cd4e 100644 --- a/vibe/2026-10/2026-10-06-1-restart-to-apply.md +++ b/vibe/2026-10/2026-10-06-1-restart-to-apply.md @@ -159,15 +159,15 @@ This step only adds the option; nothing passes it yet. Step 4's supervisor is it ## Step 4: Supervisor mode -- New `src/supervisor.rs` + `src/supervisor/` (spawn, loop, rollback): entered for a bare launch, `--login`, and `--no-tray`. The supervisor has no tray and no window in any mode. +- New `src/supervisor.rs` (spawn and loop, with its unit tests in `supervisor-tests.rs`; 4c's rollback makes the group three files, a `src/supervisor/` directory): entered for a bare launch, `--login`, and `--no-tray`. The supervisor has no tray and no window in any mode. - Start: `main` calls `settle_gateway_startup(&app_options, ..)` as today; for a launch that will supervise it runs `launch_or_attach` in the run directory. `OpenSettings` hands off through `main`'s existing arm (opens Settings unless `--login`). `Supervise(lock)` calls `supervisor::run(&app_options, lock)`, which spawns the child and holds the lock until it returns. - The supervisor never starts canonical logging: the child rotates and writes the log file as today, and two processes rotating one file would collide. The supervisor's own messages go to its stderr. - `--print-url` launches stay single-process and unsupervised: a terminal-driven mode with no tray, where Restart to Apply falls back to today's Apply and banner. -- Child spawn: `current_exe()` with `--supervised`; `--no-tray`, `--config`, and `--profile` passed through when the supervisor received them; `--browser` passed to the first child only, so the installer's first run still opens Settings and restarts never do; and `--preferred-port` after the first boot (read from the discovery file). Stdin piped and held open (the watchdog). Stdout and stderr piped; a reader thread per pipe copies every line to the supervisor's own stdout or stderr respectively, so a terminal or service manager sees the child's output as before, and the stderr reader also keeps the last 64 lines for the failure record. Windows adds `CREATE_NO_WINDOW` like `production_command` (`gateway/local/src/server-support.rs:102-106`). +- Child spawn: `current_exe()` with `--supervised`; `--no-tray`, `--config`, and `--profile` passed through when the supervisor received them; `--browser` passed to the first child only, so the installer's first run still opens Settings and restarts never do; and `--preferred-port` after the first boot (read from the discovery file). Stdin piped and held open (the watchdog). Stdout and stderr piped; a reader thread per pipe copies every line to the supervisor's own stdout or stderr respectively, so a terminal or service manager sees the child's output as before; from 4c the stderr reader also keeps the last 64 lines for the failure record. Windows adds `CREATE_NO_WINDOW` like `production_command` (`gateway/local/src/server-support.rs:102-106`). - Loop on child exit: - - 0: the supervisor exits 0. - - `RESTART_REQUESTED`: relaunch, still holding the launch lock. A launch fails when the child exits or does not publish within 30 s. The first failure with `.prev` files present rolls back as in Decisions; every failure relaunches after a backoff from 250 ms doubling, at most 5 launches per restart. Success (the child, having published, has already removed `.prev`) resets the count. - - Anything else, or no publication within 30 s on the first boot: no relaunch. The supervisor exits with the child's code (1 when the child died by a signal, or published nothing and was stopped), having logged the child's last stderr lines and printed them on its own stderr. + - 0: the supervisor exits 0. A child that exits 0 before publishing has handed off to a gateway it found serving, and the supervisor exits 0 with it. + - `RESTART_REQUESTED`: relaunch, still holding the launch lock. A launch fails when the child exits or does not publish within 30 s (a child that times out is killed). A publication counts only when the discovery file names the new child's pid, not the one the last child left behind. A child that exits to restart leaves its discovery file in place (the guard's `keep`), and the supervisor checks for publication before checking for exit. Together these mean a child that publishes, is asked to restart, and exits within a single poll still counts as published, with its port carried over. Without them the supervisor read that case as a failed first boot and exited 75, which Windows CI hit. The next child overwrites the left file, and the launch lock keeps other launchers from deleting it in the gap. The first failure with `.prev` files present rolls back as in Decisions; every failure relaunches after a backoff from 250 ms doubling, at most 5 launches per restart. Success (the child, having published, has already removed `.prev`) resets the count. + - Anything else, or no publication within 30 s on the first boot: no relaunch. The supervisor exits with the child's code (1 when the child died by a signal, or published nothing and was stopped). The child's stderr has already reached the supervisor's own through the forwarder, so the supervisor prints nothing more. - Failure record: on rollback the supervisor writes `restart-failure.json` in the run directory (`{"at", "exit", "stderr_tail"}`); the next child reads and deletes it at boot and reports it once in `/admin/status` as `restart_failure`. - Ctrl-C in headless mode stops the child through `request_shutdown` (`gateway-api-discovery/src/shutdown.rs`) and waits, then exits. - Integration tests (`tests/it/boot/supervisor.rs`, real binary):