Skip to content

feat(blaze): create sandboxes from templates - #2481

Merged
WeissonHan merged 1 commit into
alibaba:mainfrom
WeissonHan:feature/blaze/template-backed-create-draft-v1
Aug 24, 2026
Merged

feat(blaze): create sandboxes from templates#2481
WeissonHan merged 1 commit into
alibaba:mainfrom
WeissonHan:feature/blaze/template-backed-create-draft-v1

Conversation

@WeissonHan

@WeissonHan WeissonHan commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Description

Delivers template-backed sandbox creation as one self-contained capability: POST /v1/sandboxes accepts an optional template field, and the daemon validates the published catalog entry, materializes it into storage the new sandbox owns outright, and restores the backend from it.

This branch was rebuilt from scratch on current main; it is no longer the historical linear integration. The implementations this capability actually uses are folded in rather than deferred to peer PRs, so there is no interface-and-orchestration-only path:

Capability Where it lives in this PR
Template artifacts become sandbox-owned storage (was #2478) StorageProvider::acquire_template / supports_templates in blaze-core/src/storage.rs; FileStorageProvider::acquire_template and copy_template_artifact in blazed/src/file_provider.rs, which stream every artifact into a fresh provider-owned slot and re-verify size and digest while copying
Host resources are rebound for the restored sandbox (was #2477) PORTABLE_ROOTFS_PATH, MOUNT_AND_EXEC, and prepare_portable_view_target in blazed/src/spawner/firecracker.rs; write_vm_config records the portable path and each owner binds its own rootfs onto it inside the existing private mount namespace
Catalog entry resolution and boot-metadata validation TemplateCatalog::resolve_for_create, validate_template_manifest, and open_verified_template_artifact in blazed/src/sandbox/template.rs
Create orchestration and compensation prepare_template_create and the restore branch of SandboxManager::create in blazed/src/sandbox/manager.rs

Why the rootfs rebinding is required rather than optional: a Firecracker snapshot records its root drive's host path and PUT /snapshot/load overrides only the network and vsock resources. Without one stable in-namespace path, a snapshot captured by one sandbox would resolve to the capture-time disk, so restoring it elsewhere would either fail or mutate the source sandbox's rootfs. That is also what makes the recorded resource_layout: portable-v1 contract true instead of merely asserted.

Ordering safety: policy allow-list, catalog resolution, artifact re-hashing, and image/backend/version/VM-shape/guest-transport agreement are all checked before any lifecycle state is published. Copy, restore, readiness, and final-state failures reuse the existing recoverable create cleanup, retaining residual storage for a later destroy when rollback cannot complete.

Isolation: every template-backed sandbox receives a complete private copy, so mutating or destroying one never changes the catalog or a sibling created from the same entry. A networked template receives a fresh network allocation rather than inheriting the source's slot.

No second template registry or API namespace is added; /v1/templates remains the single template resource.

Related Issue

closes #2465
closes #2466
closes #2467

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional change)
  • Performance improvement
  • CI/CD or build changes

Scope

  • blaze (blaze)

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • Lock files are up to date (package-lock.json / Cargo.lock)

Testing

Validated on the exact PR head (f7e1be89e8):

  • The hosted Linux Blaze gate passed formatting, workspace and all-target Clippy with warnings denied, and workspace tests. blaze-core passed 70 tests and blazed passed 356 tests, including the Linux sparse-copy regression.
  • A real KVM smoke test passed on Linux 6.6 with Firecracker 1.16. A source sandbox completed guest command execution and file read/write, was checkpointed, and its checkpoint was imported through POST /v1/templates/import. Three sandboxes created from that template all reached guest-ready state.
  • The source and the three created sandboxes used independent rootfs and memory objects, network allocations and network namespaces, and VM processes and identities.
  • Modifying and destroying one created sandbox did not change a sibling, the published template, or the source sandbox. After all sandboxes were destroyed, the catalog artifacts retained their original hashes; the daemon exited cleanly with no remaining Firecracker process or network namespace.

Tests added by this PR:

  • template_create_restores_independent_sandboxes — two creates from one entry receive independent copies; mutating the first does not change the catalog or the second; restore observes the published bytes and requests a fresh network allocation.
  • template_create_is_rejected_when_policy_disallows_it — refused before any lifecycle state or storage directory exists.
  • template_create_rejects_mismatched_image_without_lifecycle_state — same, for image identity.
  • mock_restore_accepts_a_foreign_identity_only_for_templates — a template restore accepts the source's recorded identity while a rollback still rejects it.
  • launch_command_binds_the_owned_rootfs_to_the_portable_path — the launch binds this sandbox's rootfs onto the path the machine configuration records.
  • template_identity_round_trips — the catalog name survives persist and load.

Additional Notes

Builds on merged #2219 (template catalog) and #2473 (Firecracker capture and restore). #2477 and #2478 are superseded by this PR: their implementations are folded in above, so they should be closed rather than merged separately — neither had a production caller on its own.

#2471 is not a prerequisite for this capability. It hardens the shared StorageAcquireError contract (adding a ManualCleanupRequired disposition) and adds an instances-root configuration boundary; it produces nothing this PR consumes. acquire_template uses the same two-state disposition contract as the existing acquire, so it is exactly as safe as the current cold-create path and will adopt the third state mechanically when #2471 merges.

@github-actions github-actions Bot added component:blaze src/blaze scope:documentation ./docs/|./*.md|./NOTICE labels Aug 13, 2026
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from a333a77 to ea7f0b1 Compare August 20, 2026 05:28
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review adds a policy-gated template field to POST /v1/sandboxes that validates a published catalog entry, materializes it into an independent provider-owned storage slot, and restores the sandbox from it.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea7f0b1b46

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs Outdated
Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs Outdated
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from ea7f0b1 to c863504 Compare August 20, 2026 05:56
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after folding the Firecracker portable-rootfs rebinding (P1) and carrying the policy's serial-log shape into template restores (P2).

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c863504178

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread docs/user-guide/en/runtime/blaze.md Outdated
Comment thread docs/user-guide/en/runtime/blaze.md
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from c863504 to 74bbf99 Compare August 20, 2026 06:08
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after removing the stale template-create limitation and the unimplemented hibernate/resume claims from the docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74bbf991cf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/spawner/firecracker.rs Outdated
Comment thread docs/user-guide/en/runtime/blaze.md
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from 74bbf99 to dfc3cae Compare August 20, 2026 06:32
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after reserving the portable rootfs path from template catalog roots and documenting the bootable template manifest in both languages.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfc3cae0ea

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/sandbox/template.rs Outdated
Comment thread src/blaze/crates/blazed/src/sandbox/template.rs Outdated
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from dfc3cae to fab371c Compare August 20, 2026 06:53
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after switching the snapshot-view reservation to configured-and-resolved handling and documenting the reserved path in both languages.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fab371c180

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from fab371c to fb7c641 Compare August 20, 2026 07:11
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after distinguishing cross-sandbox template restores from same-sandbox rollbacks in the restore contract.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb7c6411a2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread docs/user-guide/en/runtime/blaze.md Outdated
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from fb7c641 to 91aefed Compare August 20, 2026 07:23
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after documenting backend_version as a general adapter-equality requirement, including mock-v1 for Mock templates.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91aefed0a7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/spawner/firecracker.rs
Comment thread docs/user-guide/en/runtime/blaze.md Outdated
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from 91aefed to 5250033 Compare August 20, 2026 08:02
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review re-review after protecting the sh and mount PATH helpers and distinguishing the 409 and 501 manifest refusals.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5250033118

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/spawner/firecracker.rs Outdated
@WeissonHan
WeissonHan marked this pull request as ready for review August 20, 2026 08:39
@WeissonHan
WeissonHan requested a review from casparant as a code owner August 20, 2026 08:39

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5250033118

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/blaze/crates/blazed/src/spawner/firecracker.rs Outdated
Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs Outdated
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to the Firecracker VM-shape item in Qoder review #2481 (review):

No code change required; confirmed in current head 891cf2d10c. Both user guides already state that missing or zero vcpus/memory_mib, or a shape that differs from policy, returns 409 during preflight before lifecycle state or storage allocation and cannot leave a residual sandbox directory. The following compensation section separately documents that later copy or restore failures can return HTTP 500 with RecoveryRequired and retain resources for deletion.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review This PR adds policy-gated template-backed sandbox creation with independently owned storage and exact cold-start restore compatibility.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@qoder review

@qoderai qoderai Bot 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.

[P1] 模板创建下 Firecracker 恢复目前将 TemplateRestore.preserve_network 直接绑定为 manifest 中的 network 标志,当模板声明网络化时会沿用源快照的网络绑定而非分配新槽位,与“模板创建获得独立网络资源”的公开契约不符;建议模板创建始终将 preserve_network 设为 false,仅普通 checkpoint 恢复保留原网络。 [P2] copy_template_artifact 在 materialize 根文件系统和内存快照时逐字节 write_all,对包含稀疏或零区的模板会让每个 sandbox 拷贝都占用完整逻辑大小,而现有 checkpoint capture 通过稀疏复制控制磁盘占用;建议将模板 artifact 拷贝改为与 checkpoint capture 一致的稀疏复制策略,以避免模板创建路径异常放大空间使用。 [P2] 文档侧模板失败补偿已区分 409/501 与 500 RecoveryRequired,但对新引入的 Firecracker boot_args/VM 规格校验的状态仍略抽象;建议在错误表中单列这些纯前置校验为 409、不创建实例目录,并与 artifact 尺寸/摘要不一致导致的 500 残留场景做明确对照,便于运维根据状态判断是否需要后续 DELETE 清理。


🤖 Generated by QoderView workflow run

Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs Outdated
Comment thread src/blaze/crates/blazed/src/file_provider.rs
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 891cf2d10c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from 891cf2d to f7e1be8 Compare August 20, 2026 10:25
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review This PR adds policy-gated template-backed sandbox creation with sparse, independently owned storage and exact restore compatibility.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@qoder review

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to the preflight-status documentation item in Qoder review #2481 (review):

No code change required; confirmed in current head f7e1be89e8. Both user guides already state that missing, zero, or policy-mismatched Firecracker vcpus/memory_mib returns 409 before lifecycle state or storage allocation and cannot leave a sandbox directory. The adjacent compensation section separately states that artifact-copy or restore failures occur after create intent and may return HTTP 500 with RecoveryRequired when cleanup cannot complete, in which case a later DELETE retries cleanup.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: f7e1be89e8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to all three summary items in Qoder review #2481 (review), verified against current head f7e1be89e8:

  1. [Resolved] Firecracker probe requires every launch helper. FIRECRACKER_LAUNCH_TOOLS contains unshare, mount, and sh; FirecrackerSpawner::probe checks the complete set before the backend is selected. launch_tool_probe_requires_the_shell_used_by_the_mount_wrapper covers the missing-shell case.
  2. [Resolved] The cross-sandbox restore contract is explicit and constrained. Template create sets snapshot_from_other_sandbox, rollback clears it, and the Mock adapter accepts only a valid, non-nil source UUID different from the new sandbox while retaining all format, kind, backend, and version checks. Both template-catalog design documents record this distinction.
  3. [Resolved] Failure compensation and version-status behavior are documented. Both user guides distinguish preflight 409/501 refusals with no allocated sandbox resources, fully compensated runtime failures, and incomplete compensation returning HTTP 500 with RecoveryRequired. They also distinguish a versionless Firecracker manifest rejected with 409 from a Mock adapter mismatch rejected with 501.

Hosted Docs Lint and Test blaze pass on f7e1be89e8; the Blaze test binary reports 356 passing tests. No item from this review remains unresolved.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to all three summary items in Qoder review #2481 (review), verified against current head f7e1be89e8:

  1. [No code change required] Backend-owner identity is checked at the correct boundary. Both production adapters construct the owner identity and backend from the validated restore request. The manager checks the returned owner immediately, before guest-readiness waiting, owner registration, or publication of Running; any Firecracker launch records at that point are cleanup-owned records for the same request UUID.
  2. [Resolved] Mock foreign-source identity is now narrow. A template restore requires a syntactically valid, non-nil source UUID different from the new owner. Missing, malformed, nil, and target-equal identities are rejected; rollback still requires equality. mock_template_restore_requires_a_valid_foreign_identity and mock_restore_accepts_a_foreign_identity_only_for_templates cover both sides.
  3. [Resolved] The user-visible failure outcomes are concrete. Both guides map preflight conflicts and unsupported capability to 409/501 without allocation, successful compensation to the original error without retained resources, and incomplete compensation to HTTP 500 with RecoveryRequired and later DELETE /v1/sandboxes/{id} cleanup.

Hosted Docs Lint and Test blaze pass on f7e1be89e8. No item from this review remains unresolved.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to all three summary items in Qoder review #2481 (review), verified against current head f7e1be89e8:

  1. [Resolved] VM-shape conflict and residual behavior are explicit. Both user guides state that missing, zero, or policy-mismatched Firecracker vcpus/memory_mib returns 409 before lifecycle state or storage allocation and cannot leave a sandbox directory; later copy or restore failures are documented separately.
  2. [Resolved] Firecracker manifest requirements are complete. The field table and validation text require resource_layout = "portable-v1", captured boot_args, non-zero vcpus and memory_mib, and a matching byte-sized memory_size, with violations rejected as 409 preflight conflicts.
  3. [Resolved] Mock version mismatch has a concrete diagnostic example. Both guides state that the built-in adapter reports mock-v1; a manifest containing mock-v2 returns 501 and should be corrected rather than selecting a different backend.

Hosted Docs Lint and Test blaze pass on f7e1be89e8. No item from this review remains unresolved.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to all three summary items in Qoder review #2481 (review), verified against current head f7e1be89e8:

  1. [Resolved] Networked Firecracker templates use the effective cold-start command line. effective_boot_args adds Blaze’s fixed network argument when required, and both write_vm_config and template preflight call that function. The focused network and non-network regression passes.
  2. [Resolved] Firecracker VM-shape preflight is documented. Both guides state that missing, zero, or policy-mismatched vcpus/memory_mib returns 409 before lifecycle state or storage allocation and leaves no sandbox directory, distinct from a later 500 RecoveryRequired failure.
  3. [Resolved] Mock mock-v2 is documented as a manifest error. Both guides provide the requested mock-v1 versus mock-v2 example and explain that the 501 response calls for correcting the manifest, not changing backend.

Hosted Docs Lint and Test blaze pass on f7e1be89e8. No item from this review remains unresolved.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

Follow-up to all three summary items in Qoder review #2481 (review), verified against current head f7e1be89e8:

  1. [No code change required] A networked template receives a new slot. preserve_network carries whether the captured VM requires a network interface; it does not carry a source slot. Firecracker restore maps it to enable_network, and start calls NetworkManager::create with the new sandbox UUID. No source NetworkSlot exists in RestoreRequest; forcing this flag to false would omit the interface required by the captured VM state.
  2. [Resolved] Template materialization preserves sparse storage. It now reuses copy_sparse_file on the retained source and a new provider-owned destination, then verifies that destination’s logical size and SHA-256 digest before syncing it. The hosted Linux regression verifies allocated blocks, data extents, a zero hole, the copied digest, and rejection of an incorrect manifest digest.
  3. [Resolved] Preflight and recovery states are distinguished. Both guides state that Firecracker boot-command and VM-shape conflicts return 409 before lifecycle/storage allocation, while later copy or restore failures can return HTTP 500 with RecoveryRequired only when compensation cannot complete.

Hosted Docs Lint and Test blaze pass on f7e1be89e8; the sparse-copy regression is explicitly present in the successful Linux test log. No item from this review remains unresolved.

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@qoder review

@qoderai qoderai Bot 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.

本次审查范围内未发现需要修改的问题。


🤖 Generated by QoderView workflow run

Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs Outdated
Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs
The template catalog could publish and inspect runtime artifact sets, but
sandbox creation could not turn a published entry into a running sandbox.

Add an explicit, policy-gated `template` field to `POST /v1/sandboxes`. Before
any lifecycle state is written, the manager confirms the name is allowed by the
matched policy, resolves the catalog entry, re-hashes every artifact against its
manifest, and validates the recorded image identity, backend, exact backend
version, snapshot kind, and — for Firecracker — the guest-transport and VM shape
the policy would launch. It then materializes an independent provider-owned slot
from the artifacts, restores the backend with a fresh network allocation when the
template is networked, waits for guest readiness, and persists the catalog name
on the instance.

Storage growth: a new `StorageProvider::acquire_template` copies and revalidates
the open VM-state, memory, and rootfs objects into writable per-sandbox storage,
so every template-backed sandbox owns a complete copy that can be checkpointed,
rolled back, and deleted independently without touching the catalog.

Firecracker host rebinding: a snapshot records its root drive's host path, and
`PUT /snapshot/load` overrides only the network and vsock resources. Each owner
therefore binds its own rootfs onto one stable in-namespace path, which the
recorded machine configuration names, so a snapshot captured by one sandbox
restores against the restoring sandbox's independent copy instead of the
capture-time disk. The launch already ran inside a private mount namespace, so
this adds the bind step and its shared mount target only, and `sh` and `mount`
join the protected PATH helper set the launch now depends on. The fixed target is
reserved from template catalog roots, literal and resolved target alike, so
startup accounting cannot mistake it for
a published entry.

Cross-sandbox restore: a template capture records its source sandbox, so
`RestoreRequest` now states whether a snapshot came from another sandbox. A
rollback still requires an adapter-recorded identity to name the restoring
sandbox; a template restore accepts the source's identity, which is what lets a
mock-backed template create succeed instead of failing after allocation.

Copy, restore, readiness, and final-state failures reuse the existing
recoverable create cleanup, retaining residual storage for a later destroy when
rollback cannot complete. The daemon adds no second template registry or API
namespace; `/v1/templates` remains the single template resource.

Signed-off-by: Weisson <Weisson@linux.alibaba.com>
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from f7e1be8 to 5ef5d64 Compare August 21, 2026 09:55
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@qoder review

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 5ef5d64899

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@WeissonHan

Copy link
Copy Markdown
Collaborator Author

单测设计思路

实验按下面的因果顺序进行:

  1. 在普通 Firecracker 沙箱中写入磁盘标记,并启动一个把随机标识和计数保存在
    /dev/shm 的程序。/dev/shm 位于客户机内存,普通冷启动不会保留其中的数据。
    建立只能通过完整内存与磁盘恢复才能保留的可观察证据。
  2. 捕获该沙箱的处理器、内存和磁盘状态,将三项文件发布为模板。
    确认模板包含恢复虚拟机所需的完整状态,而不只是根文件系统。
  3. 先销毁制作模板的原沙箱,再从模板创建 A、B 两个沙箱。
    排除新沙箱仍依赖原虚拟机进程或原沙箱运行目录的可能。
  4. 检查 A、B 是否保留相同的磁盘标记、随机标识和 /dev/shm 文件,并确认计数程序从
    捕获位置继续运行。
    证明系统实际恢复了模板中的磁盘、内存和进程状态,而不是忽略模板后重新
    冷启动。
  5. 检查 A、B 使用不同的 Firecracker 进程、内存文件和根文件系统。
    证明 A、B 是两个独立运行的沙箱,不是共同连接到同一虚拟机或同一份可写
    存储。
  6. 只修改 A 的磁盘标记,确认 B 的内容和模板目录中的原始文件均未变化。
    证明沙箱之间没有共享可写磁盘,并且运行中的沙箱不能污染模板。
  7. 销毁 A,确认 B 仍正常运行;随后再次从原模板创建 C,并检查 C 仍能恢复模板中的原始
    标记和程序状态。
    证明销毁一个沙箱不会误删其他沙箱或模板资源,同时证明同一模板可以安全、
    重复地创建新沙箱。

只有上述证据全部成立,才能确认 #2481 同时满足两项要求:正确恢复模板保存的虚拟机状态,
并为每个新沙箱提供相互独立的运行资源。

测试过程

1. 启动 0 号沙箱 ,并运行计数器用以检查运行状态

1

2. 用 0 号沙箱创建检查点,并且从检查点创建模板

2

3. 从模板创建 A、B 两个沙箱

3

4. A、B 两个沙箱的文件描述符、pid 等运行资源隔离

4

5. 修改 A 沙箱的内容,不会影响 B 沙箱

截屏2026-08-23 12 59 15

6. 销毁 A 沙箱,紧接着创建 C 沙箱,观察到 A 的销毁行为不会影响到模板,C 沙箱仍然应用了模板的原始状态

6

总结

本次按照上述验证要求测试了模板制作、发布及原沙箱销毁阶段的响应和文件均完整保留;
在确认二进制、模板文件校验值和持久状态一致后,重新启动 Blaze,人工完成 A、B、C
三个沙箱的创建、隔离、销毁和清理。

  • 原沙箱销毁且 Blaze 重启后,模板仍可查询和使用;
  • A、B、C 都恢复了模板制作时写入客户机内存的随机标识和运行中计数程序;
  • 各沙箱使用独立的 Firecracker 进程、根文件系统和内存文件;
  • 修改 A 不影响 B,也没有改变模板;
  • 销毁 A 不影响 B,随后仍能从同一模板创建出干净的 C;

@WeissonHan
WeissonHan merged commit ad0980f into alibaba:main Aug 24, 2026
24 checks passed
@WeissonHan
WeissonHan deleted the feature/blaze/template-backed-create-draft-v1 branch August 24, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:blaze src/blaze scope:documentation ./docs/|./*.md|./NOTICE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[blaze] feat: create sandboxes from templates [blaze] feat: materialize template storage [blaze] feat: rebind snapshot host resources

2 participants