Repository navigation
fix(workspace): reduce checkpoint writes and restore read-only directories - #1410
Conversation
crispinhu27
left a comment
There was a problem hiding this comment.
初审 head 14e17fae(base / main f7b066d8)。审查了 7 个文件的全部改动:SaveWorkspaceCheckpointStream 一律写入 chunk 表,以及提交回复丢失时保留 chunk 的处理;预览清理暂停期间 claimIdleConversationWorkspace 的保存条件(heldWorkspaceCheckpointNeedsSave / workspaceCheckpointNeedsSave),以及恢复前的再次捕获;恢复时目录先以 0700 解包、再按深度从深到浅应用原始权限,失败时把权限改回去。
验证都在隔离环境中进行,用非特权 Linux 用户、无凭据、合成数据:
- 在
internal/repo、internal/runtime、internal/engine上跑go vet和go test:head 和 base 的失败集合完全一致(各 102 项,原因都是本机缺 bwrap/Docker/Chromium),本 PR 没有新增失败。 - 本 PR 新增的
TestWorkspaceCheckpointRestoresRestrictedDirectoryModes在 head 上通过;放到 base 上会失败(mkdirat module-cache/version: permission denied),说明它能复现原缺陷。 TestConversationWorkspaceReusesCheckpointDuringPreviewHold以及 Checkpoint/Publish/Backoff 相关测试通过。- 用本地 MySQL 8.4.13(binlog_row_image=FULL)跑了
TestMySQLWorkspaceCheckpointChunks、SharedBackoff、PublishCommitError(committed=true/false),head 上全部通过。 - 在同一个 MySQL 库里做了新旧版本交替读写的兼容性检查:base 写入的内联小 checkpoint,head 能读;head 改写为 chunk 后,base 能读;base 再写回内联格式时,旧 chunk 被清理,head 仍能读。
- 额外写了恢复边界的探测测试:tar 中子文件排在父目录条目之前;目录权限为 0000、0500、0555;同级目录
a-x的排序;恢复后再次捕获并恢复,权限保持;发布阶段失败(目标目录在解包期间变为非空)时,父目录下没有残留 staging 目录,已有文件也没被改动。以上全部符合预期。 - CI 16/16 通过。
没有发现阻塞问题。不阻塞的说明:本 PR 和 #1223 改的是同一个函数 claimIdleConversationWorkspace,先合入其中一个后,另一个需要 rebase。另外没有复现 PR 描述里的磁盘和 binlog 增长数据,那部分是性能结论,不影响正确性判断。
|
CR + 部署实测: 代码
测试(Go 1.26.11,MySQL 8.4.7,
部署实测(main 和 PR 各用一个全新库,native 沙箱,对比时只起一个平台,binlog 只算本平台写入)
和本 PR 无关、已有的问题(不阻塞,供 #1223 参考):用非 root 跑 native 沙箱时,工作区里只要有嵌套只读目录,回收用的 |
|
Post-merge deployment check (local MySQL 8.4 FULL row image, native sandbox, Cursor
Fixed in #1412, with reproduction tables and tests. |
…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>
What changed
This is the smaller follow-up to #1223 and #1138. Save streamed workspace checkpoints in the existing chunk table, including small archives, so MySQL lease updates keep the archive bytes out of the row image. Preserve the last published chunks when a commit reply is lost.
Keep a current checkpoint while preview cleanup is on hold. Capture again before reclaiming so late workspace edits are included.
Restore files into a writable staging tree and apply directory modes before publishing it. The restricted-directory regression checks nested contents, original modes, and cleanup of the validation tree.
Scope
Compatibility
The existing chunk schema and reader are used. Legacy inline checkpoints remain readable and convert when saved again. The previous main build also read a newly chunked checkpoint in the shared test database. Reclamation ownership and deployment settings are unchanged. The persistent Worker reclaim failure case remains in #1223.
Validation
An isolated row-image comparison on an initialized database reduced the same heavy batch from 106.1 MiB to 90.1 MiB with NOBLOB. The 16 MiB difference was the old chunk images in the delete events. The application changes use the existing MySQL settings.
Safety