Skip to content

feat(lifecycle): validate resource flags and improve runtime prerequisite errors - #122

Merged
zeekay merged 3 commits into
hanzoai:mainfrom
tranhoangtu-it:feat/audit-lifecycle-flags-and-prereqs-110
Nov 29, 2026
Merged

zeekay merged 3 commits into
hanzoai:mainfrom
tranhoangtu-it:feat/audit-lifecycle-flags-and-prereqs-110

Conversation

@tranhoangtu-it

@tranhoangtu-it tranhoangtu-it commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Audits lifecycle resource flags (--cpus, --memory, --disk / --disk-size, --cloud-only, --vm, --all-workloads) and surfaces actionable prerequisite remediation errors across hanzo start, hanzo up, hanzo restart, hanzo down, and hanzo vm.

Closes #110
/claim #110

Changes

  • Resource flag validation (src/commands/lifecycle/units.rs, src/main.rs, src/commands/lifecycle/resources.rs):
    • Added parse_cpus (1..=256), parse_memory_mb (>= 256 MiB), and parse_disk_mb (>= 1 GiB / 1024 MiB) with clear boundary error messages and applied them across Up, Start, Restart, VmLifecycleCommand::Start, and VmLifecycleCommand::Resize.
  • Mutually exclusive down scopes (src/main.rs, src/cli_subcommands.rs, src/cli_dispatch.rs):
    • Added conflicts_with_all between --vm, --cloud, and --all-workloads on hanzo down and aligned hanzo up down to expose the same scope flags.
  • Runtime prerequisite remediation (src/commands/vm.rs, src/commands/up.rs, src/commands/up/kube.rs):
    • Generalized Linux /dev/kvm checks across x86_64 and aarch64 (modprobe kvm, usermod -aG kvm $USER && newgrp kvm), added macOS Virtualization.framework / entitlement preflight checks (check_macos_virtualization_host), invoked vm::preflight_host() before downloading or booting checkpoints in up::up and up::start, added an explicit WSL2/native guidance error for hanzo start on Windows, added PermissionDenied remediation when adopting /etc/rancher/k3s/k3s.yaml, and wrapped stale/malformed KubeClient::from_kubeconfig errors with rm -f ... && hanzo start recovery commands.
  • Unit tests (src/main_lifecycle_tests.rs, src/commands/lifecycle/tests.rs, src/commands/vm/tests.rs, src/commands/up/tests.rs):
    • Added coverage for --cpus, --memory, --disk, --cloud-only, --vm/--cloud/--all-workloads conflicts, Linux/macOS virtualization preflight errors, native kubeconfig permission errors, and corrupt/missing kubeconfig remediation.

Reproducible Build & Test Output (WSL2 Linux x86_64)

$ cargo test --locked --workspace --lib
hanzo-client: 3 passed; 0 failed
hanzo-event:  8 passed; 0 failed
hanzo-identity: 28 passed; 0 failed
hanzo-cli (bin): 529 passed; 0 failed

$ cargo test --locked --test cli && cargo test --locked --test cloud_sessions && cargo test --locked --test feedback_flows && cargo test --locked --test refresh && cargo test --locked --test shell && cargo test --locked --test auth && cargo test --locked --test build
cli: 27 passed; 0 failed
auth: 7 passed; 0 failed
cloud_sessions: 4 passed; 0 failed
feedback_flows: 4 passed; 0 failed
refresh: 2 passed; 0 failed
shell: 3 passed; 0 failed
build: 0 passed; 0 failed; 1 ignored

$ cargo clippy --locked --all-targets -- -D warnings
Finished dev profile [unoptimized + debuginfo] target(s) in 13.03s (0 warnings)

@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-28T12:46:01.344164Z
We couldn’t complete this review. Comment @codex review to try again.
234c7c4 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
tranhoangtu-it force-pushed the feat/audit-lifecycle-flags-and-prereqs-110 branch 2 times, most recently from 23a00fc to 424f07d Compare November 29, 2026 00:52
@tranhoangtu-it

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto latest main (d6686fc) and verified commands::up (35/35) and commands::lifecycle unit tests pass.

