feat(blaze): create sandboxes from templates - #2481
Conversation
a333a77 to
ea7f0b1
Compare
|
@codex review adds a policy-gated |
There was a problem hiding this comment.
💡 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".
ea7f0b1 to
c863504
Compare
|
@codex review re-review after folding the Firecracker portable-rootfs rebinding (P1) and carrying the policy's serial-log shape into template restores (P2). |
There was a problem hiding this comment.
💡 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".
c863504 to
74bbf99
Compare
|
@codex review re-review after removing the stale template-create limitation and the unimplemented hibernate/resume claims from the docs. |
There was a problem hiding this comment.
💡 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".
74bbf99 to
dfc3cae
Compare
|
@codex review re-review after reserving the portable rootfs path from template catalog roots and documenting the bootable template manifest in both languages. |
There was a problem hiding this comment.
💡 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".
dfc3cae to
fab371c
Compare
|
@codex review re-review after switching the snapshot-view reservation to configured-and-resolved handling and documenting the reserved path in both languages. |
There was a problem hiding this comment.
💡 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".
fab371c to
fb7c641
Compare
|
@codex review re-review after distinguishing cross-sandbox template restores from same-sandbox rollbacks in the restore contract. |
There was a problem hiding this comment.
💡 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".
fb7c641 to
91aefed
Compare
|
@codex review re-review after documenting backend_version as a general adapter-equality requirement, including mock-v1 for Mock templates. |
There was a problem hiding this comment.
💡 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".
91aefed to
5250033
Compare
|
@codex review re-review after protecting the sh and mount PATH helpers and distinguishing the 409 and 501 manifest refusals. |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
Follow-up to the Firecracker VM-shape item in Qoder review #2481 (review): No code change required; confirmed in current head |
|
@codex review This PR adds policy-gated template-backed sandbox creation with independently owned storage and exact cold-start restore compatibility. |
|
@qoder review |
There was a problem hiding this comment.
[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 Qoder • View workflow run
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
891cf2d to
f7e1be8
Compare
|
@codex review This PR adds policy-gated template-backed sandbox creation with sparse, independently owned storage and exact restore compatibility. |
|
@qoder review |
|
Follow-up to the preflight-status documentation item in Qoder review #2481 (review): No code change required; confirmed in current head |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
Follow-up to all three summary items in Qoder review #2481 (review), verified against current head
Hosted Docs Lint and |
|
Follow-up to all three summary items in Qoder review #2481 (review), verified against current head
Hosted Docs Lint and |
|
Follow-up to all three summary items in Qoder review #2481 (review), verified against current head
Hosted Docs Lint and |
|
Follow-up to all three summary items in Qoder review #2481 (review), verified against current head
Hosted Docs Lint and |
|
Follow-up to all three summary items in Qoder review #2481 (review), verified against current head
Hosted Docs Lint and |
|
@qoder review |
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>
f7e1be8 to
5ef5d64
Compare
|
@qoder review |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
单测设计思路实验按下面的因果顺序进行:
只有上述证据全部成立,才能确认 #2481 同时满足两项要求:正确恢复模板保存的虚拟机状态, 测试过程1. 启动 0 号沙箱 ,并运行计数器用以检查运行状态
2. 用 0 号沙箱创建检查点,并且从检查点创建模板
3. 从模板创建 A、B 两个沙箱
4. A、B 两个沙箱的文件描述符、pid 等运行资源隔离
5. 修改 A 沙箱的内容,不会影响 B 沙箱
6. 销毁 A 沙箱,紧接着创建 C 沙箱,观察到 A 的销毁行为不会影响到模板,C 沙箱仍然应用了模板的原始状态
总结本次按照上述验证要求测试了模板制作、发布及原沙箱销毁阶段的响应和文件均完整保留;
|






Description
Delivers template-backed sandbox creation as one self-contained capability:
POST /v1/sandboxesaccepts an optionaltemplatefield, 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:StorageProvider::acquire_template/supports_templatesinblaze-core/src/storage.rs;FileStorageProvider::acquire_templateandcopy_template_artifactinblazed/src/file_provider.rs, which stream every artifact into a fresh provider-owned slot and re-verify size and digest while copyingPORTABLE_ROOTFS_PATH,MOUNT_AND_EXEC, andprepare_portable_view_targetinblazed/src/spawner/firecracker.rs;write_vm_configrecords the portable path and each owner binds its own rootfs onto it inside the existing private mount namespaceTemplateCatalog::resolve_for_create,validate_template_manifest, andopen_verified_template_artifactinblazed/src/sandbox/template.rsprepare_template_createand the restore branch ofSandboxManager::createinblazed/src/sandbox/manager.rsWhy the rootfs rebinding is required rather than optional: a Firecracker snapshot records its root drive's host path and
PUT /snapshot/loadoverrides 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 recordedresource_layout: portable-v1contract 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/templatesremains the single template resource.Related Issue
closes #2465
closes #2466
closes #2467
Type of Change
Scope
blaze(blaze)Checklist
package-lock.json/Cargo.lock)Testing
Validated on the exact PR head (
f7e1be89e8):blaze-corepassed 70 tests andblazedpassed 356 tests, including the Linux sparse-copy regression.POST /v1/templates/import. Three sandboxes created from that template all reached guest-ready state.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
StorageAcquireErrorcontract (adding aManualCleanupRequireddisposition) and adds an instances-root configuration boundary; it produces nothing this PR consumes.acquire_templateuses the same two-state disposition contract as the existingacquire, so it is exactly as safe as the current cold-create path and will adopt the third state mechanically when #2471 merges.