Skip to content

up --local: Cloud from this machine's source, on a runtime with a budget - #119

Merged
zeekay merged 5 commits into
mainfrom
local-cloud
Nov 28, 2026
Merged

zeekay merged 5 commits into
mainfrom
local-cloud

Conversation

@dissoupov

Copy link
Copy Markdown
Contributor

What this does

hanzo up --local runs Cloud from the source on this machine, and the local runtime gets a resource budget, an account of its own and a data volume. Four faults met on one runtime, each fixed where it starts. The bus side is hanzoai/cloud#87.

Fault Cause Fix
A local build was never what ran hanzo up only deploys a published image up --local: run the directory's declared build, load the OCI layout into the node's containerd, deploy that exact name with imagePullPolicy: Never
A local image was replaced by the published one after hanzo down, Kubernetes omits spec.replicas: 0 from the Scale object, which was read as "no Deployment" a scale of zero is a Deployment; an up changes the image only when it names one
Insufficient memory on every first boot the request was half the vm, so two pods never fit, and the supervisor deleted the first pod because it was created before its pull secret request is half of what the node does not keep for itself; the workload is applied after its credentials
is forbidden: User "system:serviceaccount:hanzo:default" Cloud ran as the default account its own account hanzo/cloud, granted the four reads Cloud makes
Data lost on hanzo down the volume was an emptyDir a volume claim; the Deployment is replaced, not merged
26 GB left per hanzo stop a vm stopped by signal keeps its disk stop runs hanzo-vm prune

up --local

The directory's hanzo.config.json declares the build: "local": {"build": "<command>", "image": "<OCI layout dir>"}. --local=<dir> names a layout directly and builds nothing.

  • It does not fall back. Nothing on this path resolves a name against a registry. A failed build ends the command; the Deployment is written only once the node holds the image; an absent image is ErrImageNeverPull. A local image must be named under hanzo.local/, which no registry answers to.
  • The control socket (up/control.rs, ~/.hanzo/up/control.sock, 0600). The supervisor is the only process that can run a command in the guest, so it answers three named operations between looks at its vm: load, prune, facts. Never a command a caller wrote. A runtime booted by an older hanzo has no socket, and --local says to restart it once.
  • Loading (up/load.rs). ctr content ls says what the node holds; only the layers it lacks are sent, in imports of about 256 MiB, and the last import names and unpacks the image. Verified on k3s v1.37.2 / containerd 2.3.7 that an archive without layers the store already has imports cleanly.

Budget, account, doctor

  • up/budget.rs: on the 4 GiB default Cloud requests 1664 MiB (was 2048), floor 1536, and a runtime under 3840 MiB is refused with the arithmetic. The bus is told its file store through CLOUD_PUBSUB_MAX_STORE. On a warm runtime the shape comes from the supervisor, not the flags of the later invocation.
  • up/manifest.rs ground: namespaces, the cloud ServiceAccount, its grants and the volume claim. Grants: pods list+watch cluster-wide, jobs list in hanzo and hanzo-build, apps.hanzo.ai list in hanzo. No write verb.
  • up/diagnose.rs: hanzo doctor prints a runtime section: shape, budget, host memory beside the runtime's, node disk, image provenance, whether two pods fit, whether data is on a claim, each grant asked of the API server by SubjectAccessReview, and refused stream declarations in the pod's log.

Measured (Linux x86-64, 4 GiB / 32 GiB runtime, hanzo-inc/cloud)

Before After
Stopped runtime to Cloud answering 36m57s (published image pull) 120–180 s
One app edited, to running not possible 26 s
hanzo down then hanzo up data lost 17 s, same image and data
Refused Kubernetes requests in the pod log 1,597 in two hours 0
Insufficient memory events every first boot 0

Tests

cargo clippy --bin hanzo is clean. 514 unit tests and the integration suites pass. spec_drift fails here and on main as cloned (spec/live.json and .spec-lock name different releases); this branch touches neither file.

Not tested, and limits

  • macOS and arm64. Nothing was run on either.
  • A published image through to running. The changed boot path was run up to the pull (one pod, secret already on its account, no 401, no memory warning), not through the download.
  • hanzo restart restoring a local build, --local=<layout>, the native-k3s refusal: unit tests only.
  • Data does not survive hanzo stop. hanzo-vm 2.0.2 boots every vm from the checkpoint and keeps no disk (--rootfs is copied and discarded, measured).
  • Load speed. hanzo-vm 2.0.2 breaks its stdio wire on a 1 MiB message, so the transfer goes in 512 KiB parts at about 37 MiB/s: 90–100 s for a 3.3 GB first load. A forwarded port would be several times faster.
  • The source change is one large commit plus a follow-up; the pieces share files and were not split by hunk.

🤖 Generated with Claude Code

dissoupov and others added 3 commits November 27, 2026 15:39
Four faults met on one local runtime, each fixed where it starts.

