Skip to content

fix(workspace): preserve complete checkpoints when reclaim fails - #1223

Open
Robert0622 wants to merge 21 commits into
mainfrom
codex/workspace-checkpoint-write-amplification
Open

Robert0622 wants to merge 21 commits into
mainfrom
codex/workspace-checkpoint-write-amplification

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Move the live checkout out of its active path before recursively deleting it. The existing sandbox maintenance sweep retries removal of detached files.
  • After a reclaim error, use the existing Worker status request to confirm a missing checkout. Verify and reuse an identical stored archive on retries, while still capturing any late edits.
  • Keep the existing checkpoint schema and Worker protocol.

Verification

  • In a non-root Linux reproduction, main partially deleted the checkout and replaced its complete checkpoint. The narrowed patch restored all files and the original readonly directory permissions.
  • Exercise failures before deletion, lost replies after actual deletion, and a temporarily unreachable Worker.
  • With real MySQL 8.4.13 using FULL row images, eight sweeps during Worker reclaim failures added 218,202,344 bytes of binlog on main and 45,296 bytes with this patch. Both builds made eight export and reclaim calls. Late edits were saved and restored after recovery.

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.

crispinhu27
crispinhu27 previously approved these changes Nov 22, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 once workspace_cleaned_at is 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), TestConversationWorkspaceCleanupHoldKeepsCurrentCheckpointUntilReclaim and TestBackgroundWorkspaceSaveRecoversFromSlowRunnerAndExpiredLease fail. TestConversationWorkspaceStaleCleanupKeepsReclaimedCheckpoint fails on 5208d8c4. 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, core and browser.

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 for web/native-chat, which is unrelated to this change; CI core covers 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
crispinhu27 previously approved these changes Nov 22, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 as ClaimCheckpointWorkspaceCleanup, honoured by the claim and by the pre-lease short-circuit in claimIdleConversationWorkspace, and cleared by RestoreCheckpointWorkspaceBinding for the restoring lease.
  • saveConversationWorkspace(previousSHA): digest reuse only after verifyStoredCheckpoint succeeds, 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 independent CheckpointStatus probe reports WorkspaceErrorMissing.
  • compose.yaml --binlog-row-image default/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/repo passed. Full go 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:
    • main stores it inline and logs 100,678,159 B.
    • This head stores it as chunks and logs 16,332 B.
    • With NOBLOB on main, the legacy inline renewals log 14,640 B.
  • Upgrade/rollback on one DB:
    • main writes a 3 MiB inline archive.
    • This head adds the nullable cleanup_retry_at column, reads the legacy archive (sha matches), and writes a 5 MiB chunked archive.
    • main reads 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 config renders --binlog-row-image=NOBLOB by default and FULL with LOOPFORGE_MYSQL_BINLOG_ROW_IMAGE=FULL.
  • CI on this head: all 16 check runs succeeded. first-run starts the Compose MySQL 8.4 service with the new flag.

Not verified locally

  • MySQL 8.4 itself; I used MariaDB locally, and CI first-run covers 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.

@cocofhu00

Copy link
Copy Markdown
Contributor

结论:建议合入

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 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
  • ClaimCheckpointWorkspaceCleanup binding checks, plus the new Confirm/Reset/Resolve/ResetInterruptedRunnerCleanup paths.
  • cleanupWorkspace / reconcileClaimedWorkspaceCleanup, which handle reclaim-probe outcomes for local, foreign and Runner workspaces.
  • The cross-process checkpoint flock in ensureConversationWorkspace, rebindOfflineConversationWorkspace and reclaimCheckpointWorkspace.
  • ReclaimExcept / ReclaimDockerSandboxes, which now use lazily loaded owners, SandboxSweepKeepRunIDs / DockerSandboxSweepKeepRunIDs, rename-then-delete reclaim, and child-container lock handling.
  • The compose/docs revert from NOBLOB to the default FULL row 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.
  • -race subset (Checkpoint|Cleanup|Reclaim|Sweep|ConversationWorkspace|Recovery) on internal/engine and internal/repo: passed, with no races reported.
  • Full internal/engine / internal/runtime runs: the only failures were in sandbox-environment tests (Chromium/bwrap/Docker-network/git-helper). The same set fails on a248997f in the same sandbox. The new TestDockerSandboxReclaimWaitsForChildExecutionLock passes when run alone.
  • CI on this head: all 16 check runs succeeded.
  • Ran the real cmd/agentflow binary of this head and of main against an isolated MariaDB 11.8 to reproduce the issue below.

Blocking issue (1, inline)

  • [P2] internal/repo/runs.go: SandboxSweepKeepRunIDs keeps 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 and a248997f all 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.

