Repository navigation
fix(control-plane): reject hard-linked checkpoint artifacts - #9512
Conversation
runPath() treated a hard link as an exclusive checkpoint artifact because lstat().isFile() is true and realpath() stays on the in-directory name. Replay then reported ok for a shared inode, and commitCheckpoint truncated that inode through writeSynced. Require an exclusive regular file (regular file and nlink === 1) on both the in-directory path and a relocated candidate. A missing path can still be created as a new exclusive artifact. Signed-off-by: Duang777 <duangjl007@gmail.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Exact head: d9358bc06ac931612d469e46fdffcaf830ef056f
动机 / Motivation
运维者恢复中断的 Turn 或迁移后的运行目录时,需要继续读取原来的 checkpoint 和结算凭据。 正常迁移的文件应继续可读,缺失或存在共享链接的候选文件应明确拒绝,避免把无法确认的 checkpoint 当成已结算结果。 File 和 SQLite 的正式 CLI 保留了原有正常迁移与缺文件语义。候选对有共享链接的工件返回已有结构化错误,覆盖回读和写入。 本次范围是本地 checkpoint 工件检查,沿用原 Turn、索引和文件锁约束。任意外部进程同时修改文件系统及存储掉电不在已验证范围。
改动思路 / Approach
继续用 checkpoint owner 管理工件查找、恢复和写入;文件所有权检查复用 quota 工件的同一规则,原索引和 Turn 身份仍由已存在的机制保护。 当前切片只给持久化 checkpoint 的现有两条查找路径增加普通独占工件条件,其他恢复行为沿用。 两个路径调用同一资格判断,合法复制和目标文件尚未创建的正常分支继续使用现有逻辑。文件不合格时保留先前的不确定结果分类与原轮读回提示。
具体改动 / Changes
3 个文件 +204/-6,其中两组是测试。独立的候选验证包含 16 项正式 CLI File/SQLite 检查与 6 项 TypeScript 检查。基线的 6 个正常迁移、缺失工件对照也通过。已检查 DCO 和精确 diff whitespace。
关键代码讲解
isExclusiveRegularFile检查本地工件资格,并由同一 owner 的两个路径复用。 类型与谓词runPath保留同目录和迁移副本两条路径,沿用原有缺失处理、checkpoint 错误与恢复方式。 路径所有者committedArtifacts在读回时核对原工件和已承认的身份,读回不追加另一份原轮结果。 回读
规范基线 6915df67db6a8836df344a661f295006873a3ba8。原轮恢复和异常读回均在现有 checkpoint、File/SQLite 回读契约下通过。 Turn 恢复合同
对主干的风险 / Risks
定向测试使用隔离本地运行时,检查正常复制、原目录回读、缺文件与候选文件资格。候选拒绝分支仍返回原结构化错误,保持原索引、原工件和额度记录。读取路径继续以原结算身份关联上下文,使用者可以按同一原轮定位和检查恢复结果。历史拒绝用例的红测来自作者记录,本轮独立执行候选回归及两版普通路径对照。 公开 CLI 回归 TS 验证
我的整体评价 / Verdict
未发现阻塞项。正常迁移继续从已承认的原索引回读,拒绝异常文件不更换任务、receipt 或额度身份。 异常回读仍返回 checkpoint_commit_unknown 和原 Turn 的恢复提示;合法复制继续成功。 改动是 checkpoint 持久化与 CLI 诊断,没有渲染界面变更。 外部进程并发修改、其他平台的文件系统行为、断电和托管 CI 未验证。
English verdict: APPROVE. The candidate enforces checkpoint artifact eligibility on the existing commit and replay paths. Independent File and SQLite tests preserve ordinary recovery and confirm that rejected reads and writes preserve recorded state.
Goal And Delivered Outcome
runPath()andrelocatedCheckpointArtifact()accepted a hard link as an exclusive checkpoint artifact.lstat().isFile()is true for a hard link, andrealpath()stays on the in-directory name, so a second name outside the current runs directory was treated as exclusive.ok/idempotent_replayfor a hard-linked artifact whose bytes still matched the index, andcommitCheckpointtruncated that shared inode throughwriteSynced. After, both inspect and commit fail closed withcheckpoint_commit_unknownand leave the outside inode and index bytes unchanged. Exclusive regular files, missing paths created on commit, and the existing symlink / directory / missing / honest-copy cases still pass.main.What changed
Root cause: checkpoint path resolution only required a regular file. Node reports a hard link as a regular file, so the containment check could not see the other directory entry.
Fix, local to
loopx/control_plane/goals/checkpoint_commit.ts: an artifact may be opened or written only whenlstatis a regular file andnlink === 1. Both branches ofrunPath()use that check (the in-directory lexical path andrelocatedCheckpointArtifact()).ENOENTis unchanged, so a new exclusive artifact can still be created on commit. Relocated hard links fail withcheckpoint artifact path is invalid. In-directory hard links fail withcheckpoint artifact is not a regular file. Both stay incheckpoint_commit_unknown, the same fail-closed family as a symlink.This is the same exclusive regular-file rule already used for quota spend/void artifacts. That earlier work is not reopened.
Author Declaration
Implemented against
isFileandnlink === 1) on bothrunPathbranchesisExclusiveRegularFileinloopx/control_plane/goals/checkpoint_commit.tsrelocatedCheckpointArtifactcheckpoint_commit.test.ts;failure=hardlinkintest_checkpoint_relocated_replay.pyrunPathcheckpoint_commit.test.tsrunPathbeforewriteSyncedtest_public_checkpoint_commit_does_not_truncate_hard_linked_artifactsENOENTstill creates an exclusive artifact; symlink, directory, missing, and honest copy keep workingENOENThandlingcheckpoint_commit_unknowntest_checkpoint_relocated_replay.pymain, then green after the check. Rantsc --project tsconfig.control-plane.json --noEmitandruff checkon the Python test. Did not reformat the pre-existing Python test. Did not wait on remote CI.Scope And Continuation
Validation
d9358bc06ac931612d469e46fdffcaf830ef056fregression_parityfailedmain(6915df67db6a8836df344a661f295006873a3ba8).node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/checkpoint_commit.test.ts: 4 passed, 2 failed. Relocated and in-directory hard links were accepted (Missing expected exception).uv run --extra test python -m pytest -q tests/control_plane/test_checkpoint_relocated_replay.py -k "hardlink or hard_linked": 6 failed. Public replay returnedrc=0,ok=true,idempotent_replay=truefor hard-linked json and markdown on file and sqlite. Commit replaced the planted outside sentinel with the checkpoint JSON record on both providers.unitpassedreal_entrypointpasseduv run --extra test python -m pytest -q tests/control_plane/test_checkpoint_relocated_replay.py: 16 passed in 46.39s. Includes honest relocated copy, missing, symlink, hard-link replay (checkpoint_commit_unknown/checkpoint artifact path is invalid), and the commit write-through rejection.staticpassednpx tsc --project tsconfig.control-plane.json --noEmitexited 0.uv run --extra test ruff check tests/control_plane/test_checkpoint_relocated_replay.pypassed.nlink=1for an alias is not distinguished from an exclusive file. The check is not a lock betweenlstatandopen.Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
Boundary Checklist
.loopx/,.codex/goals/, and liveACTIVE_GOAL_STATE.md).python3 scripts/check_rfc_bilingual.py --base origin/main --head HEADpasses, or no paired RFC changed.none.Signed-off-bytrailer (git commit -s).duang777 (@Duang777)