Skip to content

fix(lifecycle): harden cross-OS state transitions, path normalization, and canonical CLI QA - #123

Merged
zeekay merged 2 commits into
hanzoai:mainfrom
tranhoangtu-it:feat/canonical-lifecycle-qa-112
Nov 29, 2026
Merged

zeekay merged 2 commits into
hanzoai:mainfrom
tranhoangtu-it:feat/canonical-lifecycle-qa-112

Conversation

@tranhoangtu-it

Copy link
Copy Markdown
Contributor

Summary

Closes #112
/claim #112

  • Cross-OS project path normalization (src/commands/lifecycle/project.rs, src/commands/lifecycle/mod.rs): Add normalize_project_dir() (canonicalizing paths and stripping Windows \\?\ / \\?\UNC\ verbatim prefixes) and use it in detect_project, resolve_registered_app (matching both incoming cwd and persisted project_dir), env_up, and env_down.
  • Canonical workload drain on down --all-workloads and stop (src/commands/lifecycle/mod.rs): Clear state.platform.engine_enabled and run engine::down().await alongside app cleanup when hanzo down --all-workloads executes (keeping k3s/VM warm), and call engine::down().await inside runtime_stop().
  • Accurate ps / status reporting (src/commands/lifecycle/status.rs): Extract shared app_ps_row() so ps, build_local_ps_rows, and build_local_ps_rows_with_hanzod use node_port vs container_port consistently and do not mark stopped host-process apps (image: None with dead or absent local_pid) as "Running" simply because k3s is active.
  • Hermetic canonical CLI lifecycle QA suite (tests/canonical_lifecycle_qa.rs): Verify start, up, restart, down, stop, reset CLI help/command surfaces, ps --json, status --local, doctor --offline, down --all-workloads warm-cache preservation vs Unix reset teardown, plus unit tests in project.rs and status.rs. Keeps zero file overlap with open PRs #121 and #122.

Canonical CLI Command Timings (WSL2 Ubuntu Linux, target/debug/hanzo)

Command Wall-clock (ms) Notes
hanzo start --help 57.89 CLI surface & subcommand help
hanzo up --help 56.58 CLI surface & subcommand help
hanzo restart --help 56.65 CLI surface & subcommand help
hanzo down --help 50.40 CLI surface & subcommand help
hanzo stop --help 48.57 CLI surface & subcommand help
hanzo reset --help 53.72 CLI surface & subcommand help
hanzo ps --json 1061.96 Verified dead-PID host app=Stopped, container app port=31222
hanzo status --local 1058.53 3-layer local snapshot exit 0
hanzo doctor --offline 1399.50 Local host/runtime diagnostics exit 0
hanzo down --all-workloads 452.11 Cleared cloud_enabled, engine_enabled, desired_running; preserved warm-cache.sentinel
hanzo stop 434.25 Graceful runtime drain while preserving config
hanzo reset 1059.21 Cleared isolated HANZO_LIFECYCLE_DIR and ~/.hanzo/up

Verification (WSL2 Linux x86_64)

  • rustfmt --edition 2021 --check tests/canonical_lifecycle_qa.rs (0 diff; new additions in lifecycle/{project,mod,status}.rs also clean)
  • cargo clippy --locked --all-targets -- -D warnings (passed, 0 warnings)
  • cargo test --locked --bin hanzo (529 passed; 0 failed; 0 ignored)
  • cargo test --locked --test canonical_lifecycle_qa -- --nocapture (1 passed; 0 failed)
  • Windows note: On unmodified origin/main, Windows cargo test hits a pre-existing E0282 type-inference error on let mut shape = None; at src/commands/up/diagnose.rs:142; left untouched on this branch to avoid overlapping open PR #121.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-28T16:02:52.358992Z
We couldn’t complete this review. Comment @codex review to try again.
0c1e2e3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@tranhoangtu-it

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest main (d6686fc), preserving engine::down() and runtime_stop checkpoint/hanzod coordination, and verified commands::lifecycle tests pass.

