Repository navigation
Conversation
A quota artifact that is a hard link to an outside zero-slot file still passes the symlink checks from #9420. Require one exclusive regular file before the Python ledger or the TypeScript spend reader treats it as a debit, and reject the same alias when a receipt is replayed. 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
动机 / Motivation
在已知 Goal runs 目录的配额账本及结算回读中,拒绝不符合约定的文件状态,保留正常消费、撤销与重放。
Python 配额状态、TypeScript 结算回读与 void 调用者依赖同一账本完整性约束。
比较正常消费、搬迁后的普通副本、没有新事务字段的旧记录和重放。另用合成文件元数据核对新增拒绝分支。
正常配额消费、撤销和历史回读保留。新增检查对不可接受的文件元数据走既有错误路径。
验证范围为源代码和隔离本地文件。未操作活跃配额账本。
按基线配额完整性合同核对。 状态数据合同
改动思路 / Approach
Python 账本把不可用产物映射为既有完整性失败。TypeScript 读端和已保存的事务回执复用各自现有错误合同。
检查作用于已知 runs 目录。未传目录的旧入口与无事务字段的 inline 记录由原合同处理。
复用现有文件资格判定和账本完整性错误,保留单一的窄防御分支。
具体改动 / Changes
审查提交 7e53d02e2778afffa5d96dfeb5abcc3001ddcb90,分叉基线 57c4c43b5243003c6da1988730c49ac2267626f7。4 个文件 +391/−27。
关键代码讲解
-
_exclusive_regular_file。判断正常文件及单链接计数。 源码 -
_relocated_run_artifact_path。只接受 Goal runs 中符合约定的普通副本。 源码 -
_regular_artifact_inside_runs_dir。为 Python 配额账本验证已知目录中的候选文件。 源码 -
readQuotaSpendEventFromRun。在边界验证后读取已有消费记录。 源码 -
rejectSymlinkPath。复用既有回执错误合同拒绝不合格文件。 源码 -
quota-artifact-integrity(implemented)。不可用的索引产物走既有完整性失败。 对应
_regular_artifact_inside_runs_dir。 -
readable-copy-and-replay(implemented)。普通副本、旧记录和真实精确效果重放保持。 对应
readQuotaSpendEventFromRun。
对主干的风险 / Risks
两版各 2 项真实 File 账本和 4 项 TypeScript 实际文件测试通过,包含正常提交、断点修复、复制后的重放和旧格式对照。
生产 Python 判定对合成多条目元数据、目录及符号条目均拒绝。TypeScript 读取和回执检查也复用同一个独占普通文件判定。
改动的 Python 文件 Ruff 通过,TypeScript control-plane typecheck 和 git diff --check 通过。标准本地预合并门通过 6 项直接检查和 16 项 smoke。
独立测试覆盖正常生产入口和合成文件元数据。作者另报告完整分支测试。远程 CI、安装态和 Windows 未核验。
我的整体评价 / Verdict
APPROVE。 普通产物、复制和重放语义保留。新增文件资格检查沿用已有完整性失败结果。基线与当前的普通文件路径都完成了相同的消费、撤销及回执测试。
English verdict: APPROVE at 7e53d02. Paired ledger and receipt checks preserve ordinary artifacts, relocation, and exact-effect replay. The patch keeps the new file classification within existing ledger integrity boundaries.
Goal And Delivered Outcome
57c4c43b5243003c6da1988730c49ac2267626f7realpath/Path.resolvestays on the in-directory name, so an outside zero-slot file that repeats the commit identity was still a readable zero debit.None(a readable zero spend,unreadable_event_count == 0). The TypeScript reader returnedslots: 0, and receipt replay accepted the hard link. After the fix, the Python ledger reportsartifact_missing,spent_slots == 0,unreadable_event_count == 1, and automatic-turnquota_statusisblocked_health. The TypeScript reader returnsnull. Receipt replay rejects the alias withmalformed_transaction_receipt. The index row and the outside bytes stay unchanged, and the in-directory name remains a hard link.main. This PR does not claim or close an existing issue.动机 / Motivation
#9420 关掉了符号链接:
lstat必须是普通文件,且resolve()/realpath必须留在 Goal 的 runs 目录里,否则事件是artifact_missing,自动执行进入blocked_health。硬链接仍然是普通文件(S_ISREG/lstat().isFile()为真),真实路径也停在目录内的那个名字上,所以上述检查会通过。把 runs 目录里的消费记录换成指向目录外、同一 commit identity、slots: 0的硬链接,仍会被当成可读的零消耗;目录外的那个名字以后还可以被改写,而不必再碰 runs 目录。Python 滚动账本因此丢掉这笔扣减,Goal 仍可自动执行。TypeScript 的
readQuotaSpendEventFromRun会把这个零事件交回结算回读和 void。回执重放里的rejectSymlinkPath只拒绝符号链接,所以同一别名也能通过回执准入。改动思路 / Approach
配额产物的预期形态是独占的普通文件:
nlink === 1。官方运行时复制用的是shutil.copytree/fs.cp(新 inode),不是硬链接。loopx/control_plane/quota/ledger_readback.py:_regular_artifact_inside_runs_dir与_relocated_run_artifact_path在lstat为普通文件之后再要求st_nlink == 1。否则返回None。调用方已经把这映射为artifact_missing。不改写索引,也不改写目录外的文件。readQuotaSpendEventFromRun:对候选路径做lstat,要求isFile()且nlink === 1,然后再要求realpath仍在 runs 目录内。路径真实位置离开目录时,仍抛出原来的quota spend json_path must stay inside the goal runs directory。ENOENT仍返回null。硬链接按目录内不可读/缺失处理,返回null,不把零事件交回去。relocatedRunArtifactPath同样要求nlink === 1,因此复制后的同名硬链接不会被当成可迁移的产物。rejectSymlinkPath仍先拒绝符号链接。普通文件且nlink !== 1时,用现有的malformed_transaction_receipt拒绝,消息为must not be a hard link。没有新增 lease owner,也没有新的公共错误码。Author Declaration
Implemented against
nlink == 1) on that same reader, on the TypeScript spend reader, and on receipt replay.ledger_readback.py_regular_artifact_inside_runs_dir;accounting_artifact_transaction.tsreadQuotaSpendEventFromRuntest_in_directory_hard_link_cannot_zero_a_quota_debit;readQuotaSpendEventFromRun does not accept an in-directory hard link as a zero spend_relocated_run_artifact_path;readQuotaSpendEventFromRun;relocatedRunArtifactPathtest_relocated_hard_link_cannot_zero_a_quota_debit; relocated reader and receipt testsjson_paththat is a hard link to an outside alias is rejected with the existing receipt code, and symlink rejection stays in placerejectSymlinkPathspend receipt replay rejects an in-directory hard link to an outside alias; existing symlink receipt testsmain, the new tests failed as a readable zero spend (reason is None, TypeScript eventslots: 0, receipt replay resolved). After the fix they pass. Outside bytes and the hard link itself are left in place. Callers that do not pass a runs directory still keep the stored path. No UI change. This is a source-tested proposal, not an installed-product claim. No merge authorization.Scope And Continuation
Validation
7e53d02e2778afffa5d96dfeb5abcc3001ddcb90regression_paritypasseduv run --extra test python -m pytest tests/control_plane/test_quota_ledger_relocated_runtime.py::test_in_directory_hard_link_cannot_zero_a_quota_debit tests/control_plane/test_quota_ledger_relocated_runtime.py::test_relocated_hard_link_cannot_zero_a_quota_debit -q --tb=shortfailed: 2 failed, bothassert None == 'artifact_missing'. Before the fix,node --no-warnings --experimental-sqlite --experimental-strip-types --test --test-name-pattern "hard link" tests/control_plane_ts/quota_spend_commit.test.tsfailed: 3 failed, 0 passed (in-directory and relocated readers returnedslots: 0; receipt replay was not rejected). The later relocated-receipt test, run against the unfixed reader, failed withMissing expected rejection(1 failed, 0 passed).unitpassedtests/control_plane/test_quota_ledger_relocated_runtime.py,test_quota_ledger_integrity.py,test_quota_slot_accounting.py,test_quota_rolling_window_projection.py,test_history_relocated_run_artifacts.py, andtest_usage_summary.py: 140 passed.tests/control_plane_ts/quota_spend_commit.test.ts: 36 passed, 0 failed.quota_void_commit.test.tsandquota_settlement_readback.test.ts: 192 passed, 0 failed.staticpasseduv run --extra test ruff check loopx/control_plane/quota/ledger_readback.py tests/control_plane/test_quota_ledger_relocated_runtime.py.npm run typecheck:control-plane(tsc --project tsconfig.control-plane.json --noEmit) exited 0..venv/bin/loopx canary premerge --from-git-diff --git-diff-base origin/mainon this change set: passed,changed_files=4, diff check, RFC bilingual check,py_compile, 8 catalog canaries, 8 risk-profile smokes,failures=0. Passing premerge is not merge authority.nlink == 1for a hard link would still hide the alias. Callers that do not supply the current runs directory are unchanged. No UI change.Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
Boundary Checklist
python3 scripts/check_rfc_bilingual.py --base origin/main --head HEADpasses, or no paired RFC changed.none.Signed-off-bytrailer (git commit -s).Written by: duang777 (@Duang777)