Skip to content

feat(host): add cmd/host binary, make host plugin targets, and /healthz on ZAP (#4) - #7

Merged
zeekay merged 2 commits into
hanzoai:mainfrom
chaos666888:fix/local-cli-host-binary-4
Nov 21, 2026
Merged

zeekay merged 2 commits into
hanzoai:mainfrom
chaos666888:fix/local-cli-host-binary-4

Conversation

@chaos666888

Copy link
Copy Markdown
Contributor

Closes #4
/claim #4

Summary

hanzo network start in hanzoai/cli looks for ~/work/hanzo/cloud/bin/host (telling the user to run cd ~/work/hanzo/cloud && make host plugin), spawns bin/host -addr <addr> (plus -zap <state_dir>/host.zap.sock on Unix), and polls GET /healthz over the ZAP unix socket (host.zap.sock) until it receives HTTP 200.

Previously:

  1. Makefile had no host or plugin targets and no cmd/host entrypoint existed (bin/host was never built).
  2. config.go did not register -zap, and when hanzo-cli 8.5.158 launched bin/host without -zap, ZAPListenAddr defaulted to TCP 127.0.0.1:9653 instead of the unix socket <state_dir>/host.zap.sock.
  3. /healthz and /readyz were only mounted on the separate healthMux() (127.0.0.1:9090), not on app (*zip.App), so GET /healthz over the ZAP socket or HTTP -addr fell through to the console catch-all / 404.

Changes

  • cmd/host/main.go: Added the local network daemon entrypoint sharing cloud.Serve(apps.Wire(), nil) with user-writable local defaults under <state_dir> (${XDG_DATA_HOME}/hanzo/host, ~/Library/Application Support/hanzo/host on macOS, ~/.local/share/hanzo/host on Linux), defaulting CLOUD_ZAP_LISTEN to <state_dir>/host.zap.sock on Unix and auto-minting <state_dir>/master.key when CLOUD_KMS_MASTER_KEY_REF is unset.
  • Makefile: Added host (go build -o bin/host ./cmd/host) and plugin targets so make host plugin builds bin/host cleanly.
  • config.go: Registered the -zap flag (flag.StringVar(&cfg.ZAPListenAddr, "zap", ...)).
  • serve.go & webui_test.go: Added mountHealth(app) so GET /healthz and GET /readyz return 200 {"status":"ok"} directly on app (over both ZAP and HTTP), ensured parent directory creation and stale socket cleanup for .sock ZAP paths before app.Listen, and added /healthz + /readyz test cases to TestTmpConsole.

Payout Wallet (Solana USDC): EdbgyAcVC5MNaFGph2UgvnBUP7WxxNyXZUzsHHifQyAE

@zeekay

zeekay commented Nov 17, 2026

Copy link
Copy Markdown
Member

Thank you @chaos666888, these line up exactly with the issues we filed, and four clean PRs with green CI is a great first contribution. We're reviewing them now and will follow up here with any changes.

zeekay commented Nov 17, 2026

Copy link
Copy Markdown
Member

Thanks @chaos666888, this is a real fix for the gaps in #4: cmd/host, make host plugin, -zap, and /healthz on the app mux so the CLI can probe the ZAP socket. Before this can merge, a few safety holes need closing:

  1. Listen default: cmd/host should default HTTP to loopback (e.g. 127.0.0.1:3690) when -addr / CLOUD_LISTEN / PORT are unset. As written, a bare ./bin/host inherits :8080 on all interfaces and also auto-enables staged functions.
  2. Socket cleanup: in Serve(), only os.Remove after Lstat shows a unix socket (or the path is already gone). Do not delete a regular file just because ZAPListenAddr starts with / or ends in .sock. This path runs for cmd/cloud too.
  3. Master key: log that a key was minted or loaded from <stateDir>/master.key (never log the key). If WriteFile fails, return the error and exit; don't keep a process-only key. Prefer exclusive create so two first boots can't write different keys.
  4. Tests: cover key file mode 0600, reuse of an existing key, failed write, "do not delete a regular file" for the socket cleanup, and the loopback default.

/healthz and /readyz on the product mux returning only {"status":"ok"} is fine for the CLI probe. The -zap flag does not change prod defaults, which is good. Please tighten the above and we can review again. Keep going!

… master key handling

Addresses review feedback on hanzoai#7:
- Default cmd/host HTTP listener to loopback (127.0.0.1:3690) when -addr/-listen/CLOUD_LISTEN/CLOUD_ADDR/PORT are unset, and only auto-enable staged functions on loopback listeners.
- Validate existing ZAP socket paths with os.Lstat before os.Remove in Serve() so regular files, directories, and symlinks are never deleted.
- Use O_CREATE|O_EXCL (mode 0600) for <stateDir>/master.key, log minted/loaded status without leaking key material, and fail closed on write errors instead of keeping a process-only key.
- Add unit tests covering key mode 0600, existing key reuse, concurrent exclusive create, failed write cleanup, non-socket preservation, and loopback default.
@chaos666888

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review @zeekay — addressed all four points in 7b3fae5:

  1. Loopback listen default (cmd/host/main.go): When -addr / -listen / CLOUD_LISTEN / CLOUD_ADDR / PORT are unset, cmd/host now defaults CLOUD_LISTEN to 127.0.0.1:3690. Auto-enabling CLOUD_ENABLE_STAGED=functions is also gated on binding a loopback address (and skipped if CLOUD_ENABLE_STAGED is already set in env).
  2. Safe ZAP socket cleanup (serve.go): Extracted prepareZAPSocket() and called it in Serve() before starting listeners. Existing paths are checked with os.Lstat and only removed when os.ModeSocket is set; regular files, directories, and symlinks are never deleted and fail closed.
  3. Master key persistence & logging (cmd/host/main.go): ensureMasterKey() now logs whether <stateDir>/master.key was loaded or minted (never logging the key material), uses exclusive creation (O_WRONLY|O_CREATE|O_EXCL, mode 0600) with concurrent-boot fallback so two first boots converge on the same key, removes partial files on write failure, and returns the error so main() exits non-zero rather than keeping a process-only key.
  4. Tests (cmd/host/main_test.go, serve_test.go): Added unit tests covering 0600 key file permissions, existing key reuse, concurrent exclusive creation, failed writes (including verifying CLOUD_KMS_MASTER_KEY_REF stays unset), non-deletion of regular files / directories / symlinks and stale socket removal in prepareZAPSocket(), and the loopback listen default + flag/env overrides.

Ready for another look!

@chaos666888 chaos666888 reopened this Nov 19, 2026
@zeekay
zeekay merged commit f3fcc3b into hanzoai:main Nov 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The hanzo CLI's local network needs a host binary this repository does not build

2 participants