Repository navigation
fix(sandbox-template): apply min_free_disk on same-name builds - #466
DROWNING2003 wants to merge 3 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: DROWNING2003 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
The template API dropped diskSizeMB in favor of minFreeDiskMb, so a leftover disk_size_mb used to be silently ignored and builds fell back to the team default disk. Parse the retired key only to emit a migration hint.
75677da to
f77da86
Compare
Rebuild requests carry no disk field, so a template created months ago never picks up min_free_disk_mb. When the name already exists and a positive min-free-disk is set, create through the v3 endpoint instead, matching E2B Template.build; the server keeps the template ID and applies the disk setting.
|
/review -claude |
Alias lookup can resolve to another team's public template, where a same-name create lands in the caller's team but stays unreachable by name. Verify ownership before re-creating, and correct the docs: the v3 create path updates the same template ID instead of forking a new one.
There was a problem hiding this comment.
Updated: this review was first written against
eabc26e8. While it was being submitted,73e9a583("guard re-create against foreign templates") was pushed, and GitHub attached the review to that commit. The findings below are re-checked against73e9a583.
73e9a583 resolves the main concerns from the first pass:
- Docs, CHANGELOG and comments now say the v3 same-name create keeps the template ID. You also note you confirmed this by testing. That removes the earlier worries about template pile-up, losing the per-template COPY cache, and losing the public flag.
- The lookup/recreate branching is simplified to a single decision.
- A same-name create against another team's public template now fails early.
go test ./iqshell/sandbox/template/... passes on 73e9a583 and gofmt -s -l is clean.
Reviewed head commit: 73e9a583440eed9e275361c353f21649db63f904
Remaining findings
[P2] An explicit --min-free-disk 0 is still ignored without a warning on name or ID rebuilds (iqshell/sandbox/template/operations/build.go:196)
The recreate path clears templateID before this check, so the old info.MinFreeDiskMB != nil condition never fired there anyway. Narrowing it to > 0 therefore changes only the explicit-0 case. 0 is a documented value ("explicit 0 disables free-space growth"), and docs/sandbox_template_build.md:117 still promises a notice on rebuild. Now --min-free-disk 0 or min_free_disk_mb = 0 against an existing template is dropped with no feedback. You now know the v3 create keeps the ID, so the simplest fix may be to let shouldRecreateForDisk accept any non-nil value, which would apply 0 too. Otherwise, restore the != nil warning.
[P3] The legacy warning names the wrong file and mixes languages (iqshell/sandbox/template/operations/build.go:406)
The message hardcodes qshell.sandbox.toml, but with --config ./prod.toml a different file was read. Use cfg.SourcePath() instead. It is also the only Chinese runtime message in this flow: PrintWarn adds an English Warning: prefix and the other build warnings are English.
[P3] Some docs still say a name hit always rebuilds (see the inline comment on docs/sandbox_template_build.md:50)
Minor: the new CHANGELOG entries sit in the first # 未发布 block. The related min_free_disk_mb addition and the --disk-size / disk_size_mb removal are in the second # 未发布 block below 2.19.13. Entry 1 also calls the key "已废弃" (deprecated), while that block lists it as removed under 不兼容变更 (breaking changes).
| if err := validateRebuildSourceSelection(info, cliFromImage, cliFromTemplate); err != nil { | ||
| sbClient.PrintError("%v", err) | ||
| return | ||
| } |
There was a problem hiding this comment.
[Resolved in 73e9a583] [P1] Recreate path depends on unconfirmed server behavior and runs on every build
This was written against eabc26e8; it is now anchored to the wrong line because the head moved. 73e9a583 states, from testing, that the v3 same-name create keeps the template ID, and adds an ownership guard. That addresses the 409, template pile-up, COPY-cache and visibility concerns. Nothing left to do here.
|
|
||
| 未提供 `template_id` 时,如果配置文件或 CLI 中有 `name`,命令会先按 name 在远端查找模板;命中即进入 rebuild,未命中再创建新模板。按 name 命中的 rebuild 不会把 `template_id` 回写到配置文件,便于同一份配置在多个环境复用。 | ||
|
|
||
| 例外:配置了 `min_free_disk_mb > 0`(或 `--min-free-disk` 大于 0)且按 name 命中已有模板时,命令不会走 rebuild,而是改用 v3 创建接口以同名提交,由服务端更新该模板并应用磁盘设置(实测模板 ID 不变)。模板磁盘只在创建时确定,rebuild 请求没有磁盘字段,只有创建接口才能应用该设置。若命中的是其他团队的公共模板,命令会直接报错,因为再构建也会被按 name 解析回那个公共模板。显式传入 `--template-id` 或配置文件中存在 `template_id` 时仍走 rebuild,磁盘不会改变,并会打印告警。 |
There was a problem hiding this comment.
[P3] Some docs still say a name hit always rebuilds
The contradiction this comment first raised (new template vs. same ID) is fixed in 73e9a583. A few texts still describe the old behavior, though:
- Line 40 of this file says
--min-free-diskis "重新构建已有模板时忽略" (ignored when rebuilding an existing template). It now does apply when the name resolves and the value is > 0. - The minimal example in
docs/sandbox_template_config.md:126-137setsmin_free_disk_mb = 5120, but still says a name hit rebuilds ("同名模板已存在则 rebuild" / "按 name 命中后 rebuild"). - The
--helplong text atcmd/sandbox_template.go:178says "命中即对已有模板触发 rebuild" (a name hit triggers a rebuild).
| if err := validateRebuildSourceSelection(info, cliFromImage, cliFromTemplate); err != nil { | ||
| sbClient.PrintError("%v", err) | ||
| return | ||
| recreate := shouldRecreateForDisk(info, foundByName) |
There was a problem hiding this comment.
[Resolved in 73e9a583] [P3] Simplify the lookup/recreate branching
The branching now makes the decision once and the separate recreate block is gone. Nothing left to do here.
| if tmpl == nil { | ||
| return nil | ||
| } | ||
| return ownershipError(name, templateID, tmpl.IsOwner) |
There was a problem hiding this comment.
[P3] The legacy warning names the wrong file and mixes languages
(Because the head moved, this comment landed on ownershipError. The code in question is legacyDiskSizeWarning, at line 406 in 73e9a583.)
The message hardcodes qshell.sandbox.toml, but with --config ./prod.toml a different file was read. Use cfg.SourcePath() instead. It is also the only Chinese runtime message in this flow: PrintWarn adds an English Warning: prefix and the other build warnings are English, so the output mixes languages.
问题
模板磁盘只在创建时确定:rebuild 接口(
POST /templates/{id},TemplateBuildRequest)没有磁盘字段,min_free_disk_mb只存在于创建接口(POST /v3/templates,TemplateBuildRequestV3)。qshell 按 name 命中已有模板后走 rebuild,
min_free_disk_mb永远不生效——构建显示成功,磁盘还是几个月前的容量。E2B 的Template.build不受影响,因为它每次都调POST /v3/templates。改动
min_free_disk_mb > 0且按 name 命中已有模板时,改走 v3 创建接口以同名提交,由服务端更新该模板并应用磁盘设置。实测模板 ID 不变、alias 不变,磁盘 12559 MiB → 23844 MiB。--template-id/ 配置文件template_id仍走 rebuild,并保留「磁盘不会改变」的告警。disk_size_mb:解析该字段仅用于输出迁移提示,避免静默忽略。验证
go test ./iqshell/sandbox/template/...go build ./...gofmt -l无输出