Skip to content

perf(vm): resolve a cached digest-pinned bootstrap image without a preparation worker - #6057

Closed
balajinvda wants to merge 2 commits into
ai-openshell:mainfrom
balajinvda:perf/6055-vm-cached-image-without-worker/balajinvda
Closed

balajinvda wants to merge 2 commits into
ai-openshell:mainfrom
balajinvda:perf/6055-vm-cached-image-without-worker/balajinvda

Conversation

@balajinvda

@balajinvda balajinvda commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A create whose image is the bootstrap image, pinned by digest, with its root disk cached and no local container engine, started an image preparation worker that only read the cache. The driver now resolves that case in its own process, with the same plan, logs and events; every other case keeps the worker unchanged.

Related Issue

Closes #6055

Changes

  • Includes perf(vm): hash the guest runtime identity at build time, cherry-picked from perf(vm): stop repeating per-launch bookkeeping before the VM starts #6056 (ea6c298), so this PR stands alone: cached_digest_pinned_image_plan calls bootstrap_image_cache_identity on the driver's async runtime, and without that commit sandbox_guest_runtime_identity() hashes every embedded blob there on each eligible create. With it the identity is a build-time constant (same value, so cached root disks stay valid). Whichever of perf(vm): stop repeating per-launch bookkeeping before the VM starts #6056 and this PR lands second drops that commit on rebase.
  • prepare_images_in_worker first asks cached_digest_pinned_image_plan. It returns a plan only when: no rootfs tar; a bootstrap image is configured; the requested image is the bootstrap image (or the request is bootstrap-only); the sandbox is registered, not deleting and not already preparing; the reference is not a local build image and carries a digest; the root disk image_cache_rootfs_image(bootstrap_image_cache_identity(digest)) exists; registry_auth succeeds; and no local container engine answers. These are the conditions under which the worker answers from the cache without a registry call since fix(vm): boot a digest-pinned image from the cache without a registry call #4582.
  • On that path it emits what the worker emitted, in order, under the same vm.resolve_bootstrap_image span: the no local container engine available warning, ensuring cached root disk image (registry), root disk image cache hit (digest-pinned, no registry call), and publish_registry_cache_hit (Pulling, CacheHit, Pulled).
  • Every other case returns None before any log or event and goes to the worker, which prepares, reports and fails exactly as before. Errors are left to the worker on purpose (for example a missing sandbox is still Cancelled, from the worker path), so error precedence does not change. Cancellation after the plan is still caught by the existing ensure_provisioning_active check that follows image resolution. The overlay preparation keeps its worker.
  • The engine probe is passed as a LocalEngineProbe function so the tests can run on hosts where Docker answers (CI runners included); production passes connect_local_container_engine.
  • Measured on an x86-64 KVM host with both changes, the worker bypass and the build-time guest identity (together with the rest of VM driver repeats per-launch bookkeeping before the VM starts: a debugfs process per overlay command, guest identity re-hashed #6054's changes, p50, ten re-creates of a cached digest-pinned image): create_sandbox received → sandbox root disk plan resolved 114 → 1–2 ms. This figure is not a measurement of the worker bypass alone. Measured on the v0.1.7 driver with the same changes; the code path is unchanged on main (659b45f3b), which this branch is based on.

Testing

  • Checks appropriate to the affected code and behavior pass: cargo fmt -p openshell-driver-vm -- --check, cargo clippy -p openshell-driver-vm --all-targets -- -D warnings, cargo test -p openshell-driver-vm (lib: 304 passed)
  • Unit tests added/updated (if applicable):
    • cached_digest_pinned_image_plan_skips_the_worker_only_on_a_digest_cache_hit: eight cases through a stub worker that records each run (bootstrap-only hit, workload equal to the bootstrap image, cache miss, tag, other workload image, rootfs tar, reachable engine, locally built image); checks which ones ran the worker, the plan, and that the fast path emits Pulling, CacheHit, Pulled. With the fast path disabled it fails with bootstrap-only hit: worker ran.
    • guest_runtime_identity_built_once_matches_the_embedded_bytes (from the cherry-picked commit): the build-time value equals the hash of the embedded bytes computed at run time.
    • cached_digest_pinned_image_plan_keeps_the_worker_path_errors: with the root disk cached, a missing and a deleting sandbox still fail as Cancelled and no worker starts.
  • E2E tests added/updated (if applicable)

The same change, on the v0.1.7 driver, booted VM sandboxes from a cached digest-pinned image on an x86-64 KVM host, and the unit tests above (in their v0.1.7 form) also passed on arm64.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

…rker

Every launch starts an image preparation worker (an exec of the driver
binary, which then probes for a local container engine, plus the
parent's 10 ms exit poll) to resolve its root disk. When the workload
image is the bootstrap image, pinned by digest, its root disk is cached
and no local container engine answers, the worker writes nothing: it
finds no engine and answers from the cache without a registry call
(since ai-openshell#4582).

The driver now answers that case in its own process, with the same logs
and the same Pulling, CacheHit and Pulled events under the same
vm.resolve_bootstrap_image span. Everything else keeps the worker: a
rootfs tar, another workload image, a tag, a locally built image, a
reachable container engine, a cache miss, a registry credential error,
a missing bootstrap image, a sandbox that is gone or already preparing.
Those checks run before any log or event, so the worker then prepares,
reports and fails exactly as before. The overlay preparation keeps its
worker.

The engine probe is passed in (LocalEngineProbe) so the tests can run on
a host where Docker answers.

Test: cached_digest_pinned_image_plan_skips_the_worker_only_on_a_digest_cache_hit
runs eight cases through a recording worker and checks which ones the
worker answered, the plan and the events; it fails when the fast path is
disabled. cached_digest_pinned_image_plan_keeps_the_worker_path_errors
checks a missing and a deleting sandbox still fail as Cancelled with a
cached root disk present.

Closes ai-openshell#6055

Signed-off-by: Balaji Ganesan <bganesan@nvidia.com>
@TaylorMutch

Copy link
Copy Markdown
Contributor

This PR should include or follow the build-time guest runtime identity change from #6056 (ea6c298dbe3102733fa7d74dc2ecc888caa3c3dd). As submitted, it has an effective performance dependency on that change.

In cached_digest_pinned_image_plan, the new call to bootstrap_image_cache_identity(&digest) synchronously calls sandbox_guest_runtime_identity(). On this branch that still hashes all embedded sandbox, vm-init and umoci blobs plus the init script on every call.

Before this PR, that work ran in the image preparation worker. With this PR, every eligible request performs it on the parent driver's async runtime before checking the cache. A cache miss then falls back to the worker and repeats the hashing; a cached image with a reachable engine also pays the parent hash and probe before taking the worker path. This can delay unrelated driver operations under concurrent creates. The stub-artifact tests do not exercise the production-sized hashing cost, and the reported 114 → 1–2 ms measurement includes the companion identity change.

Please land the build-time guest identity commit first and rebase this PR, or include that change here. Alternatively, move the expensive computation off the async runtime. This dependency is specific to the guest identity change: neither overlay batching nor the supervisor hash cache is required, so the supervisor-cache integrity concern raised on #6056 can remain separate.

Every bootstrap root disk's image cache key includes
sandbox_guest_runtime_identity(), a SHA-256 over the embedded sandbox,
vm-init and umoci blobs and the guest init script. It was computed on
every call, and every launch resolves its root disk in a fresh image
preparation worker process, so every launch hashed the embedded blobs
again, even on a cache hit. On an x86-64 host without SHA instructions
most of the 90 ms between the worker's "ensuring cached root disk image"
and its cache hit is this hash (inferred from the driver log gap, not
profiled).

build.rs now hashes exactly the files the crate embeds (from OUT_DIR,
plus the init script, which build.rs now watches) and the function
returns that constant. The value is unchanged, so cached root disks stay
valid.

Test: guest_runtime_identity_built_once_matches_the_embedded_bytes holds
the build-time value equal to the hash of the embedded bytes computed at
run time, as before.

Cherry-picked from ai-openshell#6056 (ea6c298) so
that this PR stands alone: cached_digest_pinned_image_plan calls
bootstrap_image_cache_identity on the async runtime, which must not hash
the embedded blobs there.

Refs ai-openshell#6054

Signed-off-by: Balaji Ganesan <bganesan@nvidia.com>
@balajinvda

Copy link
Copy Markdown
Contributor Author

Agreed: the fast path calls bootstrap_image_cache_identity on the async runtime, so it depends on the build-time identity. I've added that commit (ea6c298, cherry-picked from #6056) so this PR stands alone, and corrected the measurement note: the 114 → 1-2 ms figure was measured with both changes.

@balajinvda

Copy link
Copy Markdown
Contributor Author

@TaylorMutch the build-time identity commit from #6056 is now included here (ea6c298), so this PR stands alone, and the measurement note is corrected. Could you take another look, and approve the pending Branch Checks / Helm Lint runs?

@balajinvda

Copy link
Copy Markdown
Contributor Author

Folded into #6056 (commit 286504a), since this change depends on #6056's build-time identity commit. One PR now closes #6054 and #6055; closing this one.

@balajinvda balajinvda closed this Dec 2, 2026
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.

VM driver starts an image preparation worker on every create, even for a cached digest-pinned image

2 participants