Comment thread internal/repo/runs.go Resolved
roberttwang and others added 2 commits November 24, 2026 14:17
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 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 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。

Comment thread internal/engine/workspace_cleanup.go Resolved
roberttwang and others added 5 commits November 24, 2026 17:10
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
@cocofhu00

Copy link
Copy Markdown
Contributor

结论:需要修改

GitHub 拒绝了 Pull Request Review 接口(HTTP 403:Tencent 组织启用了 OAuth App 访问限制)。当前账号无法提交正式 Approve / Request changes。以下改为普通评论。

  1. 与 main 冲突(mergeable_state=dirty)。请先变基到当前 main 后再合。
  2. CI 已失败。core(https://github.com/Tencent/LoopForge/actions/runs/45450048685/job/138644317418)里 TestSOPNodeRepointedWhilePausedStartsNewChild(0.66s)失败,原始信息是 testing.go:1464: TempDir RemoveAll cleanup: unlinkat .../TestSOPNodeRepointedWhilePausedStartsNewChild1438258102/002: directory not empty。platform-required 因此也是 failure。这和 internal/engine/workspace_cleanup.go 里清理占用、跨进程确认目录是否还在的改动一致:测试结束时临时目录仍非空。请在该测试结束前释放工作区锁和仍占用目录的进程,变基后重跑 go test ./internal/engine -run TestSOPNodeRepointedWhilePausedStartsNewChild。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

Pushed 944f4efc (merges main f3d4f41a / #1284 and fixes the failed core check on 5f6de83f).

CI failure (run 45450048685): TestSOPNodeRepointedWhilePausedStartsNewChild passed its assertions but failed in teardown with TempDir RemoveAll cleanup: ... directory not empty. Cause: this PR's removeReclaimedSandbox renames a checkout to a .loopforge-reclaimed-* sibling before deleting it, and terminal cleanup runs after the run is already reported finished. A test that returns during that rename races t.TempDir's single RemoveAll. Isolated repro: 187/3000 teardown failures with rename-then-delete vs 0/3000 with main's direct delete. The product behaviour is intended; only the tests were fragile.

Fix (test-only), 0bf9c1d: new internal/engine/sandbox_root_test.go sandboxRoot(t); engine tests take their sandbox root from it, and it removes the root first, retrying until it stays gone.

Merge with main (#1284), 944f4efc:

Verification (native lane; bwrap stubbed because this host forbids namespaces):

  • go build ./..., go vet ./internal/... pass.
  • engine/repo/runtime/httpapi full packages on this head vs main f3d4f41a: identical failure set (15 tests needing Docker/Chromium/bwrap/global git identity), no new failures; repo passes.
  • TestSOPNode*|TestSOPChild* ×300 at -parallel 48: this head 0 failures; 5f6de83f reproduces directory not empty (TestSOPChildRetryResumesFailedParent).

crispinhu27
crispinhu27 previously approved these changes Nov 24, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 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|TestSOPChild 100 轮:5f6de83f 复现 2 次,944f4efc 0 次。
  • 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 描述里已列为待验证项),本次没有验证。

roberttwang and others added 3 commits November 25, 2026 09:00
…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>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

合入最新 main(cb78a499 → 11e7521)并解决与 #1327 的冲突

新 head:87ea7345(49160f87 合 cb78a49 解冲突,7e356d35 补一处合并后才出现的名额问题,87ea7345 再合 11e7521 / #1329,无冲突)。

冲突怎么解的(两边语义都保留)

合并后补的一处(7e356d35)

#1327 让已清理的 run 在下一轮 sweep 释放名额。和本 PR 的 cleanup_retry_at 放在一起后会出一个问题:本地删除结果未知时,run 已标 cleaned、目录还在,名额却已被放掉。现在本地认领只要还挂着 cleanup_retry_at 就不放名额,等复查确认目录已删(或重开认领)再放。新增回归测试 TestSOPIdleReclaimKeepsSlotWhileDeletionUnconfirmed(去掉这个判断时失败,加上后通过)。

另外按本 PR 的语义调整了 #1327 的两个测试:TestSOPIdleReclaimReconcilesAlreadyCleanedSlots 先取保存租约再标 cleaned,因为本 PR 不允许给已回收的 checkout 再开保存租约;TestSOPIdleReclaimTouchAndDescendantActivity 里删除失败后,要等 10 分钟退避才重试,不再每轮重新导出。

验证(容器内、Go 1.26.11、MySQL 8.4.7)

  • go build ./...、go vet ./... 通过;bash scripts/build-chatbot.sh 通过。
  • go test ./internal/... ./web/ ./cmd/...,和 main 11e7521 同环境对比:SQLite 两边都是 148 个失败、MySQL(AGENTFLOW_TEST_MYSQL_DSN,-p=1)两边都是 150 个,集合完全相同,没有新增失败,也没有 panic。失败都是本机缺 bwrap、Docker、Chromium、ssh 导致的。
  • feat(sop): reclaim idle failed/waiting SOP workspaces and release admission slots #1327 的 sop_idle_reclaim_test.go、repo/run_admission_test.go、repo/workspace_checkpoints_test.go、httpapi/workspace_restore_test.go,以及本 PR 的 workspace_cleanup_test.go、workspace_checkpoint_publish_test.go、sandbox_reclaim_test.go、checkpoint_recovery_test.go,共 64 个测试,SQLite 和 MySQL 下全过。
  • cd webtest && npm ci && npm test:292/292;python3 scripts/check-public.py 通过。

部署实测(本机起平台,全新 MySQL 库,设了 AGENTFLOW_SESSION_SECRET,native 沙箱,脚本节点,不调模型)

场景 本 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>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

CI 补充:87ea7345 的 core 只挂了 TestPassFailedScriptContinuesDownstreamHTTP,报错是 TempDir RemoveAll cleanup: ... workspaces: directory not empty。日志里紧接着有 record reclaimed workspace ...: sql: database is closed,说明测试结束时,成功 run 的终态回收(先改名成 .loopforge-reclaimed-* 再删)还在跑,跟 t.TempDir 的删除撞上了。这和之前 engine 测试修过的是同一类问题。

1f49a659 只改测试:httpapi 包加了和 engine 一样的 sandboxRoot(t)(先删沙箱根,失败就重试),用在会把 SOP 跑到结束的 pass_test.go 和 stream_test.go。本机用 bwrap 替身把这个用例连跑 30 次全过;整个 httpapi 包和 main 基线比没有新增失败。

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 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。

Comment thread internal/runtime/sandbox_manager.go Resolved
Robert0622 added a commit that referenced this pull request Nov 25, 2026
* 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>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

与最新 main f7b066d8 试合并验证:f32d4dc4 无需修改,可直接合入

本 PR 落后 main 18 个提交(#1339 Runner 统一、#1301、#1342、#1343、#1348、#1351、#1345 等)。GitHub 显示无冲突,本地在 f7b066d8 上做了试合并(只在本地,没有推送,避免让现有 Approve 失效),有 8 个文件两边都改过,都自动合并成功。重点看了这两处:

  • internal/engine/workspace_cleanup.go:main 在两处释放名额后调用的 wakeRunClaimLoop() 都还在(cleanupWorkspace 借用会话工作区分支,以及 releaseCleanedRunAdmission)。
  • internal/repo/runs.go:合并后已经没有调用 LiveSandboxRunIDs 的地方,SandboxSweepKeepRunIDs / DockerSandboxSweepKeepRunIDs 是唯一入口。
  • main 新增的 restoreLocalArchivedOutputs(Prevent SOP runs from hanging after artifact write failures #1301)只在节点执行时写已准入 run 的 checkout,不和空闲回收同时发生。

测试(Go 1.26.11,MySQL 8.4.7)

  • build-chatbot、go build ./...、go vet ./... 通过。
  • go test ./... 全量:main 832e2bef 和试合并结果失败的都是同样 18 个,都是本机缺 Docker、Chromium、user namespace、git 身份造成的环境失败,没有新增失败。合入 fix(chat): keep MCP requests alive while approval is pending #1351/test: repair main platform CI for Runner selection and run evaluation #1345 后又跑了 httpapi/runtime/mcpserver/engine/repo,失败的 15 个也都在这份名单里。
  • internal/repo、internal/engine 接 MySQL(AGENTFLOW_TEST_MYSQL_DSN)跑:两边失败集合一致。其中 admission/工作区相关的 5 个用例换成全新库单独跑,main 和合并结果都通过(共享库时失败是前面的用例留了数据)。

部署实测(试合并 c89f822 = main f7b066d8 + 本 PR,全新 MySQL 8.4.7 库,native 沙箱)

场景 结果
A. failed SOP 空闲满 1 小时 只存档 1 次(308KB)后回收,名额 held→released;之后 3 轮 sweep 不再存档;Retry 恢复 checkout,sha256sum -c 通过,run 成功
B. succeeded run 处于 cleanup hold hold 期间最多补存 1 次,之后连续多轮都不再存档;解除 hold 后回收 1 次;POST /workspace/restore 恢复,sha 校验通过
C. 删除失败(沙箱根目录只读) 6 轮 sweep 只存档 1 次,cleanup_retry_at 推后 10 分钟,名额保持 held;恢复写权限、退避到期后回收并释放名额,Retry 恢复后校验通过
D. 真实模型(Cursor CLI grok-4.7-high) Agent 节点写出 notes/report.md(含 RECLAIM-7319),后面的脚本节点失败后空闲回收,检查点 397B 写进 run_workspace_checkpoint_chunks(inline 列为 0),Retry 后模型写的文件逐字节一致,verify 节点通过

run_workspace_checkpoints 里 4 个 run 的 inline archive 长度都是 0,存档都进了 chunk 表。

…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>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

合入最新 main(2e5176f1 / #1410),解决 4 个文件的冲突

新 head:5c8313bc(合并 f32d4dc4 和 2e5176f1)。#1410 是本 PR 的子集("smaller follow-up to #1223"),所以代码按本 PR 的完整实现解,测试保留 #1410 新加的语义。

冲突怎么解的

验证(容器内,Go 1.26.11,MySQL 8.4.7)

  • go build ./...、go vet ./...、bash scripts/build-chatbot.sh 都通过。
  • go test ./internal/... ./web/ ./cmd/...,与 main 2e5176f1 在同一环境对比,SQLite 和 MySQL(AGENTFLOW_TEST_MYSQL_DSN,-p=1)各跑一遍:失败集合与 main 相同,没有新增失败,也没有 directory not empty。本机没有 bwrap、Docker、Chromium、ssh,这些失败两边都有。internal/engine 包因为缺 bwrap 的用例每个要等 30 秒,两边都接近默认的 10 分钟超时。所以这个包另外用 -timeout 40m 两边各跑一遍:SQLite 和 MySQL 下两边都是 87 个失败,集合完全相同,没有 panic。
  • fix(workspace): reduce checkpoint writes and restore read-only directories #1410 的 4 个新测试,以及 SOPIdle、Checkpoint、Cleanup、Reclaim 相关测试,repo 和 runtime 全部通过,engine 只剩 main 上同样失败的 Chromium 用例。
  • cd webtest && npm test:307/307。python3 scripts/check-public.py 通过。

部署实测(本机起平台,全新 MySQL 库,设了 AGENTFLOW_SESSION_SECRET,native 沙箱,只用脚本节点,不调模型)

场景 结果(5c8313bc)
A. failed SOP 空闲满 1 小时 只保存 1 次(308KB),然后回收,名额改为 released;之后几轮 sweep 都不再保存。Retry 恢复 checkout,sha256sum -c 通过
B. succeeded 运行处于 cleanup hold hold 期间 7 轮 sweep 一次都没有再保存。解除 hold 后回收 1 次(内容 sha 未变),之后 3 轮也不再保存;POST /workspace/restore 恢复,sha 校验通过
C. 删除失败(沙箱根目录设成只读) 6 轮 sweep 只保存 1 次,cleanup_retry_at 推后 10 分钟,名额一直 held。恢复写权限并让退避到期后,回收完成、名额释放,Retry 恢复且校验通过
D(新增). waiting SOP 的工作区里有只读目录树(模拟 Go module cache,chmod -R a-w) 只保存 1 次(158KB),之后不再重复保存,残缺的树也没有覆盖检查点。approve 后恢复,sha256sum -c 全部通过,目录权限恢复成 555

场景 D 说明:本 PR 的 removeReclaimedSandbox 先 rename、再调 os.RemoveAll。遇到只读目录时,删不掉的部分会以 .loopforge-reclaimed-* 隐藏目录的形式留在沙箱根下(这次约 228KB),sweep 每 20 秒重试一次并打一行 permission denied 日志。这不会丢数据:检查点在删除前已经存好,root 已经不在原位,复查后正常确认并释放名额。等 #1412(runtime.RemoveWorkspaceTree)合入后,我会把这里的 os.RemoveAll 和传给 removeMatching 的 os.RemoveAll 都换成 RemoveWorkspaceTree。目前 #1412 还没合,这次没有改。

crispinhu27
crispinhu27 previously approved these changes Nov 25, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 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/runtime
    • internal/engine 全量(-timeout 45m):两边都是 96 项失败。
    • repo 包在 MariaDB 下:两边都是 8 项失败。
  • CI:16/16 通过。

场景 D(只读目录导致回收删除失败):在 head 和 base 上做了对照实测。

  • 两边都会残留删不掉的目录,并且每轮清扫都会打一行日志,所以这不是本 PR 引入的。
  • head 上残留目录改名为 .loopforge-reclaimed-*;名额在退避期过后会释放,存档始终完整。
  • base 上名额一直处于 held 状态。第 2 轮清扫会把删了一半的目录重新存档,覆盖掉完整的存档,导致文件丢失。
  • 不阻塞。按作者的计划,等 #1412 合入后改用 RemoveWorkspaceTree 即可。

未覆盖:远程 Worker 的回收路径(probeRemoteCheckpointRoot)需要多实例,这次只做了代码审查和单元测试,没有端到端实测。

以上结论只针对本次的审查范围和验证结果,不代表代码绝对没有缺陷。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 部署实测:合并 main 2e5176f(#1410)后的 head 5c8313bc

结论:合并正确,没有发现问题,没有推新提交。 #1410 的实现和测试语义都保留了,#1223 的完整实现也没丢,没有重复或遗漏的逻辑。CI 16/16 全过。

CR 要点(4 个冲突文件)

文件 合并结果 核对
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 只有新增),提交回执丢失的语义没变,另外多了绑定变更期间抓取的用例。

其他核对:

单测(本机,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 脚本和两边的原始日志。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 部署实测 5c8313bc:LGTM,可合入(剩 1 个已知 P3,跟 #1412 的合入顺序有关)

本轮范围:f32d4dc4..5c8313bc 只有一个提交,合入 main 2e5176f1(#1410),解决冲突。

代码评审

测试(Go 1.26.11,本机)

  • go vet ./internal/repo/ ./internal/runtime/ ./internal/engine/ 通过。
  • go test ./internal/repo/ ./internal/runtime/,加上 engine/httpapi 里 Checkpoint|Reclaim|Cleanup|SOPIdle|ConversationWorkspace|WorkspaceRestore|Admission 相关用例:repo、httpapi 全过。runtime/engine 失败 13 个,和 main 2e5176f1 在同一环境下失败的用例完全相同,都是本机缺 Docker、Chromium 或 git 身份造成的。

部署实测(两套平台:PR 5c8313bc 和 main 2e5176f1,各用全新的 MySQL 8.4.7 库,native 沙箱;真实模型用 Cursor CLI grok-4.7 high)

场景 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,所以只发评论。

roberttwang and others added 2 commits November 26, 2026 02:32
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>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

已合入最新 main 并解决冲突,补上 #1412 约定的 RemoveWorkspaceTree:head 3f66a97

main 先后合入了 #1412、#1411、#1231、#1429、#1413、#1432,本 PR 因此出现冲突。这次推了两个合并提交(没有强推),并按合并顺序约定补上了 #1412 合入后要做的改动。

改动

  1. internal/runtime/sandbox_manager.go 冲突:fix(workspace): reclaim workspaces that contain read-only directories #1412 在 main 上把 removeMatching 里的 os.RemoveAll(dir) 换成了 RemoveWorkspaceTree(dir)。本 PR 把这一行改成了调用方传入的 remove(dir)。解法是保留 remove(dir),同时把两个调用方都换成 RemoveWorkspaceTree:
    • DestroyRun → removeReclaimedSandbox:先 rename 成 .loopforge-reclaimed-*,再用 RemoveWorkspaceTree(retired) 删除。
    • ReclaimExcept 清理孤儿目录和退役副本时,也改用 RemoveWorkspaceTree。
    • 合并后,生产代码里的 os.RemoveAll 和 RemoveWorkspaceTree 调用,除这两处外和 main 完全一致。
  2. 新增回归测试 internal/runtime/sandbox_reclaim_readonly_unix_test.go:用只读的 Go module cache 目录树,分别测 DestroyRun,以及 ReclaimExcept 对孤儿目录和退役副本的清理。两个用例在本提交上通过;把这两处换回 os.RemoveAll 后都会失败,报 permission denied,并留下 .loopforge-reclaimed-* 目录。
  3. 两处合并后的编译问题:main 新加的 issue_sop_mode_test.go(fix(issues): let agents create requirements without an SOP #1411)和 catalog_test.go(fix(catalog): keep the sandbox description #1432)里各有一个用例用了 filepath,但本分支已经从这两个文件里删掉了 path/filepath import。我把这两处改成和同文件其他用例一样用 sandboxRoot(t)。只改了测试。

验证

  • go build ./...、go vet ./... 通过。
  • runtime、engine、repo、domain、runner、httpapi 六个包全量 go test,失败用例和 main 080e91b0 逐条一致,都是本机缺 docker、Chromium、真实 bwrap 导致的。httpapi 只失败 2 个浏览器用例,main 上同样失败。
  • 部署实测:合并后的构建,全新 MySQL 库,native 沙箱,脚本节点 SOP。沿用上一轮的 7 个场景,全部 PASSED:
场景 结果
A 失败的 SOP 空闲 1 小时 只存 1 次 checkpoint;回收后释放名额,之后 3 轮扫描不重复归档;Retry 恢复后 sha256 校验通过
W 卡在审批的 SOP 空闲 1 小时 只存 1 次 checkpoint,回收后释放名额;批准后恢复,校验通过
B 已成功的 SOP 带清理保留期 保留期内不重复存 checkpoint;解除后只回收一次;restore API 校验通过
C 沙箱根目录只读导致删除失败 只存 1 次 checkpoint,名额保持占用,按 600 秒退避重试;目录恢复可写且到期后回收;Retry 校验通过
D 工作区里有只读目录树(模拟 Go module cache) 空闲回收后批准恢复,所有文件都还原了。工作区根目录下 .loopforge-reclaimed-* 残留为 0。上一轮 5c8313b 跑同一场景时残留 1 个,本次修好
E 约 20 MiB 不可压缩的检出 分 5 个 chunk 存储,不内联;回收后恢复,校验通过
F 回收后在 IDE 里编辑文件 先恢复再编辑,checkpoint 包含编辑内容;Retry 后 sha256 和编辑内容都校验通过
  • CI 16/16 通过。
  • 同一实例上用 CodeBuddy deepseek-v4.1-flash 在 native 沙箱里对话执行 shell 命令,返回正常。

crispinhu27
crispinhu27 previously approved these changes Nov 26, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 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。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

独立 CR + 部署实测 3f66a977:合 main 的解法正确,LGTM,可合入

本轮有两个新的合并提交:01422c4f 合入 main 080e91b0,包含 #1412、#1411、#1413、#1429;3f66a977 合入 main 68ed15f3(#1432)。我单独审了一遍,并部署实测。没有发现问题,没有改代码。token 身份是 PR 作者本人,所以只评论,不点 Approve。

代码审查(git show --remerge-diff)

部署实测(PR 构建,全新 MySQL 库,native 沙箱,脚本节点,平台 20 秒一轮维护)

场景 结果
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 和 main 68ed15f3 在同一台机器上跑,本 PR 没有比 main 多出来的失败。失败的都是本机缺 Docker、bwrap、Chromium 沙箱这类环境问题,两边一样。
  • internal/engine 加上 bwrap 替身、超时放到 40 分钟后两边各重跑一次:都只有同样 3 个失败。其中 2 个是本机全局 git 身份覆盖了测试里设置的提交作者,1 个是 Chromium 起不来,和本 PR 无关。

@Robert0622 Robert0622 changed the title fix(engine): avoid repeated workspace checkpoints during cleanup holds fix(workspace): preserve complete checkpoints when reclaim fails Nov 26, 2026
@Robert0622

Copy link
Copy Markdown
Collaborator Author

独立 CR + 部署实测 ab12e77c:收窄后的实现成立,LGTM

这一版只剩「回收失败时不覆盖已发布的存档、先把 checkout 挪走再删」,cleanup_retry_at 退避、ResolveCheckpointWorkspaceCleanup 和 deployment.md 的说明都去掉了,净改动 10 个文件 +278/−13。我按「失败前就删不动」「删到一半删不动」「Worker 删完丢回包」三条路径分别审了一遍并做了对照实测,没有发现需要改代码的问题。token 身份是 PR 作者本人,所以只评论,不点 Approve。

代码审查

  • reclaimWorkspaceTree:os.Rename 到同级的 .workspace-reclaim-<随机>,再对挪走的那份递归删除。删除失败只记日志、仍然返回 nil,checkout 已经离开活动路径,下一轮清扫按前缀把它当普通目录删;removeMatching 只对带这个前缀的条目跳过 . 开头过滤和 workspaceInUse 检查,不会碰正在用的 run 目录。
  • saveConversationWorkspace(previous):只在 reclaim 重试时传 previous,用 io.MultiWriter 边写边算 sha256;内容与已发布存档一致时走 reuseWorkspaceCheckpoint(先 verifyStoredCheckpoint 再清错误位),不一致就照常写入,晚到的编辑不会丢。空 checkout 分支 digest.Reset() 后再写 EmptyWorkspaceCheckpoint,摘要和实际内容对得上。
  • workerWorkspaceMissing:只在 reclaim 回包报错时用 5 秒探一次 status,404 + WorkspaceErrorMissing 才算「Worker 已删掉」,否则照旧 reset 重试;cleanupWorkspace 里那个 context.Background() 调用不吞别的错误。
  • ClearVerifiedWorkspaceCheckpointError 的 WHERE 里带了 lease_token/lease_until/sha256,RowsAffected != 1 返回 ErrWorkspaceInUse,不会误清别人的存档。

部署实测(本机 MySQL 8.4.7 + native 沙箱,私有库,未碰 Tencent/LoopForge)

PR 上 7 个场景全过:A(失败 SOP 空闲回收→Retry 恢复,sha 一致)、W(waiting 审批回收→批准后恢复)、C(沙箱根目录只读导致删不掉)、D(只读目录树恢复与权限)、E(20 MiB 大存档分块)、F(回收后 IDE 写入→再次回收保留编辑)、P(checkout 里放 root 拥有的子目录,删到一半失败)。每个场景的存档都只有 1 份、saved_at 在多轮清扫里不变、Retry 后 sha256sum -c 通过。

与 main 的对照差在 C 和 P 上,正是这个 PR 修的问题:

  • C(沙箱根只读):main 上 6 轮清扫写了 6 次存档,checkout 里的文件被删光(filesInCheckout: []),最终存档 39 字节——完整存档被空目录覆盖,Retry 恢复不出任何文件;PR 上 checkout 原样保留 payload.txt/payload.sha/.e2e-retry-ok,只保存 1 次,根目录恢复可写后一轮回收成功、存档 sha 不变。
  • P(删到一半失败):main 上 6 轮清扫写 6 次(binlog 801,494 字节),存档被改写成只剩 zz-locked(156 字节),Retry 校验失败;PR 上同样 6 轮只保存 1 次(binlog 323,871 字节,基本是首次 300 KB 存档),checkout 被整体挪走、活动路径为空,Retry 恢复后 RESTORE_VERIFIED 通过。

Go 侧:go vet ./internal/{runtime,engine,repo} 通过;go test 定向集合里 internal/runtime、internal/repo 全过,internal/engine 4 个失败与 main 逐条相同(都是本机缺 bwrap 的环境问题)。CI 16/16 绿。

仍待确认(不阻塞)

  • 删不掉期间没有退避,每 20 秒一轮清扫都会 verifyStoredCheckpoint 读一次已发布存档;不写 MySQL,但大工作区上是一笔持续的读 IO。以前用退避掩盖过这个问题,收窄后回到每轮一次。
  • workerWorkspaceMissing 的远程 Worker 路径只有单测(TestWorkerWorkspaceReclaimAfterFailure)覆盖,本机没起多实例,端到端没跑。
  • 上一版里「清理结果未确认时保留空闲 LOOP 名额」的 ResolveCheckpointWorkspaceCleanup 随收窄一起删了;现在失败就 reset 并保留名额,行为与 main 一致,只是不再有显式的 resolve 步骤。

以上结论只针对 ab12e77c,不代表没有其他缺陷。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR + 部署实测收窄后的 ab12e77c:回收/保存行为符合预期,16/16 全绿;有一处并发保护的收窄请确认

3f66a977 之后推了 ab12e77c("Narrow workspace reclaim fix to preserving checkpoints"),把改动收窄到「回收时保住 checkpoint」,删掉了跨进程 flock、claim 后的状态复核、写放大相关的批次改动,以及 824 行的 checkpoint_recovery_test.go。本轮只审这个收窄后的 diff 并重新实测。token 身份是 PR 作者本人,所以只评论,不点 Approve。

代码审查

  • reclaimWorkspaceTree(internal/runtime/workspace_remove.go):先把整个 checkout os.Rename 成 .workspace-reclaim-<rand>,再删改名后的目录;删失败只记日志,原路径已经是干净的,不会留下半个 checkout 被后续 checkpoint 打包。sandbox_manager.removeMatching 里对 .workspace-reclaim- 前缀不再当隐藏目录跳过、也不再受 workspaceInUse 保护,符合「已脱离原路径」的语义。
  • saveConversationWorkspace(..., previous)(workspace_checkpoint_stream.go):回收重试时先下载/打包到临时文件并同时算 sha256,和目标 sha 一致就走 reuseWorkspaceCheckpoint(只清 error/retry 字段,保留 archive 和 saved_at);连不上 worker 且 worker 确认 checkout 缺失时(5s 探测 checkpoint-status 404 + WorkspaceErrorMissing)复用旧 checkpoint;cleanupWorkspace 结尾也用同一个探测忽略 reply 失败。这几处和实测一致(见下)。
  • 收窄掉的并发保护,请确认是有意为之:
    1. ensureConversationWorkspace / rebindOfflineConversationWorkspace 去掉了 TryLockWorkspaceCheckpoint 的跨进程 flock,现在恢复/改绑只靠 DB lease;
    2. claimIdleConversationWorkspace 在 BeginWorkspaceCheckpointSave 之后不再重读 run(原来会复核 revision / workspace host+root / 空闲 / generation),另一个实例在这几毫秒到 5 分钟的采集窗口内恢复或改绑时,采集的是旧路径上的目录,可能把一份不完整的快照发布出去;
    3. 保存返回 ErrWorkspaceCheckpointStale 时不再当作「本轮跳过」而是作为 saveError 返回。
      回收认领本身仍按 ClaimCheckpointWorkspaceCleanup(runID, token, revision) 的 revision + 节点状态 + checkpoint 行条件串行,不冲突;风险只在「采集期间被恢复/改绑」。如果这是有意用 revision 兜底,建议在代码注释里写清取舍。

部署实测(本机 MySQL + ab12e77c 构建,私有实例/私有库;脚本节点 + native 沙箱,bwrap 用测试替身,沙箱隔离本身未验证)

  • A 失败 SOP 空闲 1 小时:只归档一次(saved_at 之后 3 个 sweep 不变),回收后 workspace_cleaned_at 落下、名额 released、目录删除;Retry 后 RESTORE_VERIFIED,payload sha256 校验一致。通过
  • W 等待审批的 SOP 空闲 1 小时:归档一次、回收、放名额;审批后恢复,RESTORE_VERIFIED。通过
  • B 成功 SOP 在 cleanup hold 下:hold 期间 4 个 sweep 不再重写 checkpoint;解除 hold 后回收一次;恢复接口返回的 sha 一致。通过
  • D 等待审批 + 只读目录树(Go module cache 风格):空闲回收,审批后每个文件逐字节恢复。通过
  • E 约 20 MiB 不可压缩 checkout:分块 manifest(archive_chunks>1、无 inline blob),回收后 Retry 恢复校验通过。通过(首次和 A~D 并行跑时 Retry 返回过一次 400,单独重跑通过,判断是并发负载下的时序问题,不是稳定复现)
  • C 空闲失败的 SOP + 沙箱根只读导致删除失败:6 个 sweep 期间只归档一次、目录保留、名额保持 held(不无限重写)。通过
    • 注意:本 head 已没有「删除失败后 +10 分钟再试」的 cleanup_retry_at 机制(收窄时一起去掉了),所以脚本里那条 backoff 断言在这个 head 上不成立;实际行为是保持 held,直到下次 sweep 删除成功再回收。

测试与 CI

  • 定向 go test:internal/runtime 的 TestReclaimExceptRemovesDetachedFilesAndKeepsRestoredCheckout 通过;internal/engine 的 9 个 workspace/checkpoint 用例全部通过;internal/repo 的 checkpoint 用例全部通过。
  • internal/engine 里 TestMainBotResumeLegacyScriptCreatesUsableWorkspace、TestMainBotRetryExecutesAfterWorkspaceOwnerReleasesLease、TestEnsureRunBrowserRestoresReclaimedWorkspaceWithStaleRun 在本机失败,在 main c039a78a 上失败完全一致(本机无 user namespace / 无浏览器),不是本 PR 引入。
  • CI 16/16 全绿。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,待其他评审批准后可合入。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

在最新 main fe6c45f0 上的复验(ab12e77c):无冲突,可以合入

main 已推进到 fe6c45f0(含 #1314 进化工作台、#1349 对话交接、#1409 工作台选择器、#1448 沙箱字段),本 PR 的改动(internal/engine、internal/runtime 工作区检查点与回收、internal/api 等)与这些提交没有文件重叠。

  • 试合并:无冲突;git merge-tree 干净。
  • 单测:go vet ./... 通过;go test ./... 与 main 失败集合相同(19 个环境类)。全量跑里 TestBrowserViewCapturesLighterFramesWhileScrolling 偶发失败一次,单跑 main 和本 PR 各 2 次都通过,是 Chromium 滚动帧的环境抖动,与本 PR 无关。
  • 部署实测:沿用上一轮已确认的结论(只读目录导致检查点被覆盖、删除失败时反复存档、退避期内 Retry 拿到删了一半的工作区三类问题,在部署环境里和 main 对照都修好了);本轮没有新提交,没有新代码需要复测。
  • 上一轮评论里问的「收窄时去掉的三处并发保护」,已核对这三处在 main 上本来就没有,不是回退。

CI 16/16、MERGEABLE;仍需要非作者批准(crispinhu27 之前的 Approve 已被后续推送作废)。评审 token 是作者本人,不点 Approve。

@Robert0622

Copy link
Copy Markdown
Collaborator Author

23:00 轮验证 ab12e77c:与 main be6918d7 无冲突,可合入

验证基准:head ab12e77c,base main be6918d7(相比上轮 fe6c45f0 新合入 #1442、#1452、#1450、#1461)。

项目 结果
新提交 无(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 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审 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 的 CI core 检查结果为 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-status 404 + 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)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants