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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11dafc1385
ℹ️ 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".
11dafc1 to
fcfddab
Compare
|
@codex review This PR adds policy-gated template-backed sandbox creation with independently owned storage and exact Firecracker restore identity. |
|
@qoder review |
There was a problem hiding this comment.
[P1] Firecracker 模板 VM 形状与 policy 的匹配逻辑整体合理,但目前用户指南中对 vcpus/memory_mib 必填且必须匹配的约束,以及与 storage 分配前冲突拒绝之间的可见行为差异仍略抽象,建议在模板创建错误表和 manifest 字段表中用一两句补上,帮助运维区分完全不创建实例的 409 场景与可能产生残留目录的 500 RecoveryRequired 场景。
[P1] 模板 manifest 对 Firecracker 的额外要求已经在代码和设计文档中充分体现,包括 resource_layout = portable-v1、捕获的 boot_args、非零 VM 形状及 memory_size 与 memory_mib 的一致性,用户指南可以再明确这几项都是创建前必需的校验条件,并在状态说明中标出违反时的 409 行为。
[P2] Mock 模板下 backend_version 字段值与 restore 能力不一致时目前统一归类为 501 未实现,文档侧可考虑增加一个简短示例,说明这类错误是配置值不匹配而非后端能力缺失,便于调用方据此判断需要调整 manifest 而不是切换 backend。
🤖 Generated by Qoder • View workflow run
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fcfddabcda
ℹ️ 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".
fcfddab to
0412d5c
Compare
|
@codex review This PR adds policy-gated template-backed sandbox creation with independently owned storage and exact restore compatibility. |
|
@qoder review |
There was a problem hiding this comment.
[P1] Firecracker 模板 boot_args 校验仅与原始 policy 值比较,在启用网络时未考虑 NETWORK_BOOT_IP 自动追加,可能导致合法模板被 409 拒绝或错误放行;建议改为与 write_vm_config 使用的有效命令行(含网络自动追加)对比,确保恢复下的内核参数严格匹配 cold start 形态。
[P1] 英文/中文用户指南虽然补充了模板字段和状态说明,但对 Firecracker VM 规格不匹配这一纯前置冲突未单独归类;建议在模板错误说明中显式标注“vcpus/memory_mib 缺失或与 policy 不一致 → 409 Conflict,且不会创建实例目录”,帮助运维区分与后续 copy/restore 失败返回 500 RecoveryRequired 并可能保留残留的路径。
[P2] Mock 模板 backend_version 不匹配时当前统一以 501 未实现报错,文档已指出需要与 restore 能力一致但示例略抽象;建议在用户指南中补充一个具体示例(如 Mock adapter 固定报告 mock-v1,manifest 写成 mock-v2 也会返回 501,属于 manifest 配置错误),方便调用方根据 501 判断是修正字符串而非切换 backend。
🤖 Generated by Qoder • View workflow run
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0412d5c70c
ℹ️ 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".
0412d5c to
891cf2d
Compare
|
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". |
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>
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 |
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 #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.