Skip to content

fix(control-plane): reject hard-linked checkpoint artifacts - #9512

Merged
huangruiteng merged 1 commit into
mainfrom
cursor/reject-hardlinked-checkpoint-artifacts-aad3
Nov 27, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
cursor/reject-hardlinked-checkpoint-artifacts-aad3

Conversation

@Duang777

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: self-found hole in checkpoint artifact path resolution. Prior related work: fix(control-plane): resolve checkpoint artifacts after runtime relocation #9163 (relocated checkpoint paths). This PR does not close that issue.
  • Goal/source and gap: runPath() and relocatedCheckpointArtifact() accepted a hard link as an exclusive checkpoint artifact. lstat().isFile() is true for a hard link, and realpath() stays on the in-directory name, so a second name outside the current runs directory was treated as exclusive.
  • Observable before → after, with the validation row that proves it: before, relocated replay returned ok / idempotent_replay for a hard-linked artifact whose bytes still matched the index, and commitCheckpoint truncated that shared inode through writeSynced. After, both inspect and commit fail closed with checkpoint_commit_unknown and 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.
  • Issue/task and intended base: no issue is closed. Prior related work fix(control-plane): resolve checkpoint artifacts after runtime relocation #9163. Base is 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 when lstat is a regular file and nlink === 1. Both branches of runPath() use that check (the in-directory lexical path and relocatedCheckpointArtifact()). ENOENT is unchanged, so a new exclusive artifact can still be created on commit. Relocated hard links fail with checkpoint artifact path is invalid. In-directory hard links fail with checkpoint artifact is not a regular file. Both stay in checkpoint_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

  • Specification and revision: no written specification; the request in this PR is the basis.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Exclusive regular file (isFile and nlink === 1) on both runPath branches implemented isExclusiveRegularFile in loopx/control_plane/goals/checkpoint_commit.ts TypeScript inspect tests and public CLI replay/commit tests below
Relocated hard link with matching identity bytes is rejected; outside inode and index stay unchanged implemented relocatedCheckpointArtifact checkpoint_commit.test.ts; failure=hardlink in test_checkpoint_relocated_replay.py
In-directory hard link is rejected implemented runPath checkpoint_commit.test.ts
Commit must not truncate a hard-linked target implemented runPath before writeSynced test_public_checkpoint_commit_does_not_truncate_hard_linked_artifacts
ENOENT still creates an exclusive artifact; symlink, directory, missing, and honest copy keep working implemented existing ENOENT handling existing cases in both test files, still passing
Public CLI hard-linked relocated replay returns checkpoint_commit_unknown implemented same error family as the symlink case test_checkpoint_relocated_replay.py
  • Self-check before submission: ran the new tests red on unfixed main, then green after the check. Ran tsc --project tsconfig.control-plane.json --noEmit and ruff check on the Python test. Did not reformat the pre-existing Python test. Did not wait on remote CI.

Scope And Continuation

  • Completed scope and remaining work: checkpoint artifact open/write now requires an exclusive regular file. Complete within this scope.
  • Slice boundary / successor: N/A. Quota artifact checks and other open work are untouched.

Validation

  • Tested revision: d9358bc06ac931612d469e46fdffcaf830ef056f
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
regression_parity failed Unfixed main (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 returned rc=0, ok=true, idempotent_replay=true for hard-linked json and markdown on file and sqlite. Commit replaced the planted outside sentinel with the checkpoint JSON record on both providers.
unit passed After the fix, the same node command: 6 passed, 0 failed. Existing copy, in-directory exclusive file, symlink, and directory cases stayed green.
real_entrypoint passed After the fix, uv 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.
static passed npx tsc --project tsconfig.control-plane.json --noEmit exited 0. uv run --extra test ruff check tests/control_plane/test_checkpoint_relocated_replay.py passed.
  • Coverage and gaps: Linux hard links are covered for inspect and for the public commit write. Platforms that cannot create hard links skip only that case. A filesystem that reports nlink=1 for an alias is not distinguished from an exclusive file. The check is not a lock between lstat and open.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: control-plane checkpoint artifact exclusivity. No roadmap id.

Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A
  • Semantic dimensions changed, or reviewed no-impact rationale: N/A
  • Provider conformance arms run: N/A
  • Read-only legacy/file/PostgreSQL three-arm rehearsal (required for promotion, runtime-routing, or compatibility-projection changes): N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

duang777 (@Duang777)

Open in Web Open in Cursor 

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 loopx-agent 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.

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.

@huangruiteng
huangruiteng merged commit b6be7f6 into main Nov 27, 2026
24 of 28 checks passed
@huangruiteng
huangruiteng deleted the cursor/reject-hardlinked-checkpoint-artifacts-aad3 branch November 27, 2026 03:55
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.

3 participants