@tranhoangtu-it
tranhoangtu-it force-pushed the feat/audit-lifecycle-flags-and-prereqs-110 branch from 424f07d to 0b703fa Compare November 29, 2026 01:47
@zeekay

zeekay commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks for rebasing onto d6686fc (v8.5.1495)! Good coverage on --cpus bounds (1..=256), down / up down scope flag conflicts (--vm, --cloud, --all-workloads), /etc/rancher/k3s/k3s.yaml PermissionDenied hints, and Linux aarch64 + macOS Virtualization.framework preflight errors. Two items to resolve before we can merge:

  1. Align memory/disk minimums with src/commands/up/budget.rs: src/commands/lifecycle/units.rs introduces MIN_MEMORY_MB = 256 and MIN_DISK_MB = 1024, whereas src/commands/up/budget.rs is the single source of truth for node sizing (SYSTEM_MB = 768 for kernel + k3s + containerd on bare runtime start/resize; MEMORY_MIN_MB = 3840 and DISK_MIN_MB = 16384 when deploying Cloud via up). Allowing hanzo up --memory 256MiB --disk 1GiB to pass CLI flag validation only to fail inside up::budget::plan creates competing thresholds — use >= budget::SYSTEM_MB (768 MiB) for bare runtime start/resize and align up minimums with budget.rs (updating the parser tests accordingly).
  2. Keep src/commands/up/tests.rs under 1,000 lines: After the rebase onto v8.5.1495, src/commands/up/tests.rs is 1,012 lines (up.rs and up/kube.rs are also close to the limit). Please split or place the new kubeconfig adoption / stale-kubeconfig tests in a dedicated submodule so all files stay well below 1,000 lines.

@tranhoangtu-it

tranhoangtu-it commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @zeekay for the detailed review! Both items are resolved in 7a831e67 (rebased onto origin/main at 37f7df43):

  1. Aligned memory/disk minimums with up::budget.rs: MIN_MEMORY_MB in src/commands/lifecycle/units.rs now references budget::SYSTEM_MB (768 MiB) for bare runtime start/resize/restart, and parse_up_memory_mb / parse_up_disk_mb enforce budget::MEMORY_MIN_MB (3840 MiB) and budget::DISK_MIN_MB (16384 MiB) on hanzo up, with updated unit tests in src/commands/lifecycle/tests.rs.
  2. Kept all files well under 1,000 lines: moved the native-linux kubeconfig adoption helpers into src/commands/up/diagnose.rs (583 lines; src/commands/up.rs is 948 lines) and split kubeconfig/KubeClient tests into src/commands/up/tests/kubeconfig.rs (161 lines; src/commands/up/tests.rs is 882 lines).

Verified cleanly with cargo clippy --locked --all-targets -- -D warnings plus commands::up::tests (40/40), commands::lifecycle (26/26), and commands::vm::tests (15/15 on Linux / WSL2).

@tranhoangtu-it
tranhoangtu-it force-pushed the feat/audit-lifecycle-flags-and-prereqs-110 branch 2 times, most recently from 7a831e6 to cda025d Compare November 29, 2026 16:42
@zeekay
zeekay force-pushed the feat/audit-lifecycle-flags-and-prereqs-110 branch from cda025d to d48dc40 Compare November 29, 2026 20:05
@zeekay

zeekay commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks @tranhoangtu-it for aligning the up/start thresholds with budget.rs and splitting up/tests/kubeconfig.rs cleanly! Pushed one small follow-up updating src/main_lifecycle_tests.rs to match the 3840 MiB / 16 GiB (up) and 768 MiB / 1 GiB (start) thresholds. Verified cargo clippy --locked --all-targets -- -D warnings and 566/566 unit tests under read-only HOME. Merging!

@zeekay
zeekay merged commit 311a70a 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] Audit hanzo start / hanzo up / hanzo down resource flags & prerequisite error messages

2 participants