Repository navigation
Conversation
append_run_index_record opened goals/<goalId>/runs/index.jsonl in place, so a same-uid hard link or symlink published the JSONL row outside the runs directory. The append now fails closed unless the path is an exclusive regular file, and a missing index is still created at mode 0o600. A dangling Markdown symlink is an occupied artifact name and is not followed. 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
本地运行历史的写入方包括结算、投影和操作回执。 公共 JSONL append 端点直接按路径打开已有文件,普通追加对目标文件的排他性校验不足。 候选在共享追加端点确认独占常规文件,并让选中的历史与投影 Markdown writer 独占创建。 范围是共享 run index 和两个 Markdown 生产路径。保留当前归档格式、锁和正常读回。 正常索引兼容和锁测试在 macOS 执行。异常 descriptor 元数据为受控模拟,Windows 尚未实测。
改动思路 / Approach
共享 history helper 负责追加、补行和索引权限。run_artifacts 负责新文件名和 Markdown 创建,投影仍在原锁下校验读回。 在公共追加所有调用方共享的持久化端点加检查。保留 Markdown 原内容、权限语义及锁。两个 Markdown 生产者使用同一创建函数。 保留现有 owner 和状态合同,按证据限定变更。 主干和候选的正常历史、时间窗、序列化及索引锁各 41 项通过。候选新增的普通创建、已有模式保留和尾行修复三个用例通过。
具体改动 / Changes
关键代码讲解
- _open_exclusive_run_index。打开后核验包括描述符在内的文件属性。 源码
- append_run_index_record。原 JSONL 数据和尾部补行。 源码
- write_reserved_run_artifacts。共享索引锁与历史产物。 源码
- create_exclusive_markdown。新 Markdown 独占创建。 源码
- write_compact_runtime_projection。复用 Markdown writer,原索引后置读回。 源码
exclusive-index-append 通过。locked-history-readback 通过。规范修订为 d0df4f9。 验收依据
对主干的风险 / Risks
使用普通单文件与受控 descriptor 元数据验证拒绝分支。出现不可独占状态时写入被拒,文件原内容一致。解除模拟后同一正常追加只写一条。 受控元数据验证了描述符拒绝顺序。更广泛的路径并发和 Windows reparse 分支仍属于未实测范围。
语义与 CI 对齐
不变的调用方经同一索引 helper 获得拒绝语义。新的 Markdown helper 只用于明确列出的生产路径。一般 I/O 失败的索引之前产物写入顺序仍沿用原合同。 Premerge 的 18 项选中检查和 6 项直接检查通过。
我的整体评价 / Verdict
APPROVE。 保留现有 owner 和状态合同,按证据限定变更。 继续复用现有追加 helper、OSError 和相同写锁,避免在调用方另建存储规则。 结论绑定 e68a7c6。
English verdict: APPROVE at e68a7c6. The shared run-index append enforces exclusive regular-file metadata and preserves JSONL append, mode, newline repair and locking behavior. Paired normal history tests and a bounded descriptor-rejection check passed.
Goal And Delivered Outcome
main(d0df4f970abe5d3bcdb573c7f335b1ab0aad70b4). No issue is closed.append_run_index_recordopenedgoals/<goalId>/runs/index.jsonlwithopen("a+b")and wrote the JSONL row in place. A same-uid hard link or symlink published settlement and projection bytes outside the runs directory.reserve_run_artifact_pathsalso treated a dangling Markdown symlink as absent, andPath.write_textthen created the link target outside the runs directory.OSErrorbefore any byte is written, the external inode and bytes stay unchanged, and the runs directory entry is not replaced. A missing index is still created as one exclusive regular file at mode0o600. A dangling Markdown name is skipped, the run is stored on the next exclusive pair inside the runs directory, andcreate_exclusive_markdownraisesELOOPif it is aimed at that symlink.main. Context only: the TypeScript append work in fix(runtime): reject hard-linked JSONL append targets #9579 does not cover this Python writer, so the same write-through would remain after that change. This PR does not edit fix(runtime): reject hard-linked JSONL append targets #9579 or fix(runtime): reject hard-linked private snapshot files #9560.Author Declaration
Implemented against
st_nlink != 1), or not an exclusive regular fileloopx/history.pyappend_run_index_recordtests/test_history_run_index_exclusive_append.pyindex.jsonlis created as one exclusive regular file at mode0o600_open_exclusive_run_indextest_missing_index_is_created_as_an_exclusive_private_fileappend_run_index_recordtest_exclusive_index_keeps_newline_repair_and_appendsreserve_run_artifact_paths,create_exclusive_markdownmain, then re-ran the focused tests below. Did not run a full-repo pytest orloopx canary premerge. Did not change checkpoint capture, lease JSON, or TypeScript append helpers.Scope And Continuation
Validation
e68a7c60ac181b1eca09b839f8c9b171b98c6160regression_parityfailedon unmodifiedmain, thenpassedafter the fixuv run --extra test python -m pytest -q --no-cov tests/test_history_run_index_exclusive_append.py -k 'not missing_index and not newline_repair'reported 5 failed, 2 deselected. Each index append was treated as success and the external sentinel gained the JSONL row. The dangling Markdown writer test failed because the outside target existed. A separate probe also showedwrite_reserved_run_artifactswriting the rendered Markdown through that symlink, while a dangling JSON symlink was not followed (O_EXCLadvanced to the next stem).unitpasseduv run --extra test python -m pytest -q --no-covontests/test_history_run_index_exclusive_append.py,tests/test_history_index_write_serialization.py,tests/test_history_artifact_observation.py,tests/test_history_chronology.py,tests/control_plane/test_run_artifact_reservation.py,tests/control_plane/test_runtime_projection_writer_guards.py,tests/control_plane/test_replan_context_order.py, andtests/architecture/test_posix_flag_portability.py: 99 passed.staticpasseduv run --extra test python -m ruff checkon the five touched paths: all checks passed.staticpasseduv run --extra test python -m mypy --follow-imports=silentonloopx/history.py,loopx/control_plane/runtime/run_artifacts.py, andloopx/control_plane/runtime/runtime_projection_writer.py: no issues. These modules are outside the repository's configured mypy file list.write_reserved_run_artifacts,write_compact_runtime_projection, reservation, newline repair, and create mode. Not run: full-repo pytest andloopx canary premerge. Residual risk: a TOCTOU window remains betweenlstatandopen, and another betweenfstatandwrite.O_NOFOLLOWis used when the host provides it. On Windows, where that flag is absent, a symlink orst_nlink != 1seen bylstatstill fails closed, and a reparse point is refused; a link planted afterlstatcan still be followed. Link tests skip when the filesystem cannot create the link.operator_gatestill callsPath.write_texton paths it builds itself.state_refreshstill callsPath.write_text, but it reserves throughreserve_unique_run_paths, so the dangling Markdown name is skipped first. JSONwrite_textstill replaces the exclusive sentinel this process just created; the dangling JSON symlink probe did not write outside.load_indexstill follows a symlink when reading.next_run_artifact_pathsstill usesPath.existsfor preview only.See validation disclosure guidance.
Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
N/A
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).