fix(hub): wait for daemon readiness in SEA mode before success#66
Merged
Conversation
- In SEA builds, `--daemon` re-execs the binary with CLI argv [`start`, `--port`, N] instead of spawning a non-existent ./main.js sibling - New `daemon-launch.ts` exports buildDaemonSpawnPlan (spawn plan per mode), waitForDaemonReady (polls runtime.json then GETs /api/health), and log-tail utilities - CLI daemon branch now writes child stdout/stderr to hub-daemon.log, polls for readiness, and exits non-zero with daemon log tail on failure - Fixes silent spawn failure where stdio: "ignore" swallowed errors and success was printed before daemon proved reachable (#60)
Use the ChildProcess handle for daemon termination instead of a raw process.kill(pid) to prevent hitting an unrelated process if the OS reuses the pid. Also consolidate the health-check timeout into a single constant to keep both bounds (fetch AbortSignal and race timeout) in sync.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #60
Summary
termora-hub start --daemon(SEA build) used to print success and exit 0 while the daemon died instantly: it spawned a non-existent./main.jssibling,stdio: "ignore"swallowed the error, and there was no readiness check.--daemonre-execs the binary with CLI argv (start --port N) instead of spawning a JS path; dev keeps themain.jssiblingdaemon-launch.ts:buildDaemonSpawnPlan(spawn plan per mode) +waitForDaemonReady(pollsruntime.jsonfor the child pid, then/api/healthon the actual port — zero_conf safe)hub-daemon.login the state dir (truncated per start, chmod 600); failures print the child's exit code or timeout with a bounded log tail and exit non-zeroTest plan
daemon-launch.spec.ts(spawn plan per mode, ready/child-died/timeout paths, stalled health probe, log tail bounding, log truncation + permissions)@termora/hubbuild green; biome clean on touched filesceb2bb1):start --daemon→Hub daemon ready,/api/healthok,hub-daemon.logis-rw-------,stopkills the daemon; failure injection (broken config dir) → exit 1 withDaemon process exited before readiness (code 1…)+ log tail, no false success