@tranhoangtu-it
tranhoangtu-it force-pushed the feat/canonical-lifecycle-qa-112 branch from 0c1e2e3 to 5ee256d Compare November 29, 2026 00:53
@zeekay

zeekay commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks for rebasing onto d6686fc (v8.5.1495)! The normalize_project_dir Windows \\?\ / \\?\UNC\ fix in project.rs and the app_ps_row dead-host-PID / node_port fix in status.rs are great catches. However, tests/canonical_lifecycle_qa.rs and the unconditional engine::down() calls still have host-safety side effects that block merging as-is:

  1. Make tests/canonical_lifecycle_qa.rs strictly hermetic: Running hanzo down --all-workloads, hanzo stop, and hanzo reset during cargo test currently:
    • contacts any live hanzod daemon on loopback (127.0.0.1) with POST /v1/lifecycle/reset and stop;
    • invokes systemctl --user stop hanzo-router.service on the host machine via engine::down();
    • probes host PATH binaries in hanzo doctor --offline and native k3s on Linux;
    • seeds "local_pid": 999999999u32, causing stop_registered_app_instance (up::stop) to call kill(999999999, SIGTERM) on an unowned PID.
      Please isolate/disable loopback hanzod, systemctl, native k3s, and PATH in the test, and never seed an unowned PID that gets signaled (spawn and reap an owned child process if testing PID termination).
  2. Guard engine::down() behind engine_enabled: In src/commands/lifecycle/mod.rs (runtime_stop() and env_down()), let _ = engine::down().await; runs unconditionally even when state.platform.engine_enabled was false. Capture let was_engine_enabled = state.platform.engine_enabled; before clearing state and only call engine::down().await when was_engine_enabled is true.

@tranhoangtu-it
tranhoangtu-it force-pushed the feat/canonical-lifecycle-qa-112 branch from 5ee256d to 1374587 Compare November 29, 2026 02:15
@tranhoangtu-it

tranhoangtu-it commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @zeekay for catching both host-safety issues! Resolved in 95407870 (rebased onto origin/main at 37f7df43):

  1. Strictly hermetic tests/canonical_lifecycle_qa.rs: Added hermetic_test_mode() (HANZO_HERMETIC_TEST=1) to isolate loopback hanzod, host systemctl, native k3s, telemetry (DO_NOT_TRACK=1, HANZO_TELEMETRY=0), and PATH (empty_bin), and replaced the unowned PID with an owned short-lived/sleeper child process reaped cleanly during teardown.
  2. Guarded engine::down().await behind was_engine_enabled: Captured let was_engine_enabled = state.platform.engine_enabled; in both runtime_stop() and env_down() (src/commands/lifecycle/mod.rs) before clearing state so engine::down() only runs when the engine was enabled.

Verified on Linux (WSL2): commands::lifecycle (29 passed) and tests/canonical_lifecycle_qa (1 passed in 7.64s).

@tranhoangtu-it
tranhoangtu-it force-pushed the feat/canonical-lifecycle-qa-112 branch 2 times, most recently from 9540787 to 4d0ef6a Compare November 29, 2026 16:42
@zeekay
zeekay force-pushed the feat/canonical-lifecycle-qa-112 branch from 4d0ef6a to b948fdb Compare November 29, 2026 20:10
@zeekay

zeekay commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks @tranhoangtu-it for making canonical_lifecycle_qa completely hermetic and gating engine::down() on was_engine_enabled! Rebased onto main alongside #121 and #122 (aligning doctor/host.rs with up::home_root() and hermetic_test_mode()), and verified cargo clippy --locked --all-targets -- -D warnings, read-only HOME (chmod 0555), and empty-writable-HOME gates all pass cleanly. Merging!

@zeekay
zeekay merged commit 606761d into hanzoai:main Nov 29, 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.

[Intern] Cross-OS canonical CLI lifecycle QA (start/up/ps/down/restart/stop/reset)

2 participants