fix(broker): verify worker process before spawn success

Merged
KH
4mo ago
+1668-137

Fixes the silent `node agent spawn` failure hit repeatedly today across 3 machines: the CLI reports "Spawned X (codex, pty)." success while the spawned worker process has already exited (e.g. a wrapper that can't launch its harness) — `Command::spawn` only proves the wrapper was created, not that it survived.

Adds a brief (250ms) stability window after spawn that non-blockingly checks the child is still alive via `try_wait()` before reporting success. If it already exited, the stale registry entry is removed and the real error (exit status + log path) is returned instead of letting `node agent list` briefly advertise a dead process.

Companion fix for Bug A (workspace-enrollment precedence overriding an explicit `RELAY_WORKSPACE_KEY`) is being worked separately.

Test plan

  • `cargo test --package agent-relay-broker worker::` — 62/62, 4 consecutive clean runs
  • Real integration test: `RELAY_INTEGRATION_REAL_CLI=1 node --test tests/integration/broker/dist/cli-spawn.test.js` — missing-CLI rejection path, 21.5s, real broker, confirms no stale agent is listed