Skip to content

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

Open
WeissonHan wants to merge 1 commit into
alibaba:mainfrom
WeissonHan:feature/blaze/template-backed-create-draft-v1
Open

feat(blaze): create sandboxes from templates#2481
WeissonHan wants to merge 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 #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
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

@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: 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".

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

Copy link
Copy Markdown
Collaborator Author

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

@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 模板 VM 形状与 policy 的匹配逻辑整体合理,但目前用户指南中对 vcpus/memory_mib 必填且必须匹配的约束,以及与 storage 分配前冲突拒绝之间的可见行为差异仍略抽象,建议在模板创建错误表和 manifest 字段表中用一两句补上,帮助运维区分完全不创建实例的 409 场景与可能产生残留目录的 500 RecoveryRequired 场景。
[P1] 模板 manifest 对 Firecracker 的额外要求已经在代码和设计文档中充分体现,包括 resource_layout = portable-v1、捕获的 boot_args、非零 VM 形状及 memory_sizememory_mib 的一致性,用户指南可以再明确这几项都是创建前必需的校验条件,并在状态说明中标出违反时的 409 行为。
[P2] Mock 模板下 backend_version 字段值与 restore 能力不一致时目前统一归类为 501 未实现,文档侧可考虑增加一个简短示例,说明这类错误是配置值不匹配而非后端能力缺失,便于调用方据此判断需要调整 manifest 而不是切换 backend。


🤖 Generated by QoderView workflow run

Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs
Comment thread src/blaze/crates/blazed/src/sandbox/template.rs
Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs

@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: 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".

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 fcfddab to 0412d5c Compare August 20, 2026 10:08
@WeissonHan

Copy link
Copy Markdown
Collaborator Author

@codex review This PR adds policy-gated template-backed sandbox creation with independently owned storage and exact 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 模板 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 QoderView workflow run

Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs Outdated
Comment thread docs/user-guide/zh/runtime/blaze.md

@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: 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".

Comment thread src/blaze/crates/blazed/src/file_provider.rs Outdated
@WeissonHan
WeissonHan force-pushed the feature/blaze/template-backed-create-draft-v1 branch from 0412d5c to 891cf2d Compare August 20, 2026 10:17
@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
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".

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 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
Comment thread src/blaze/crates/blazed/src/sandbox/manager.rs
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

1 participant