Repository navigation
fix(workspace): preserve complete checkpoints when reclaim fails - #1223
Robert0622 wants to merge 21 commits into
Conversation
crispinhu27
left a comment
There was a problem hiding this comment.
Automated review: approving head 3157149a (base main @ eb2e368f). This is the first review on this PR.
Scope reviewed
claimIdleConversationWorkspace: cleanup-hold short-circuit before taking a lease,heldWorkspaceCheckpointNeedsSave/workspaceCheckpointNeedsSave, and the unchanged final capture before reclaim once the hold clears.EndConversationWorkspaceUseAsync: retry backoff (100 ms → 500 ms within the existing 5-minute deadline) and token-fenced renewal of an expired lease.beginWorkspaceLease: maintenance and save leases are now refused onceworkspace_cleaned_atis set (07b8d10).- Callers and lease/finish/claim paths in
internal/repo/workspace_checkpoints.go.
Verification run in an isolated environment with no credentials and synthetic data (Go 1.26.11)
go vet ./internal/engine ./internal/repo: passed.- Full
go test ./internal/engine ./internal/repo: passed. - Checkpoint, cleanup and workspace-use subset with
-race: passed, and no data races were reported. - Baseline comparison: on
cf0cd69(main before this PR),TestConversationWorkspaceCleanupHoldKeepsCurrentCheckpointUntilReclaimandTestBackgroundWorkspaceSaveRecoversFromSlowRunnerAndExpiredLeasefail.TestConversationWorkspaceStaleCleanupKeepsReclaimedCheckpointfails on5208d8c4. All three pass on this head. - Extra edge-case tests (not pushed) passed under
-race. They covered:- a FollowUp workspace held past its idle TTL: the workspace is saved once at idle expiry, 3 held sweeps reuse that checkpoint and leave no lease behind, and after the hold clears there is a final capture and reclaim that restores the latest edit;
- a background save whose expired lease is taken over by maintenance mid-capture: the save stops after one capture and the new lease stays intact (no renewal or clobbering).
- CI on this head: all 16 check runs succeeded, including
platform-required,coreandbrowser.
Not verified locally
- The MySQL/binlog measurements and live Runner/CodeBuddy runs described in the PR body.
- Full
go build ./.... It needs a frontend build forweb/native-chat, which is unrelated to this change; CIcorecovers it. - Chromium and Docker tests in
internal/runtime. The sandbox lacks Docker and Chromium, and this PR does not touch that package.
This approval reflects the checks above, not a guarantee that the change is defect-free.
crispinhu27
left a comment
There was a problem hiding this comment.
Automated re-review: approving head a248997f (base main @ eb2e368f).
The previous automated APPROVE on 3157149a raised no blocking issues and was dismissed when a248997f was pushed. I reviewed the full PR again, focusing on the new commit.
Scope reviewed
- Chunk-only
SaveWorkspaceCheckpointStream(the inline small-archive path was removed). The legacy inline reader is unchanged, and no other code path relies on small archives staying inline. cleanup_retry_at: set in the same transaction asClaimCheckpointWorkspaceCleanup, honoured by the claim and by the pre-lease short-circuit inclaimIdleConversationWorkspace, and cleared byRestoreCheckpointWorkspaceBindingfor the restoring lease.saveConversationWorkspace(previousSHA): digest reuse only afterverifyStoredCheckpointsucceeds, republish when the stored copy is damaged, and the local/remote missing-root handling.- Lost reclaim reply in
cleanupWorkspace: reset is skipped only when an independentCheckpointStatusprobe reportsWorkspaceErrorMissing. compose.yaml--binlog-row-imagedefault/override and the deployment docs.
Verification (isolated sandbox, synthetic data, no credentials in the test environment; Go 1.26.11, MariaDB 11.8 with ROW binlog)
go vet ./internal/engine ./internal/repopassed. Fullgo test ./internal/engine ./internal/repo(SQLite) passed.- Checkpoint/cleanup/reclaim subset under
-race,-count=2, passed with no races. Repo checkpoint tests against MySQL-protocol DB (AGENTFLOW_TEST_MYSQL_DSN) passed. - Binlog probe, 16 lease renewals on a 3 MiB checkpoint with
binlog_row_image=FULL:mainstores it inline and logs 100,678,159 B.- This head stores it as chunks and logs 16,332 B.
- With
NOBLOBonmain, the legacy inline renewals log 14,640 B.
- Upgrade/rollback on one DB:
mainwrites a 3 MiB inline archive.- This head adds the nullable
cleanup_retry_atcolumn, reads the legacy archive (sha matches), and writes a 5 MiB chunked archive. mainreads that chunked archive back (sha matches).
- Extra edge test (not pushed). After a failed reclaim, the Worker status probe also returns 503:
- the workspace is reset, not marked cleaned, and the retry is deferred;
- I then corrupted the stored chunk, and the retry at the deadline published a new archive instead of reusing the damaged one. The new archive passes
ValidateWorkspaceCheckpointFrom.
docker compose configrenders--binlog-row-image=NOBLOBby default andFULLwithLOOPFORGE_MYSQL_BINLOG_ROW_IMAGE=FULL.- CI on this head: all 16 check runs succeeded.
first-runstarts the Compose MySQL 8.4 service with the new flag.
Not verified locally
- MySQL 8.4 itself; I used MariaDB locally, and CI
first-runcovers MySQL 8.4 startup. - The exact byte figures in the PR body and the NOBLOB→FULL replica replay.
- Live Worker/CodeBuddy runs, and the Chromium/Docker tests (the sandbox has no Docker daemon or Chromium).
This approval reflects the checks above. It does not guarantee the change is defect-free.
|
结论:建议合入 GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号对 LoopForge 只有 pull 权限,无法提交正式 Approve / Request changes。以下改为普通评论。 核对了清理挂起期间复用已有检查点、失败回收写入 cleanup_retry_at,以及新归档改走 chunk 表。这对应 #1138 里续租和清理把大字段反复写入 binlog 的问题;compose 默认 binlog_row_image=NOBLOB,并保留环境变量可改回 FULL。恢复测试覆盖了校验失败后的重写。CI 16 项成功,mergeable_state 为 clean。可以合入。 |
Preserve published archive chunks when a commit outcome is uncertain. Coordinate workspace recovery and reclamation across processes and keep registered workspaces out of the orphan sweep. Exercise concurrent recovery, Worker and Runner retries, and checkpoint publication on SQLite and MySQL.
crispinhu27
left a comment
There was a problem hiding this comment.
Automated re-review of head 525ee0c1 (base main @ eb2e368f; current main is be35aff8). The previous approval on a248997f was dismissed by the new push. That review raised no blocking issues, so there are no earlier findings to recheck. This review covers the incremental commit a248997f..525ee0c1.
Scope reviewed
- Chunk publication that tolerates an uncertain commit, and
SaveBoundWorkspaceCheckpointStream, which fences captures by workspace binding. ClaimCheckpointWorkspaceCleanupbinding checks, plus the newConfirm/Reset/Resolve/ResetInterruptedRunnerCleanuppaths.cleanupWorkspace/reconcileClaimedWorkspaceCleanup, which handle reclaim-probe outcomes for local, foreign and Runner workspaces.- The cross-process checkpoint flock in
ensureConversationWorkspace,rebindOfflineConversationWorkspaceandreclaimCheckpointWorkspace. ReclaimExcept/ReclaimDockerSandboxes, which now use lazily loaded owners,SandboxSweepKeepRunIDs/DockerSandboxSweepKeepRunIDs, rename-then-delete reclaim, and child-container lock handling.- The compose/docs revert from
NOBLOBto the defaultFULLrow image.
Verification (isolated environment, synthetic data, no credentials, Go 1.26.11)
go vet ./internal/engine ./internal/repo ./internal/runtime: passed.go test ./internal/repo: passed.-racesubset (Checkpoint|Cleanup|Reclaim|Sweep|ConversationWorkspace|Recovery) oninternal/engineandinternal/repo: passed, with no races reported.- Full
internal/engine/internal/runtimeruns: the only failures were in sandbox-environment tests (Chromium/bwrap/Docker-network/git-helper). The same set fails ona248997fin the same sandbox. The newTestDockerSandboxReclaimWaitsForChildExecutionLockpasses when run alone. - CI on this head: all 16 check runs succeeded.
- Ran the real
cmd/agentflowbinary of this head and ofmainagainst an isolated MariaDB 11.8 to reproduce the issue below.
Blocking issue (1, inline)
- [P2]
internal/repo/runs.go:SandboxSweepKeepRunIDskeeps every registered run. If a cleanup claim commits and the process stops before the directory is removed, that checkout is never reclaimed.main, the merge-base anda248997fall remove it.
Not verified locally
- MySQL 8.x itself (I used MariaDB), the binlog byte figures in the PR body, mixed-version shared storage, and live Worker/Runner reclaim over the network.
This review is limited to the checks above.
The orphan sweep now keeps every registered run, so a checkout that survived a committed cleanup claim (process stopped before DestroyRun, or a claim from an older release) was never removed. Remove it from the run's own cleanup path once no checkpoint lifecycle needs it: hold the checkpoint lock, recheck the claim, and skip pending retries, active leases and runs that are executing again. Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
left a comment
There was a problem hiding this comment.
复审 1497420d(merge-base 21892397,当前 main 91bcf98d)。上次 REQUEST_CHANGES 6039456843 针对的是 525ee0c1。
历史问题
- [P2] 清理 claim 提交后进程退出,留下的 checkout 永远不会被回收:FIXED。在原触发条件下实测,
525ee0c1上能复现,head 上不再出现,详情见原线程。
新增已确认问题(1 条,见行内评论)
- [P2] run 改绑到其他主机后,原主机上的旧 checkout 永远不会被回收。merge-base 上能删,
525ee0c1和 head 上都删不掉,所以是本 PR 引入的回退。
增量 525ee0c1..1497420d 的其他审查
- 合入 main 的
fff65c2e没有冲突改动。 - 新加的
reclaimCleanedWorkspaceLeftover先拿 checkpoint flock,再从库里复核 cleaned_at、revision、host、root,并且会跳过运行中或排队的 run、有活动节点、有终端或对话占用、cleanup_retry_at待定、lease 仍有效的情况。按这些条件检查,没有发现误删正在使用的工作区。 - 相关子集加
-race跑过,没有数据竞争。
验证(隔离环境,最小环境变量,不含凭据,Go 1.26.11,SQLite;本机没有 bwrap,用一个只转发命令的测试替身)
go build ./...和go vet(engine/repo/runtime)通过。- 下表是全量测试结果,括号里是基线
fff65c2e(修复前已合入 main 的提交):
| 包 | head | fff65c2e |
|---|---|---|
| engine | 770 通过 / 1 失败 | 762 通过 / 1 失败 |
| repo | 606 / 0 | 606 / 0 |
| runtime | 921 / 10 | 921 / 10 |
- 剩下的失败两边一样,都是本机缺 Chromium 或 Docker 导致的。
- repo 的 MySQL 集成测试(接 MariaDB 11.8):head 比 merge-base 没有新增失败,checkpoint 相关用例全部通过。
- CI 16 项全部成功。
未验证:没有在 MySQL 8.x 上跑(本机只能装 MariaDB 11.8);真实多实例 rebind 流程、Docker 沙箱相关用例也没有跑。新问题的复现是直接写入改绑后的终态,没有走完整的多实例 rebind 流程。
本次审查只覆盖上述 head。
A run that moved to another host or root left its old checkout on the former host forever: reclaimCleanedWorkspaceLeftover returned early for any foreign bind, and the orphan sweep keeps every registered run. Sandbox roots are host-local (rebindWorkspaceHere already discards the same kind of leftover), so reclaim it under the existing flock, cleaned, revision/binding, activity, lease and cleanup_retry_at checks. Co-Authored-By: Claude Code <noreply@anthropic.com>
… Docker probe dockerAvailable is a process-wide sync.OnceValue. On hosts without Docker an earlier test caches false, so the sweep skipped the fake CLI and TestDockerSandboxReclaimWaitsForChildExecutionLock failed in a full package run while passing on its own. Co-Authored-By: Claude Code <noreply@anthropic.com>
Terminal cleanup now moves a checkout to a .loopforge-reclaimed-* sibling before deleting it, and it runs after the run is already reported finished. A test returning during that rename made t.TempDir's single RemoveAll fail with "directory not empty" (TestSOPNodeRepointedWhilePausedStartsNewChild in CI run 45450048685; TestSOPChildWorksInParentWorkspace under local stress). Engine tests now take their sandbox root from sandboxRoot(t), which removes it first and retries until it stays gone. Co-Authored-By: Claude Code <noreply@anthropic.com>
# Conflicts: # internal/engine/workspace_cleanup.go # internal/repo/workspace_checkpoints.go
|
结论:需要修改 GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号无法提交正式 Approve / Request changes。以下改为普通评论。
|
|
Pushed CI failure (run 45450048685): Fix (test-only), Merge with main (#1284),
Verification (native lane; bwrap stubbed because this host forbids namespaces):
|
crispinhu27
left a comment
There was a problem hiding this comment.
复审 head 944f4efc(合入 main f3d4f41a),结论:APPROVE。
历史问题
- [P2] run 改绑到其他主机后,原主机上的旧 checkout 永远不会被回收(
workspace_cleanup.go):FIXED。按原复现步骤做了单测复现,并用真实cmd/agentflow加 MariaDB 11.8 复测,1497420d和当前 head 做了对照。详情见原线程,该线程已 resolve。
本次增量审查
92f96395:去掉对 foreign bind 的提前 return。其余防护仍然有效:flock、重读 cleaned/revision/binding、活动检查、restore lease、cleanup_retry_at。真实服务器上,root 相同且 restore lease 有效、cleanup_retry_at待定这两种目录都保留,未清理的目录也保留。5f6de83f和0bf9c1d:只改测试。5f6de83f上 core 失败的原因是 teardown 时TempDir RemoveAll ... directory not empty。在本地用 bwrap shim(本机不支持 namespace)按-parallel 48跑TestSOPNode|TestSOPChild100 轮:5f6de83f复现 2 次,944f4efc0 次。944f4efc的冲突解决:beginWorkspaceLease保留了两个 guard;claimIdleConversationWorkspace改了返回值;reclaimCleanedWorkspaceLeftover新增 conversation SOP busy 检查。三处都核对过,没有问题。
验证
go build ./...、go vet ./internal/...均通过。-race跑定向测试全部通过,包括TestReboundRunReclaimsStaleCheckoutOnFormerHost的 7 个子场景。- engine/repo/runtime/httpapi/runner/gitwork 全包:当前 head 与 main
f3d4f41a的失败集合完全相同,都是 25 个,均是本机缺 Docker/Chromium 等环境导致,没有新增失败。 - 和最新 main
7bebfa50试合并:无冲突,build/vet 通过,engine/repo/runtime/gitwork 没有新增失败。 - CI:当前 head 全部 check 通过,含 core 和 platform-required。
未覆盖:生产共享存储上新旧版本混跑、长时间负载(PR 描述里已列为待验证项),本次没有验证。
…point-write-amplification Resolve conflicts with #1327 (idle SOP workspace reclaim and admission release) while keeping this branch's cleanup_retry_at backoff, reclaim confirmation/reset and Docker sweep protection: - ClaimCheckpointWorkspaceCleanup keeps the binding check, CleanupDeferred and cleanup_retry_at, and adds the idle failed/waiting SOP branch, pending_input node check and admission tx options. - RestoreCheckpointWorkspaceBinding clears cleanup_retry_at and always writes the passed host/root, so a Runner SOP can drop a stale bind. - cleanupWorkspace skips running/queued runs, reconciles a committed claim before releasing a cleaned run's slot, releases borrowed SOP slots, and sends Runner runs through local reclaim plus the Runner cleanup task. - Keep SandboxSweepKeepRunIDs/DockerSandboxSweepKeepRunIDs; they already protect leased restores that LiveSandboxRunIDs covered. - Adapt two #1327 tests: a save lease is taken before the cleaned marker, and a failed deletion retries after the cleanup backoff. Co-Authored-By: Claude Code <noreply@anthropic.com>
After the merge with #1327, a cleaned run releases its admission slot on the next sweep. A local checkpoint reclaim whose deletion failed leaves the run cleaned with cleanup_retry_at set and the checkout still on disk; releasing the slot then let another run start while the old checkout was still there. Keep the slot until the recheck confirms the directory is gone (or reopens the claim), and cover it with a regression test. Co-Authored-By: Claude Code <noreply@anthropic.com>
…point-write-amplification Co-Authored-By: Claude Code <noreply@anthropic.com>
合入最新 main(cb78a499 → 11e7521)并解决与 #1327 的冲突新 head: 冲突怎么解的(两边语义都保留)
合并后补的一处(
|
| 场景 | 本 PR(87ea7345) | main |
|---|---|---|
A. failed SOP 空闲满 1 小时(改库里的 updated_at/last_used_at 模拟) |
只保存 1 次(308KB)、回收、名额 released、事件「工作区已空闲超过 1 小时…」;之后 3 轮 sweep 不再保存;Retry 恢复 checkout,sha256sum -c 通过,run 成功 |
一致 |
| B. succeeded 运行处于 cleanup hold | hold 期间最多补存 1 次(完成时的保存比 run 行最后一次更新早几十 ms,下一轮补一次),之后多轮不再保存;解除 hold 后回收 1 次、不再存档;POST /workspace/restore 恢复,sha 校验通过 |
同样会补存 1 次(这是本来就有的时序,不是合并引入) |
| C. 空闲 SOP 删除失败(沙箱根目录设成只读) | 6 轮 sweep 只保存 1 次,cleanup_retry_at 推后 10 分钟,名额保持 held;恢复写权限、退避到期后回收、名额释放,Retry 恢复并校验通过 |
每 20 秒重新导出一次(2 分钟 6 次);而且第一次删除已删掉文件、只剩目录,后面的存档变成 39 字节空包,Retry 时 sha256sum -c 失败(数据丢了) |
TestPassFailedScriptContinuesDownstreamHTTP failed in CI with "TempDir RemoveAll cleanup: ... directory not empty": the succeeded run's terminal reclaim renames the checkout to a .loopforge-reclaimed-* sibling while t.TempDir is being removed (the log shows the reclaim finishing after the store was closed). Use the same retrying sandbox root helper as the engine tests for the httpapi tests that run SOPs to completion. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
CI 补充:87ea7345 的
|
crispinhu27
left a comment
There was a problem hiding this comment.
复审 head 1f49a659(base main 11e75217)。944f4efc 上的 APPROVE 已被新推送 dismiss,本次覆盖增量 944f4efc..1f49a659:7e356d35(清理结果未确认时保留空闲 SOP 的运行名额)、1f49a659(httpapi 测试改用可重试的 sandbox root),以及两次 main 合并。
历史问题
- 之前两条 [P2](清理 claim 提交后遗留 checkout、run 改绑后原主机遗留 checkout)在
944f4efc已实测 FIXED,线程已 resolve;本次增量没有回退这两处逻辑。
增量审查
7e356d35:cleanupWorkspace在runnerID == ""且cleanup_retry_at未到期时保留 admission 名额。核对了收敛路径:到期后reconcileClaimedWorkspaceCleanup会探测目录,ResolveCheckpointWorkspaceCleanup在目录缺失时清掉cleanup_retry_at、在仍存在时重开 claim,之后才会releaseCleanedRunAdmission,不会永久占名额;runner 路径的判定未改。新增用例TestSOPIdleReclaimKeepsSlotWhileDeletionUnconfirmed本地-count=5通过。1f49a659:给 httpapi 的TestPassFailedScriptContinuesDownstreamHTTP、TestRunStreamDeliversLiveSnapshots换上了sandboxRoot重试清理。
验证(隔离环境,Go 1.26.11,合成数据,无凭据)
go test ./internal/engine -run 'TestSOPIdleReclaim|TestConversationWorkspace|TestCleanup|TestReclaim|TestSandbox'通过;go test ./internal/repo通过。- 本机没有非特权 user namespace,
bwrap起不来(TestGateExecutionScopeIsExplicit本地直接因 bwrap 缺失失败),依赖真实 sandbox 的运行期证据以 CI 日志为准,见行内评论。
阻塞问题(1 条,见行内评论)
- [P1] 当前 head 的
core必过检查失败:TestGateExecutionScopeIsExplicit在t.TempDir拆除时与仍在跑的终端清理竞争,platform-required随之失败。
结论:REQUEST CHANGES。
* fix: only offer configured executors in model pickers * fix: show when no executors are available * fix: count shared and runner-login executors as configured The executor model catalog marked a CLI configured only when the caller saved a personal key, so users on the platform's shared CodeBuddy Key or with account login on their default runner saw no executors in the role wizard and SOP preview, although SOP runs accept them. Reuse the SOP run credential check for `configured` and report the personal key separately as `personal`. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(executors): resolve picker credentials on the project default machine Project SOPs run on the user's project default machine (#1285), but /api/executor-models only checked the personal default, so a user whose only machine login was on the project default saw no usable CLI in the role wizard. ExecutorCredentials now resolves the machine with ResolveRunnerDefaults(user, project), and the role and SOP editors pass the current project and cache the catalog per user and project. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(executors): offer cloud pool logins in the executor pickers A project SOP whose responsible user has no default machine runs on a cloud pool runner with that runner's account login, but the pickers only looked at the default machine and showed no executor at all. Resolve credentials the same way selectSOPExecutionTarget does and count a CLI when any online pool runner logs it in. Co-Authored-By: Claude Code <noreply@anthropic.com> * test(httpapi): build the cloud-pool picker test without path/filepath #1223 replaces every filepath.Join(t.TempDir(), "workspaces") in catalog_test.go with sandboxRoot(t) and drops the path/filepath import. The new TestExecutorModelsConfiguredFollowsTheCloudPool still used filepath, so merging both PRs (in either order, no textual conflict) broke the internal/httpapi test build. The test only reads the executor catalog, so a plain t.TempDir() is enough and compiles on both bases. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: roberttwang <roberttwang@tencent.com> Co-authored-by: roberttwang <u_dc6754cd1ee5@users.noreply.local> Co-authored-by: Claude Code <noreply@anthropic.com>
|
与最新 main 本 PR 落后 main 18 个提交(#1339 Runner 统一、#1301、#1342、#1343、#1348、#1351、#1345 等)。GitHub 显示无冲突,本地在
测试(Go 1.26.11,MySQL 8.4.7)
部署实测(试合并
|
…point-write-amplification Resolve conflicts with #1410, a smaller follow-up subset of this branch: - conversation_workspace.go / workspace_checkpoint_chunks.go: keep this branch's implementation; drop the duplicate cleanupHeld check and the duplicate heldWorkspaceCheckpointNeedsSave/workspaceCheckpointNeedsSave helpers the textual merge produced. - workspace_checkpoint_publish_test.go: keep this branch's file, which already contains all of #1410's tests plus the rebind test. - workspace_checkpoint_chunks_test.go: keep the chunked-archive assertion and add #1410's round-trip check of the repaired archive. - #1410's runtime read-only directory restore and its new tests merge cleanly and are kept as is. Co-Authored-By: Claude Code <noreply@anthropic.com>
合入最新 main(2e5176f1 / #1410),解决 4 个文件的冲突新 head: 冲突怎么解的
验证(容器内,Go 1.26.11,MySQL 8.4.7)
部署实测(本机起平台,全新 MySQL 库,设了 AGENTFLOW_SESSION_SECRET,native 沙箱,只用脚本节点,不调模型)
场景 D 说明:本 PR 的 |
crispinhu27
left a comment
There was a problem hiding this comment.
复审 5c8313bc:这是把 main 2e5176f1(含 #1410)合入 f32d4dc4 的合并提交。f32d4dc4 上之前的问题都已确认修复,并且已经 APPROVE 过。这次重点检查冲突是怎么解的,以及 #1410 的语义有没有保留。
合并解决
git show --remerge-diff 5c8313bc显示,手工改动只在 4 个冲突文件的冲突块里,内容都是删掉重复部分,没有夹带别的改动。conversation_workspace.go和workspace_checkpoint_chunks.go两个文件,和f32d4dc4完全一致。- #1410 原来在
claimIdleConversationWorkspace里加的cleanupHeld && !heldWorkspaceCheckpointNeedsSave(...)被删掉了,但同一位置已经有条件更宽的(cleanupHeld || meta.CleanupDeferred(now)) && ...,能覆盖原来的判断。辅助函数各只定义一次。 - 两个测试文件都保留了双方的断言。#1410 的其余改动(只读目录恢复等)和 main 完全一致。
验证(隔离的非特权用户,合成数据)
- #1410 的测试在 head 上全部通过:
TestConversationWorkspaceReusesCheckpointDuringPreviewHold、TestWorkspaceCheckpointRestoresRestrictedDirectoryModes、TestWorkspaceCheckpointSmallStreamReplacesInlineArchive、TestWorkspaceCheckpointPublishCommitError。TestMySQLWorkspaceCheckpointPublishCommitError在 MariaDB 11.8 下也通过。 go build、go vet通过。- 以下几组测试,head 和 base 的失败集合都相同,差别只来自环境(缺 bwrap、Docker、Chromium,以及 MariaDB 和 MySQL 的方言差异):
go test ./internal/repo ./internal/runtimeinternal/engine全量(-timeout 45m):两边都是 96 项失败。- repo 包在 MariaDB 下:两边都是 8 项失败。
- CI:16/16 通过。
场景 D(只读目录导致回收删除失败):在 head 和 base 上做了对照实测。
- 两边都会残留删不掉的目录,并且每轮清扫都会打一行日志,所以这不是本 PR 引入的。
- head 上残留目录改名为
.loopforge-reclaimed-*;名额在退避期过后会释放,存档始终完整。 - base 上名额一直处于 held 状态。第 2 轮清扫会把删了一半的目录重新存档,覆盖掉完整的存档,导致文件丢失。
- 不阻塞。按作者的计划,等 #1412 合入后改用
RemoveWorkspaceTree即可。
未覆盖:远程 Worker 的回收路径(probeRemoteCheckpointRoot)需要多实例,这次只做了代码审查和单元测试,没有端到端实测。
以上结论只针对本次的审查范围和验证结果,不代表代码绝对没有缺陷。
CR + 部署实测:合并 main 2e5176f(#1410)后的 head
|
| 文件 | 合并结果 | 核对 |
|---|---|---|
internal/engine/conversation_workspace.go |
和合并前的 PR 版本(5c8313bc^1)完全相同 |
#1410 加的 cleanupHeld 提前返回、heldWorkspaceCheckpointNeedsSave、workspaceCheckpointNeedsSave、readyToReclaim / needsSave 在 PR 里本来就有,而且 PR 版本更完整:持有判断多了 meta.CleanupDeferred(now);取租约后会重读 run,校验 revision、host 和 root 后再算 hold;删除失败重试时会把 previous 传进去比对 digest。逐行比过,没有哪条 #1410 分支在 PR 里缺失。 |
internal/repo/workspace_checkpoint_chunks.go |
同上,取 PR 版本 | #1410 的两处改动(去掉 ≤12 MiB 走内联 BLOB 的分支、published 改成 commitMayHavePublished)PR 里都有,PR 另外多了 SaveBoundWorkspaceCheckpointStream 的绑定校验(ErrWorkspaceCheckpointStale)。旧的内联存档仍能读取。 |
internal/repo/workspace_checkpoint_chunks_test.go |
PR 版本加上 #1410 新增的 TestWorkspaceCheckpointSmallStreamReplacesInlineArchive 和恢复内容断言 |
相对 main,只是把 ClaimCheckpointWorkspaceCleanup 换成 PR 的新签名,又多了 ArchiveID/ArchiveChunks 断言,#1410 的断言一条没少。 |
internal/repo/workspace_checkpoint_publish_test.go |
PR 版本(3 个测试) | main 这个文件的全部内容都包含在里面(相对 main 只有新增),提交回执丢失的语义没变,另外多了绑定变更期间抓取的用例。 |
其他核对:
- main 在 11e7521..2e5176f 之间改过、PR 没碰过的文件,合并结果和 main 逐字节一致。
- 两边都改过、但自动合并的文件(
workspace_cleanup.go、runs.go、conversation_workspace_test.go等):main 新加的wakeRunClaimLoop()、DeleteRun后的PromoteQueuedRunsAsync()都保留了;LiveSandboxRunIDs已被 PR 的SandboxSweepKeepRunIDs/DockerSandboxSweepKeepRunIDs替换,没有遗留调用方。fix(workspace): reduce checkpoint writes and restore read-only directories #1410 的TestConversationWorkspaceReusesCheckpointDuringPreviewHold在合并结果里,测试函数集合 = main ∪ PR。 internal/runtime/workspace_checkpoint.go(fix(workspace): reduce checkpoint writes and restore read-only directories #1410 只读目录恢复)和 main 相同。go build ./...、go vet(engine/repo/runtime/httpapi)通过。
单测(本机,Go 1.26.11 + MySQL 8.4.7,AGENTFLOW_TEST_MYSQL_DSN)
go test ./internal/engine ./internal/repo ./internal/runtime:PR 和 main 2e5176f 失败集合完全相同(各 23 个),PR 没有新增失败。失败原因都是本机缺 Docker 和 Chromium、git 全局身份不同,以及 MySQL 准入用例共用一个库互相干扰。- 在全新库上单独跑
-run 'Checkpoint|Workspace|Reclaim|Cleanup|SOPIdle|MySQL':两边同样各有 9 个失败,原因同上,名单一致。
部署实测(本机起平台,全新 MySQL 库,native 沙箱 + bwrap 替身,只用脚本节点,不调模型;用 SQL 把 updated_at/last_used_at 往前拨 2 小时来模拟空闲 1 小时)
| 场景 | 本 PR 5c8313bc |
main 2e5176f1 |
|---|---|---|
| A. failed SOP 空闲回收 → Retry | ✅ 只存档 1 次(308 KB,分块 1 块、无内联 BLOB),回收后名额变为 released,写入事件「工作区已空闲超过 1 小时,已归档回收并释放运行名额」;之后 3 轮 sweep 不再存档;Retry 先恢复,sha256sum -c 通过,run 成功 |
✅ 一致 |
| W. waiting SOP(停在审批门)空闲回收 → 审批 | ✅ 只存档 1 次、回收、释放名额;审批后恢复,sha256sum -c 通过 |
✅ 一致 |
| B. succeeded 处于 cleanup hold | ✅ hold 期间最多补存 1 次(完成时那次存档比 run 行最后一次更新早几 ms,下一轮会补一次),之后连续 3 轮不再存档;解除 hold 后回收 1 次;POST /workspace/restore 恢复,sha 校验通过 |
✅ 一致(补存 1 次是原有时序,不是这次合并带来的) |
| C. 空闲 SOP 删除失败(沙箱根目录设为只读) | ✅ 6 轮 sweep 只存档 1 次,名额保持 held,cleanup_retry_at − workspace_cleaned_at = 600 s;恢复写权限后、退避到期前不重试;把退避拨到期后回收、释放名额,复用原来的检查点(saved_at 不变);Retry 恢复,sha 通过 |
❌ 每 20 秒重新导出一次(2 分钟导出 6 次),而且删除删掉一半后,存档变成 39 字节的空包,Retry 时 sha256sum -c 失败(数据丢失) |
| D. waiting SOP,工作区里有只读目录树(类似 Go module cache) | ✅ 只存档 1 次;删除只读树失败后名额保持 held,挂 10 分钟退避;拨到期后释放名额;审批后恢复,sha256sum -c 全过,目录权限仍为只读 |
❌ 每轮重新导出(6 次),删到一半时覆盖了完整检查点,审批后校验失败,run 变成 failed |
| E. 大工作区(20 MB 不可压缩数据)分块发布与读取 | ✅ archive_bytes=20 004 859、archive_chunks=5,分块表 5 行、只有 1 个 archive_id,archive 内联列为空;Retry 恢复,sha 通过 |
✅ 一致 |
F. 会话工作区租约路径:在已回收的 run 上用 IDE 写文件(PUT /workspace/file) |
✅ 自动恢复并写入,用完后存档 1 次(包含新文件);未空闲时 3 轮不再存档;再次空闲回收;Retry 后 payload 的 sha 和 IDE 写入的文件都在 | ✅ 一致 |
所有检查点都是分块格式(archive_chunks ≥ 1,内联 BLOB 长度为 0),说明 #1410「小存档也走分块」在合并后生效。
留意(不是这次合并引入的)
- 场景 D 里,只读目录树已经被改名成
.loopforge-reclaimed-*,但删不掉,会一直留在沙箱根目录下(不影响数据正确性和名额)。这就是已经计划在 fix(workspace): reclaim workspaces that contain read-only directories #1412 合入后处理的那一项:把removeReclaimedSandbox和removeMatching里的os.RemoveAll换成runtime.RemoveWorkspaceTree。
实测脚本:e2e1223.py <A|W|B|C|D|E|F>,另有 build/launch 脚本和两边的原始日志。
CR + 部署实测
|
| 场景 | PR 5c8313bc |
main 2e5176f1 |
|---|---|---|
S1. waiting SOP:Cursor grok-4.7 high 写 out/model.md(CKP-7319),加 6 MiB 二进制和只读的 Go module 目录树(500/555/444);空闲满 1 小时后 approve |
8/8:存 1 次检查点(6.29 MB,2 个 chunk)后回收;approve 后恢复,模型文件、大文件 sha、目录权限 500 500 555 555 444 都对 |
2/6:回收删到只读目录就停,下一轮 sweep 用残缺的树(只剩 gomod)覆盖检查点(273 B),approve 后 verify 失败,丢文件 |
| S2. succeeded run 处于 cleanup hold,空闲满 1 小时 | 6/6:140 秒内只存 1 次,binlog +0;hold 期间改的文件在解除 hold 回收后能恢复,8 MiB 文件完整 | 6/6(#1410 已经修好这项) |
S3. failed SOP(Cursor 写 report/summary.md,脚本失败)+ 删除失败(沙箱根目录 0555) |
6 轮 sweep 只存 1 次;cleanup_retry_at 推后 10 分钟(第一次删除失败约 2 分钟后采样,还剩 485 秒);名额保持 held,目录保留。恢复写权限、退避到期后回收,名额改为 released,之后 3 轮不再存;Retry 恢复后 payload sha 和模型文件都对,run succeeded |
6 轮 sweep 存了 6 次(每 20 秒重新存档),没有退避 |
| S4. 同 S3,但在退避期内(根目录已经可写)直接 Retry | 8/8:恢复后 run succeeded,workspace_cleaned_at、cleanup_retry_at 都清掉,checkout 完整 |
Retry 拿到的工作区被删掉了一半:.retry-ok 和 report/summary.md 都没了,节点按首次运行重跑,失败 |
[P3] 只读目录回收后残留的隐藏目录不会被清理,每 20 秒打一行日志(不阻塞,已知,跟 #1412 的合入顺序有关)
S1 回收后,沙箱根下留下 .loopforge-reclaimed-AVRG…(只读的 gomod/…/v1.0.0.mod)。removeMatching 每轮 sweep 都会用 os.RemoveAll 重试,一直报 unlinkat …: permission denied:我观察了约 20 分钟,同一个目录打了 64 行日志,目录一直在。这不会丢数据(检查点在删之前已经存好,原目录也已经不在原位)。不过 #1410 合入后,恢复时会如实还原 0555 目录,所以凡是带 Go module cache 的工作区,每回收一次就会留一份残留。修复会话在上一条评论里已经写了:#1412 合入后,把 removeReclaimedSandbox 里的 os.RemoveAll 和传给 removeMatching 的 os.RemoveAll 都换成 runtime.RemoveWorkspaceTree。建议 #1412 合入后马上跟进;如果本 PR 先合,就由 #1412 那边顺手把这两处一起换掉。
结论:LGTM。合并解得对,本 PR 修的三类问题(只读目录导致检查点被覆盖、删除失败时反复存档、退避期内 Retry 拿到删了一半的工作区)在部署环境里和 main 对照都确认修好了。评审 token 就是作者本人,GitHub 不允许作者 Approve 自己的 PR,所以只发评论。
Resolve the sandbox_manager.go conflict with #1412: removeMatching keeps its per-caller remove func, and both callers now delete through RemoveWorkspaceTree. DestroyRun retires a checkout and then removes it, and ReclaimExcept prunes orphans and retired copies; with os.RemoveAll a read-only Go module cache left .loopforge-reclaimed-* directories behind. Add regression tests for both paths. The second sop-mode test from #1411 builds its manager on sandboxRoot(t) like the rest of the file; this branch dropped the path/filepath import. Co-Authored-By: Claude Code <noreply@anthropic.com>
…fication TestSandboxDescriptionRoundTrips builds its manager on sandboxRoot(t) like the other httpapi tests on this branch, which no longer import path/filepath in catalog_test.go. Co-Authored-By: Claude Code <noreply@anthropic.com>
已合入最新 main 并解决冲突,补上 #1412 约定的 RemoveWorkspaceTree:head 3f66a97main 先后合入了 #1412、#1411、#1231、#1429、#1413、#1432,本 PR 因此出现冲突。这次推了两个合并提交(没有强推),并按合并顺序约定补上了 #1412 合入后要做的改动。 改动
验证
|
crispinhu27
left a comment
There was a problem hiding this comment.
复审 head 3f66a977(base main @ 68ed15f3)。5c8313bc 上的 APPROVE 6065222502 已被新推送 dismiss。本次范围是 5c8313bc..3f66a977 的两个合并提交:01422c4f 合入 main 080e91b0(#1412/#1411/#1231/#1429/#1413),3f66a977 合入 main 68ed15f3(#1432)。
合并解决(git show --remerge-diff)
01422c4f:只有internal/runtime/sandbox_manager.go有真冲突。解决方式是保留本 PR 的removeMatching(..., remove func(string) error)回调结构,并把 #1412 的RemoveWorkspaceTree接进去:ReclaimExcept传RemoveWorkspaceTree,removeReclaimedSandbox在改名后用RemoveWorkspaceTree(retired)删除。#1412 的语义没有丢。另外新增了sandbox_reclaim_readonly_unix_test.go;issue_sop_mode_test.go改用sandboxRoot(t)。3f66a977:catalog_test.go中 #1432 新增的用例改用sandboxRoot(t),产品代码没有手工改动。- 两边都改过的其余文件(
studio_test.go等)是自动合并,已核对,没有重复或丢失的逻辑。
历史问题
- 已知非阻塞 P3(只读目录回收后留下
.loopforge-reclaimed-*清不掉):FIXED。把新增的sandbox_reclaim_readonly_unix_test.go拷到上一版5c8313bc运行,两个用例都失败,报unlinkat …/.loopforge-reclaimed-…/go.mod: permission denied,说明问题在旧版本上真实存在。在3f66a977上go test -count=3 -run 'ReadOnly|ReclaimExcept|DestroyRun' ./internal/runtime/全部通过。 - 之前的 [P2]×2 和 [P1] 线程在早先的复审中已确认修复,本次合并没有改动相关代码,对应用例(
TestReboundRunReclaimsStaleCheckoutOnFormerHost、TestCleanedWorkspaceLeftoverKeepsCheckpointLifecycle、TestReclaimExcept*等)在 head 上通过。
验证(隔离工作区,无凭据,Go 1.26.11)
- head 和 main
68ed15f3两边都执行了:go build ./...通过,go vet ./internal/{runtime,httpapi,engine}通过。 - 两边都执行了全包
go test(./web除外,已先构建 chatbot)。失败用例集合完全一致(顶层各 140 项,head 没有新增失败),都是环境原因:容器里没有 Docker、Agent CLI 等可执行文件。本 PR 相关的 checkpoint、回收、清理用例都通过。 - GitHub CI 在
3f66a977上 16/16 通过。
未覆盖:依赖 Docker 的沙箱回收用例在本环境无法运行,这部分由 CI 覆盖。
结论:APPROVE。
独立 CR + 部署实测
|
| 场景 | 结果 |
|---|---|
| A 失败的 LOOP 空闲 1 小时 | 只存 1 次 checkpoint;回收后释放名额,之后 3 轮不再重复存档;Retry 恢复后 sha 校验通过,run succeeded |
| W 停在审批节点的 LOOP 空闲 1 小时 | 只存 1 次;回收后目录删除、名额释放、没有 .loopforge-reclaimed-* 残留;批准后恢复,sha 校验通过 |
| B 已成功的 LOOP 处于 cleanup hold | 等待期间 checkpoint 时间戳一直不变(不重复写);解除 hold 后只回收 1 次;恢复后 sha 校验通过 |
| C 删除失败(沙箱根目录改成只读) | 只存 1 次,名额保留,cleanup_retry_at = 认领时间 + 600 秒;根目录恢复可写、到点后回收,用的是同一份 checkpoint;Retry 恢复后 succeeded |
| D 工作区里有只读目录(模拟 Go module cache,#1412 的场景) | 空闲后回收成功,没有残留;批准后每个文件 sha 都一致,只读权限也恢复了 |
| E 约 20 MiB 不可压缩的检出 | 分 5 块存储,不走 inline;回收后恢复,sha 校验通过 |
| F 回收后在 IDE 写文件 | 检出被恢复,用完后存了新的 checkpoint;下一次空闲回收后,再恢复仍能读到这次修改,run succeeded |
| #1432 沙箱描述 | PUT /api/sandboxes 带 description 保存后,读回一致 |
测试
go vet ./...通过。go test ./internal/httpapi ./internal/runtime ./internal/repo ./internal/engine ./internal/mcpserver ./internal/domain:本 PR 和 main68ed15f3在同一台机器上跑,本 PR 没有比 main 多出来的失败。失败的都是本机缺 Docker、bwrap、Chromium 沙箱这类环境问题,两边一样。internal/engine加上 bwrap 替身、超时放到 40 分钟后两边各重跑一次:都只有同样 3 个失败。其中 2 个是本机全局 git 身份覆盖了测试里设置的提交作者,1 个是 Chromium 起不来,和本 PR 无关。
独立 CR + 部署实测
|
CR + 部署实测收窄后的
|
Robert0622
left a comment
There was a problem hiding this comment.
17:00 轮验证 ab12e77c:在新 main fe6c45f0 上试合并无冲突,可合入
验证基准:head ab12e77c,base main fe6c45f0(相比 05:10 轮的 c039a78a 新增 #1409、#1320、#1314、#1349、#1448)。
16:00 会话已在 930ad003 上完成验证,结论在 fe6c45f0 仍成立:
| 项目 | 结果 |
|---|---|
试合并 fe6c45f0 |
✅ 无冲突 |
go vet ./internal/runtime/... |
✅ 通过 |
| go test 失败集合 | 与 main 相同(19 个环境类失败:缺 Docker/Chromium/user namespace) |
| webtest | 385/385 全过 |
fe6c45f0 增量改动(evolution 功能、assistant context 携带、sandbox CSS)不与 internal/runtime/workspace_*.go 重叠,05:10 的部署实测结论(A/W/C/D/E/F/P 7 个场景全过)不受影响。
05:10 评论问到的并发保护收窄:收窄后 claimIdleConversationWorkspace 不再在 BeginWorkspaceCheckpointSave 后复核 run 状态,采集期间被恢复/改绑时可能采集到旧路径。如果这是有意用 revision 兜底,建议在代码注释里写清取舍;若需要恢复这层保护,可在 BeginWorkspaceCheckpointSave 之后重读 run 并对比 revision / workspace host+root / idle / generation。
结论:LGTM,CI 16/16,MERGEABLE,待其他评审批准后可合入。
在最新 main
|
23:00 轮验证
|
| 项目 | 结果 |
|---|---|
| 新提交 | 无(head 未变) |
试合并 main be6918d7 |
无冲突,10 个文件 |
| CI | 16/16 ✓ |
| go vet ./internal/... | 通过 |
| TestRemoveWorkspaceTree*(本地) | 2/2 ✓ |
| 未解决 review thread | 0 |
新 main 中 #1452 改了 internal/engine/workspace_preparation.go,本 PR 改了 internal/engine/workspace_cleanup.go 和 conversation_workspace.go,文件不重叠,合并干净。上一轮结论不变:回收失败时先 rename 再删、不覆盖已发布存档的实现正确,可合入。token 身份是 PR 作者本人,只评论,不点 Approve。
crispinhu27
left a comment
There was a problem hiding this comment.
复审 head ab12e77c(base main @ 68ed15f3,PR base main @ 68ed15f3)。上次 REQUEST_CHANGES 6056389405 针对 1f49a659,增量提交 f32d4dc4..ab12e77c。
历史问题复测结果
- [P2] cleanup claim 提交后进程退出,遗留 checkout 永远不被回收:FIXED(已在
6043077582确认,线程已 resolve,本次增量未回退相关逻辑)。 - [P2] run 改绑到其他主机后,原主机旧 checkout 永远不被回收:FIXED(已在
6045323123确认,线程已 resolve,本次增量未回退相关逻辑)。 - [P1]
TestGateExecutionScopeIsExplicit与 TempDir 拆除竞争导致core必过检查变红:FIXED。f32d4dc4把 engine/httpapi 两个测试包里所有runtime.NewManager改用sandboxRoot(t)的可重试清理根,原线程已 resolve;ab12e77c在当前 head 的 CIcore检查结果为 success,platform-required结果为 success,16/16 全绿。
增量 f32d4dc4..ab12e77c 审查
ab12e77c("Narrow workspace reclaim fix to preserving checkpoints")将改动收窄至 10 个文件(+279/−13):
workspace_remove.go:reclaimWorkspaceTree先os.Rename到.workspace-reclaim-<rand>再递归删除,删失败只记日志,checkout 已脱离原路径不会被后续快照打包。sandbox_manager.go:removeMatching对reclaimedWorkspacePrefix前缀的条目跳过.过滤和workspaceInUse检查,使用RemoveWorkspaceTree直接清除,逻辑自洽。workspace_checkpoint_stream.go:回收重试时传入previous,对本地路径采集结果 sha256 与已存档比对,完全一致走reuseWorkspaceCheckpoint避免重复写;worker 侧 checkout 缺失时走同样的复用路径;os.ErrNotExist分支对previous != nil时也走复用。workspace_cleanup.go:Worker 删完回包失败时不再立即 reset,而是用 5s 探测checkpoint-status404 +WorkspaceErrorMissing判断 Worker 已清掉。workspace_checkpoints.go:ClearVerifiedWorkspaceCheckpointError的WHERE包含lease_token/lease_until/sha256,RowsAffected != 1返回ErrWorkspaceInUse,不会误清他人存档。- 两个新测试文件(
workspace_reclaim_failure_test.go、workspace_reclaim_test.go)覆盖「删到一半失败」和「rename 场景」。
未发现新的阻塞问题。作者关于「收窄掉的三处并发保护」的疑问已在 05:10/17:00 轮评论中核实:这三处在 merge-base 上本来就没有,不是本 PR 引入的回退。
验证
- CI 16/16 全绿(含
core、platform-required、e2e-required)。 - 三个历史线程均已 resolve。
- main
be6918d7试合并无冲突(作者 23:00 轮确认)。 go vet ./internal/{runtime,engine,repo}通过(来自作者 23:00 轮自测及历次独立 CR)。
审查范围:workspace reclaim / checkpoint 保全逻辑,sandbox_manager 目录清理路径,测试隔离修复。未验证:MySQL 8.x 多实例真实 rebind 流程、Docker 沙箱端到端(本机无相关凭据,对应 CI job 均 success)。
Problem
A partial checkout deletion can leave an incomplete tree at the active path and replace the last complete checkpoint on the next sweep. A Worker can also remove a checkout and lose the reply, leaving reclamation unresolved. Repeated failures can republish the same archive and grow MySQL's binary log.
Change
Verification
The checkpoint write reduction and readonly-directory restore fixes are already covered by #1410 and #1412. This patch covers failures during platform and Worker reclamation. It does not add cross-host orphan cleanup.