Repository navigation
feat(installer): apply sandbox migration 041 on Compose upgrades - #1304
Merged
Merged
Conversation
Robert0622
previously approved these changes
Nov 24, 2026
Robert0622
left a comment
Collaborator
There was a problem hiding this comment.
构建成功。./start.sh pull 的升级链路按 docs/deployment.md 描述的走通:拉镜像 → 查 io.loopforge.sandbox-catalog label → 单独拉起 MySQL → 查旧表 → 停平台 → mysqldump 备份 → 执行 041 → 启动全部 → 补 schema extensions。备份失败、迁移失败、迁移后新平台起不来这三种情况,平台都保持停止,数据库要么没被改、要么已完整迁移,修好后重跑 ./start.sh pull 都能恢复。
实测
- PR 自带的
scripts/test-install.py:TMPDIR=/build/tmp/p1304 python3 scripts/test-install.py -v→Ran 68 tests … OK (skipped=2)(跳过的是需要 bash 3.2 的用例)。默认临时目录在/tmp,本机/tmp是 noexec,mock 的docker跑不起来会落到系统 docker,导致 43 个失败,属环境问题。新增用例覆盖:迁移先于启动、无 label 或无旧表时跳过、备份/迁移失败保持停止、pull与migrate-sandboxes共用一把锁。 - 真实旧库(MySQL 8.4.13,
log_bin=ON):编译 v0.4.2 的 agentflow,在lf_p1304_legacy上导入 v0.4.2 seed,通过 v0.4.2 的 API 造了带files的 dockerfile、孤儿 dockerfile、带 PATH/pathEntries/installScript 的 environment、docker 沙箱和 local 沙箱;旧表查询返回 2;按要求参数 mysqldump 备份退出 0、文件 0600;执行 041 退出 0(0.17s),迁移后旧表为 0,local 变 native(变量合并为 FOO/JAVA_HOME,PATH 被删),孤儿 dockerfile 变独立沙箱,docker 沙箱带上 Dockerfile 和 files;再执行一次 041 结果不变(幂等);把备份恢复回新库,旧表与 local 驱动都在(可回滚)。 - 用 root 建一个主动报错的 trigger 制造事务中途失败:
ERROR 1644 … line 111,退出 1,整个事务回滚,旧表仍为 2;删掉 trigger 后重跑成功。 AGENTFLOW_SANDBOX_MIGRATION_TEST_DSN=… go test ./internal/repo -run TestMySQLSandboxMigrationAllocatesUnusedIDs通过。- 用 fake
dockershim 驱动真实的bash start.sh pull(compose exec mysql sh -c转成连真实 MySQL 8.4 执行),逐个场景核对:镜像在跑+旧库 → 顺序正确、退出 0,备份在.local/loopforge-before-041.*/loopforge.sql(目录 700、文件 600);无 label / label 为空 → 跳过且不停平台;已迁移库重跑 → 跳过、不再备份;备份失败 → 平台停、不留半成品、退出 1;迁移失败 → 平台停、备份保留、退出 1,修好后重跑成功;迁移后新平台起不来 → 平台停、库已迁移,重跑时检测到无旧表直接启动;image inspect 失败 / mysql 起不来 / 旧表查询失败 → 退出且旧平台照常运行、库未改;并发执行pull与migrate-sandboxes→Could not lock the installation。 - 用真实 Compose 2.26 CLI(不需要 daemon)验证
compose config --format json platform取到的镜像名(默认…:0.4.2、@sha256摘要、dev 的loopforge-platform:local),以及新增的up … --no-recreate --pull never mysql、up … --pull never用--dry-run解析通过。 - LABEL 加在 Dockerfile 最终阶段,release 用 build-push-action 构建最终阶段,会进发布镜像;
.local同时在.gitignore和.dockerignore里,备份不会进 git 或 dev 构建上下文。
不阻塞的小建议(P3)
start.sh:54迁移失败的提示是 "retry with the platform stopped",而文档写的是重跑./start.sh pull;只跑migrate-sandboxes的话平台不会自动起来,建议提示语与文档统一。start.sh:62、:68里 image inspect 失败或旧表查询失败时set -e直接退出,用户只看到 docker/mysql 原始报错,建议补一条 ✗ 提示。scripts/install.sh这条升级路径不会执行 041:用./start.sh重跑安装器升到一个内联沙箱镜像后,旧库的 docker 沙箱dockerfile为 null;之后再pull能补救(旧表仍在),文档也写明升级要用pull,不算本 PR 的回归,但安装时检测到旧表可以给个提示。- 锁只覆盖
pull与migrate-sandboxes,迁移过程中执行./start.sh restart会把已停止的旧平台重新拉起(很窄的竞态)。
未能测试:真实 Docker daemon 与 docker compose exec(本机没有 Docker 权限,用 shim 代替,shim 里执行 SQL/mysqldump 连的是真实 MySQL 8.4);真实 GHCR/NJU 镜像拉取只跑了 mock;macOS bash 3.2 的 set -e 行为;磁盘写满导致备份失败。
Robert0622
approved these changes
Nov 24, 2026
Robert0622
left a comment
Collaborator
There was a problem hiding this comment.
复测 cc65e84(Merge origin/main into feature/auto-sandbox-migration)。上一轮在 469fcdc 上已经通过,这次只有合并 main 这一个提交,没有发现新问题,通过。
合并冲突处理
- 唯一冲突在
scripts/test-install.py的setUp环境清理:保留了 #1295 新加的AGENTFLOW_PROJECT_CREDENTIAL_KEY清理,也保留了本 PR 的MOCK_SANDBOX_*等 4 个变量,没有残留冲突标记。 - 对比合并前后本 PR 相对 main 的改动(
git diff merge-base..469fcdc与git diff origin/main..cc65e84),增删的行完全一致,合并没有改变 PR 本身的内容。
实测
python3 scripts/test-install.py -v:本 PR 69 个用例全部通过(跳过 2 个),main 是 65 个全部通过。新增的 4 个用例也都通过,包括test_start_pull_migrates_legacy_sandboxes_before_startup、test_start_pull_keeps_platform_stopped_on_backup_or_migration_failure、test_start_pull_and_manual_sandbox_migration_share_an_upgrade_lock。- 原生部署 head(Go 1.26.11,MySQL 8.4.7 全新库),健康检查 200。按 PR 重新构建 chatbot,487/487 通过;
go vet ./...通过。 ./internal/domain、./internal/gitwork、./internal/repo全部通过。./internal/runtime、./internal/runner、./internal/engine的失败用例和 main(177d881)完全一致,原因是本机缺 bwrap 和 Docker。- 本机不能运行 Docker,没法跑真实的 Compose
./start.sh pull升级,这部分靠上面的安装脚本用例覆盖。
2 tasks done
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1258.
What changed
Scope
Compatibility
Published Compose upgrades get the automatic migration when the target image carries the sandbox catalog label. Source builds and external MySQL retain the explicit migration procedure. Rollback to a release that uses the old sandbox format requires restoring the pre-migration backup.
Validation
python3 -B scripts/test-install.pyin Linux Docker. All 66 applicable tests passed, and the two Bash 3.2 compatibility cases passed separately on macOS./bin/bash -n start.shandgit diff --check.Safety