A local build was not what ran. `hanzo up` deploys a published image;
`--local` builds the directory's declared image (hanzo.config.json `local`),
has the supervisor load the OCI layout into the node's containerd, and writes
a Deployment that names it exactly with imagePullPolicy Never. Nothing on that
path resolves a name against a registry, so there is no published image it
can fall back to. The supervisor answers a control socket for this (load,
prune, facts): it is the only process that can reach the guest. Layers the
node already holds are not sent again.

The scheduler answered Insufficient memory. Cloud requested half the vm, so
two pods never fit, and the supervisor deleted the first pod on every boot
because it had been created before its pull secret. The request is now half
of what the node does not keep for itself, and the workload is applied after
its credentials, so there is no first pod to delete.

Cloud ran as the namespace's default account and was refused three reads.
It runs as hanzo/cloud, granted those reads and nothing else; doctor asks the
API server about each.

Its data was an emptyDir, gone with every `hanzo down`. It is on a volume
claim, and the Deployment is replaced rather than merged so the old volume
does not linger beside the new one.

Also: `hanzo up` after `hanzo down` read a Deployment scaled to zero as no
Deployment (Kubernetes omits spec.replicas when it is 0) and deployed the
default image over whatever the stopped one named. An `up` now changes the
image only when it names one. `hanzo stop` prunes the stopped vm's disk,
which was left behind whole. `hanzo doctor` prints the runtime's shape,
budget, image provenance, grants and refused stream declarations. The bus is
told its file store (CLOUD_PUBSUB_MAX_STORE).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A load staged the whole archive on the node before importing it, so a build
that changed every layer needed the old image, the new one and the archive
at once and missed fitting a 32 GiB disk by a hair. Layers now travel in
imports of about 256 MiB; every import but the last only stores, and the last
names and unpacks the image. That last import always runs, also when no layer
is new: holding every layer is not having unpacked them.

The deploy plane's health lists apps.hanzo.ai in its own namespace. Granted,
a cluster with no such kind answers 404 where it answered 403.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@dissoupov
dissoupov requested review from zeekay and a lite review from Copilot November 27, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change still has two active moderate issues in local-build state handling that can cause restarts or resizes to use stale runtime settings and a prior published image.

2 open issues
What changed in this PR

Adds hanzo up --local support so Cloud can be built from the current machine, loaded directly into the microVM's containerd, and deployed with imagePullPolicy: Never. It also updates runtime supervision, lifecycle persistence, Kubernetes identity and storage setup, cleanup, and doctor diagnostics.

Changes:

  • Adds --local[=LAYOUT] CLI handling and local build/layout resolution.
  • Adds runtime control operations, deferred workload deployment, and VM pruning.
  • Persists local-build state, applies resource budgets and persistent storage, and reports runtime health through hanzo doctor.
File Description
src/​main.rs Adds the --local option to hanzo up with its relevant conflicts.
src/​commands/​vm.rs Adds VM disk pruning and guest file-transfer helpers.
src/​commands/​up/​supervisor.rs Applies runtime ground and workload manifests in order and serves the runtime control socket.
src/​commands/​lifecycle/​resources.rs Restores local Cloud layout information when reconstructing runtime state.
src/​commands/​lifecycle/​project.rs Persists local-build metadata and recognizes the Cloud source checkout.
src/​commands/​lifecycle/​mod.rs Implements local environment startup and local-image restoration during lifecycle operations.
src/​commands/​doctor.rs Adds local runtime resource, image, access, and configuration diagnostics.
src/​cli_dispatch.rs Validates and forwards local-mode arguments into lifecycle handling.

Review effort: Lite

Comment on lines +439 to +441
state.runtime.desired_running = true;
state.platform.cloud_enabled = true;
state.platform.cloud_local = Some(layout);
let mut state = load_state().unwrap_or_default();
state.runtime.desired_running = true;
state.platform.cloud_enabled = true;
state.platform.cloud_local = Some(layout);
…eadiness

- Quiesce k3s and workloads via control.sock Request::Stop (cordoning the node
  so Deployment.spec.replicas stays intact, draining pods so SQLite WAL and
  NATS JetStream flush cleanly, stopping k3s/containerd, and checkpointing the
  live ext4 disk via hanzo-vm stdio RPC to k3s-<ver>-state.ext4 via atomic
  staging rename so macOS clonefile never hits EEXIST).
- Resume from k3s-<ver>-state on hanzo start and hanzo up when present,
  clamping --disk-size to at least the saved ext4 image, uncordoning the node,
  preserving bound PVC size in GROUND, and keeping hanzo.local/* images and
  KMS secrets across stop/start without falling back to published images.
- Sweep ~/.hanzo/vm/instances/<vm_pid> on supervisor exit and signal fallback
  so 26-32 GiB transient disks never leak; wipe k3s-<ver>-state on hanzo reset.
- Reconcile PR #114 fixes: discover project hanzo.config.{json,ts} before warm
  reuse, treat --strict-registry as a warm workload override, plant registry
  pull secrets on warm/resumed clusters, separate runtime-ready from ready, and
  wait for Deployment generation + ready/available replicas.
@zeekay
zeekay merged commit 2521889 into main Nov 28, 2026
1 check passed
@zeekay
zeekay deleted the local-cloud branch November 28, 2026 04:39
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.

3 participants