Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "マージ済み PR の pr_review.publish ローカル marker が後続 preflight を unauthorized_write_path で停止させず、remote GitHub state を authority とする限定 archive lifecycle を提供する"
change_kind: code
dedupe_key: "follow-up:squne121/loop-protocol:pr/1594:pr-review-publish-marker-lifecycle"
origin_skill: issue-refinement-loop
source_pr: "#1594"Parent Issue
なし(単独改善)
Parent Goal Ref
- Goal: Issue 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 のアンカー付き refinement preflight を、既に merge 済みの PR feat: scope-rollup registry invocation metadata #1594 に属する local-only review marker が阻害しない状態に戻す。
- Desired Destination: strict schema と remote merge/readback を確認した
PR_REVIEW_PUBLISH_MARKER_V1だけを repo 外の archive root へ退避する専用 executor と、post-merge-cleanup の明示的 handoff を提供する。
Current Validated Scope
controlled_skill_mutation_exec.pyのpr_review.publishはartifacts/<PR>/issue-metadata/pr_review.publish/pr_review_publish.marker.jsonにPR_REVIEW_PUBLISH_MARKER_V1を local cache/audit として書く。remote GitHub review readback が authority であり、marker 単体は mutation 成功の根拠にならない。- PR feat: scope-rollup registry invocation metadata #1594 は
MERGED、linked Issue 実装: command_registry.py の scope_rollup.run argv テンプレートに --invocation-id/--requested-at を反映する #1579 はCLOSEDだが、同 marker が root のpreflight.run.with_anchorでunauthorized_write_pathとして観測され、Issue 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 の refinement を fail-close 停止させた。 - 現行 post-merge-cleanup は temp residue を report-only とし、repo-local artifact の削除・移動を認可する executor を持たない。
Remaining Parent Gaps
- 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 の GitHub inventory pagination 実装、実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 の session manifest external root、実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587 の guard-shadow writer hardening は別 scope であり変更しない。
- 他の artifact family、未 merge PR、open PR の review retry marker、retention duration、repo 全体の artifact cleanup は本 Issue 完了後も対象外とする。
Outcome
scripts/agent-ops/pr_review_marker_archive_exec.py、回帰テスト、post-merge-cleanup handoff、および責務境界の SSOT が揃い、PR が remote で MERGED かつ marker/review/head binding を再検証できる場合に限り、当該 PR_REVIEW_PUBLISH_MARKER_V1 を repo 外 archive root へ退避して repo 側 marker を除去し、検証不能な marker は一切変更せず fail-close する状態。
In Scope
PR_REVIEW_PUBLISH_MARKER_V1の exact path・regular file・strict JSON key/type・pr_number/repo/expected head/review URL/review_idの binding を、directory FD ベースの TOCTOU-safe 検証(openat2/openat+O_NOFOLLOWの FD-relative walk、同一 FD からの読み取り・hash・unlink 直前の再照合)で行う専用 archive executor を追加する。- executor は GitHub の merged-check endpoint(
204=merged/404=unmerged)で対象 PR がMERGEDであること、marker のreview_idを primary key として exact review endpoint を取得し review id/URL/PR URL/state/commit/idempotency-derived body marker が一致することを確認した場合だけ、marker bytes の sha256 と archive metadata を authority 付きで解決した repo 外 archive root(no-overwrite semantics)に保存してから repo 側 marker を除去する。 - 除去は unlink 前後で明確に区別された state machine(
SOURCE_VALIDATED -> ARCHIVE_PREPARED -> ARCHIVE_DURABLE -> SOURCE_REMOVED -> SOURCE_REMOVAL_DURABLE -> COMMITTED)に従い、unlink 前の失敗は marker 保持、archive durable 後・unlink 前後の失敗は marker 現存確認可否に応じてsource_retainedまたはindeterminateを区別して返す。任意 path/glob、schema 不明、symlink/hardlink/non-regular file、open/closed-unmerged PR、remote readback 不一致は対象外として拒否する。 - post-merge-cleanup worker がこの executor を
merged_pr_numberの review marker に限って呼び出せる手順を追加し、temp residue の report-only 原則・他 artifact family の削除禁止を維持する。 - executor の許可対象、remote authority、archive metadata、fail-close と rollback/retention の責務境界を SSOT に記録する。
- merged success、unmerged refusal、schema/path/file-kind refusal、remote binding mismatch、archive/postcondition failure、および unlink 前後の各失敗状態区分で repo marker 挙動を回帰テストで固定する。
Out of Scope
controlled_skill_mutation_exec.pyの pr_review.publish request/review投稿/idempotency semantics の変更。skill_runtime_exec.pyまたは preflight の arbitrary artifact allowlist・ignore rule・fail-close policy の緩和。artifacts/**の sweep、glob cleanup、未 merge/open PR marker の archive、marker の再生成、既存 review の削除。- archive root の retention/rotation/暗号化 policy、repo 外 state の一括削除、feat: scope-rollup registry invocation metadata #1594 marker 以外の手動削除。
- 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593、実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546、実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587 の実装・契約変更(archive root の authority precedence は本 Issue 内で自己完結して定義し、実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 の resolver 実装には依存しない)。
Acceptance Criteria
- AC1: executor は exact
artifacts/<pr>/issue-metadata/pr_review.publish/pr_review_publish.marker.jsonの regularPR_REVIEW_PUBLISH_MARKER_V1だけを受け付け、PR number/repo/review URL/expected head/idempotency key の schema と binding を検証する。検証は pathname resolve に依存せず、repo root と marker の親 directory を directory FD として順次 open し(openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)、またはopenat+O_DIRECTORY/O_NOFOLLOWによる FD-relative walk)、marker をO_RDONLY | O_NOFOLLOW | O_CLOEXECで open して同一 FD から bytes を読み SHA-256 を計算する。fstatで regular file・st_nlink == 1・size 上限を確認し、unlink 直前に directory entry のst_dev/st_inoを開いている FD と再照合し、hardlink count もこの時点で再確認してからunlinkat(dir_fd, exact_name)で削除する。任意 path、glob、symlink/hardlink/non-regular file、検証後の TOCTOU 差し替え、不正 JSON/unknown schema は非0で拒否し repo 側 file を変更しない。 - AC2: GitHub readback は marker の primary key である
review_idを用いて exact review endpoint を取得し、response.id == marker.review_id、html_url == marker.review_url、pull_request_urlが対象 repo/PR の canonical API URL、state == COMMENTED、commit_id == expected_head_sha、submitted_atが有効、body 中に idempotency-key 由来 marker が exactly once かつその SHA-256 が一致、を全て確認する。PR の merge 判定は文字列比較ではなく専用の merged-check endpoint(HTTP204=merged/404=unmerged)で行う。これらすべてが確認できた場合だけ、marker bytes の sha256 と archive metadata を repo 外 archive root に保存する。archive root は authority precedence(XDG_STATE_HOME、fallback$HOME/.local/state)で解決し、relative path・symlink・他 UID owner・group/world-writable root は拒否し、directory mode0700・file mode0600を強制する。archive layout は content-addressed(例:<state_root>/loop-protocol/pr-review-marker-archive/<repo-id>/<pr-number>/<marker-sha256>.archive.json)とし、renameat2(RENAME_NOREPLACE)または archive-root 内 exclusive temp file + link publish による no-overwrite semantics で既存 archive を上書きしない。保存後、repo 側 marker が不在であることを readback 検証する。 - AC3: executor は
SOURCE_VALIDATED -> ARCHIVE_PREPARED -> ARCHIVE_DURABLE -> SOURCE_REMOVED -> SOURCE_REMOVAL_DURABLE -> COMMITTEDの state machine に従って結果を区別する。(a) source unlink より前の失敗はfailed_before_archiveとし marker を必ず保持する。(b) archive durable 達成後、source unlink の前後で失敗した場合は、marker 現存を確認できたときに限りarchive_durable_source_retainedを返し、marker 不在は確認できたが readback/directory fsync/結果出力のいずれかが失敗し状態を確定できないときはarchive_durable_source_state_indeterminateを返す(この場合「marker を保持した」とは主張しない)。(c) source removal durable 達成後はarchivedとして成功を返す。PR が open/closed-unmerged、remote review/head/repo binding が不一致、archive write が失敗、または removal postcondition が確認不能な場合も本状態機械に従って fail-close し、marker 現存を確認できないときはindeterminateを返す(保証できない保持は主張しない)。 - AC4: post-merge-cleanup の手順は merged PR の exact review marker にだけ executor を適用し、
tmp/、.claude/tmp/、.claude/worktrees/、他 artifact family の report-only / deletion 禁止を維持する。POST_MERGE_CLEANUP_REPORT_V1には schemaPR_REVIEW_MARKER_ARCHIVE_RESULT_V1のpr_review_marker_archiveresult block を追加し、少なくともstatus(archived|already_archived|source_retained|indeterminate|refused|environment_blocked)、reason_code、pr_number、source_relpath、marker_sha256、archive_locator、archive_durable、source_present_after、source_directory_synced、およびmerged/review_id/state/commit_idを含むremoteサブオブジェクトを持つ。 - AC5: SSOT が remote GitHub state を authority とし、archive は local cache/audit の lifecycle に限定され、preflight 側の generic ignore/allowlist を導入しない責務境界を明記する。
Runtime Verification Applicability
decision: immediate
reason: "POSIX file kind/path safety、repo 外 archive write、GitHub PR/review readback、failure-atomicity を実 filesystem と fake/recorded GitHub response の双方で検証する必要がある"
applicable_acs: [AC1, AC2, AC3]
execution_environment: "Linux/WSL、uv-managed Python、GitHub read-only API が利用可能な専用 worktree"
skip_conditions: "GitHub read-only API 又は POSIX file operations を利用できない環境では environment_blocked として停止し、archive success を主張しない"
fallback_policy: "remote state 未確認・archive write 未確認・repo marker removal 未確認は PASS に変換しない"
artifact_requirements: "archive metadata の marker_sha256、PR number、review URL、review_id、expected head、remote state、archive timestamp と repo marker absence readback"Verification Commands
# AC1
$ uv run --locked pytest scripts/agent-ops/tests/test_pr_review_marker_archive_exec.py::test_rejects_noncanonical_marker_inputs_without_repo_mutation -q
# AC2
$ uv run --locked pytest scripts/agent-ops/tests/test_pr_review_marker_archive_exec.py::test_archives_only_remote_merged_and_review_id_bound_marker -q
# AC3
$ uv run --locked pytest scripts/agent-ops/tests/test_pr_review_marker_archive_exec.py::test_failure_state_machine_preserves_or_reports_indeterminate -q
# AC4
$ rg -n -- "PR_REVIEW_MARKER_ARCHIVE_RESULT_V1" .claude/skills/post-merge-cleanup/SKILL.md
# AC5
$ rg -n -- "PR_REVIEW_PUBLISH_MARKER_V1" docs/dev/agent-skill-boundaries.mdAllowed Paths
scripts/agent-ops/pr_review_marker_archive_exec.py(新規)scripts/agent-ops/tests/test_pr_review_marker_archive_exec.py(新規)scripts/agent-ops/tests/__init__.py(新規、テストパッケージ化に必要な空ファイル).github/ci/python-test-plan.json(scripts/agent-ops/tests/を python-test lane に登録するために必要).claude/skills/post-merge-cleanup/SKILL.mddocs/dev/agent-skill-boundaries.md.claude/settings.json(scripts/agent-ops/pr_review_marker_archive_exec.pyを呼ぶ post-merge-cleanup executor の command allowlist エントリ追加のために必要)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- repo 外 archive root を deterministic に束縛・permission/regular-file 検証できない場合
- remote GitHub readback を実行せず marker を archive/remove しなければならない場合
- marker schema、remote merge/readback authority、archive-before-removal postcondition の変更が必要になった場合
- 別 artifact family、retention/rotation、又は preflight policy 変更へ scope 分割が発生する場合
Required Skills
- Python
- GitHub REST API readback
- POSIX ファイルシステム安全性
- pytest
Required Design References
docs/dev/agent-skill-boundaries.md.claude/skills/post-merge-cleanup/SKILL.md- Issue 実装: command_registry.py の scope_rollup.run argv テンプレートに --invocation-id/--requested-at を反映する #1579
- PR feat: scope-rollup registry invocation metadata #1594
- Issue 実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546(archive root の authority precedence / no-overwrite 契約の先行例。本 Issue は依存せず自己完結で同等契約を定義する)
Scope Delta
- source: Issue 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 anchor-preflight failure
- validated_scope_delta: merge 済み PR feat: scope-rollup registry invocation metadata #1594 の
PR_REVIEW_PUBLISH_MARKER_V1が local cache/audit のまま repo root に残り、後続 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 preflight の unauthorized write attribution を fail-close にした。 - deterministic_fix: remote
MERGED/review binding を再検証する exact marker archive executor を post-merge-cleanup に限定追加する。 - workaround_comparison: preflight で任意 artifact を ignore/allowlist する方法は所有者・schema・remote state を確認せず safety boundary を広げるため不採用。現時点の即時回避は人間が feat: scope-rollup registry invocation metadata #1594 の exact marker を archive し、sha256 と removal readback を記録することに限定する。
Scope Delta (PR #1628 review fix_delta, 追加)
- source: PR 実装: マージ済み PR の pr_review.publish marker を限定 archive し preflight 阻害を防ぐ #1628 レビュー REQUEST_CHANGES(CI python-test job / node-backed-hook-tests job FAILURE)
- validated_scope_delta:
scripts/agent-ops/tests/__init__.py(テストディレクトリのパッケージ化に必須)と.github/ci/python-test-plan.json(scripts/agent-ops/tests/を python-test lane に登録し G1uncovered_changed_test_filesgate を通すために必須)の 2 ファイルが実装時に必要と判明した。 - deterministic_fix: 上記 2 ファイルを Allowed Paths に追加する。既存 In Scope / Acceptance Criteria のスキーマ・契約は変更しない。
- workaround_comparison:
scripts/agent-ops/tests/を python-test-plan から除外したまま放置する方法は CI gate 常設という既存プロジェクト方針(新規テストは CI required job に登録必須)に反するため不採用。
Scope Delta (PR #1628 review fix_delta, 追加2)
- source: PR 実装: マージ済み PR の pr_review.publish marker を限定 archive し preflight 阻害を防ぐ #1628 コメント OWNER セキュリティレビュー P1-1(
scripts/agent-ops/pr_review_marker_archive_exec.pyが Claude Code の command allowlist に含まれておらず、post-merge-cleanup からの自動呼び出し経路が動作しない)。 - validated_scope_delta:
.claude/settings.jsonのpermissions.allowに exact command allow エントリ"Bash(uv run --locked python3 scripts/agent-ops/pr_review_marker_archive_exec.py *)"を追加する必要があると判明した。既存 In Scope / Acceptance Criteria のスキーマ・契約は変更しない。 - deterministic_fix:
.claude/settings.jsonを Allowed Paths に追加し、上記 exact command allow エントリのみを追加する。broad wildcard や他 command class への allow 拡張は行わない。 - workaround_comparison: allowlist 追加を見送り手動実行前提のままにする方法は post-merge-cleanup の自動 archive 経路という Outcome を満たさないため不採用。
Delivery Rule
1 Issue = 1 PRとし、専用 worktree で実装して Draft PR を作成する。- archive executor は post-merge-cleanup worker だけが、merged PR number と exact marker path を明示して呼び出す。任意 path の user input は受け付けない。
Notes for Reviewer
- Source: Issue 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 anchor comment
https://github.com/squne121/loop-protocol/issues/1593#issuecomment-5010741104の preflight でartifacts/1594/issue-metadata/pr_review.publish/pr_review_publish.marker.jsonが unauthorized write path として検出された。 - PR feat: scope-rollup registry invocation metadata #1594 は
MERGED、Issue 実装: command_registry.py の scope_rollup.run argv テンプレートに --invocation-id/--requested-at を反映する #1579 はCLOSED。controlled_skill_mutation_exec.pyは remote readback を authority とし、local marker は cache/audit only と定義している。 - Reframe source: Issue 実装: マージ済み PR の pr_review.publish marker を限定 archive し preflight 阻害を防ぐ #1602 OWNER anchor comment
https://github.com/squne121/loop-protocol/issues/1602#issuecomment-5010821362(REQUEST_CHANGES、reframe_in_place)の P0-1〜P0-5 を AC1〜AC4 に反映した(failure-atomicity state machine、dir-fd/openat2 TOCTOU-safe validation、review_idprimary key remote binding、archive root locator/no-overwrite 契約、POST_MERGE_CLEANUP_REPORT_V1へのpr_review_marker_archiveresult block 追加)。同コメントの P1-1〜P1-5(High priority: tracked-file 保護、idempotency/recovery matrix、archive envelope の exact schema、failure injection の細分化、実装開始 base の記録)は AC の必須契約ではなく実装時の設計・テスト網羅性の指針として扱い、本 reframe では Allowed Paths・In Scope の境界を広げていない。 - Scope Collision (C1): related_issue=実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587, 実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546, 実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523, 実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363, 実装: issue-refinement-loop の SubAgent 起動を planner-declared launch plan に制限する #1288, 実装: feat(agent-ops): issue-refinement-ops-review で agent_ops_inventory を必須 preflight 化する #1009, 実装: schema-governance.md の Initial Known Schemas を catalog から生成するスクリプト(#131 FU-5) #521, 実装: playtest-log の JSON Schema / validator の追加 #420, 実装: docs/dev/agent-skill-boundaries.md に impl-review-loop 開始の人間起点ゲート原則を追記 #260, 改善: VC 設計ガイドラインに否定パターン誤マッチ防止チェックを追加 #237, 実装: rate limit / API error 由来の停止を StopFailure hook でログ保存し resume playbook を整備する #225, 改善: executable bit audit CI guard の適用範囲を .claude/skills 外のスクリプトへ拡張する #213, 実装: .claude/skills 配下スクリプトの executable bit を監査し CI guard を追加する #205, 実装: AI駆動開発における SubAgent 観察結果の Orchestrator ルーティングと GitHub 反映責務を定義する #197, 実装: post-merge-cleanup-worker が caller premise より git/gh 実測を優先し矛盾を warnings に明示する #106, 実装: docs/dev/agent-skill-boundaries.md に「方針 vs 作業手順」の責務分離原則と Issue 本文オーサリングの方針記述を追加する #82, 実装: .claude/settings.json の Bash allow リストに uv 系コマンド (uv run / uv lock / uv sync) を追加する #63, 実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56, 実装: post-merge-cleanup/SKILL.md 内に残存する inline python one-liner を scripts に集約 #47, 実装: post-merge-cleanup に Test Plan チェックボックス自動検出を追加する #45; overlapping_paths=.claude/skills/post-merge-cleanup/SKILL.md, docs/dev/agent-skill-boundaries.md, scripts/agent-ops/pr_review_marker_archive_exec.py, scripts/agent-ops/tests/test_pr_review_marker_archive_exec.py.
- non_conflict_reason: 実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 は session manifest の external root、実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587 は
.guard_shadow_log.jsonlの canonical writer、実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523 は未公開 commit cleanup、実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363 は strict trace attribution を扱う。残りは shared SSOT/skill、又は広いscripts/docsglob による path-only hit であり、PR_REVIEW_PUBLISH_MARKER_V1の merged-only archive/repo-marker removal contract は扱わない。 - edit_intent: 新規 archive executor とその専用テストを追加し、post-merge-cleanup の同 executor handoff と agent-boundaries の marker lifecycle 段落だけを変更する。
skill_runtime_exec.py、controlled_skill_mutation_exec.py、generic artifact policy、shadow log、session manifest は編集しない。 - dependency_ordering: feat: scope-rollup registry invocation metadata #1594 は merge 済みの source PR。実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523/実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546/実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587 と同じ shared docs/skill の同一行に open PR が現れた場合は実装を停止し、先行 PR merge 後に re-readback して直列化する。新規 executor/test path は既存候補と実体の競合がない。
- non_conflict_reason: 実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 は session manifest の external root、実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587 は
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jul 18, 2026
判定
REQUEST_CHANGES —
reframe_in_place。設計方向は正しいです。
pr_review.publishmarker を preflight 側で無視するのではなく、remote GitHub state を authority として限定的に repo 外へ退避する方針は妥当です。既存 publisher も local marker を cache/audit 扱いとし、remote readback を成功判定の正本にしています。ただし現契約のまま実装すると、「失敗時には marker を保持する」という AC を満たせない障害窓、TOCTOU による別ファイル削除、archive 証跡の上書き、post-merge report への結果欠落が残ります。Issue #1602 は現在 open、コメントはまだありません。
マージブロッカー
P0-1. AC3 の failure-atomicity は実現不能な形で矛盾している
現契約はおおむね次の順序です。
archive を保存する
repo marker を除去する
marker 不在を readback する
いずれかを確認できなければ marker を保持して失敗する
しかし、
unlinkが成功した直後に readback、directoryfsync、結果出力のいずれかが失敗した場合、marker はすでに存在しません。再生成による rollback を実装しても、unlinkと rollback の間にプロセス停止・OS crash が起きれば「失敗時は必ず marker を残す」は保証できません。さらに、ファイル本体への
fsyncだけでは directory entry の永続化は保証されず、archive 側と source 側それぞれの directory FD に対するfsyncが必要です。(man7.org)AC3 を以下のように分解してください。
source unlink より前の失敗: marker は必ず保持
archive durable 後、source unlink 前後の失敗: durable archive を保持し、source の有無を
indeterminateとして返すsource removal durable 後: 成功
source removed後の失敗に対して「marker を保持した」とは主張しない最低限、次の状態機械が必要です。
結果には
failed_before_archive、archive_durable_source_retained、archive_durable_source_state_indeterminate、archivedを区別して出すべきです。P0-2. pathname ベース検証では marker 差し替え競合を防げない
既存 publisher の入力検証は、各 component の
lstat、Path.resolve()、stat()、st_nlinkを順番に確認しています。しかし検証後、bytes 読み取り前、hash 後、unlink 前のどこでも path entry は別 inode に交換できます。
しかも現在の post-merge-cleanup SSOT 自身が、将来の削除 executor に対して「
Path.resolveではなく dir-fd chain で解決する」ことを要求しています。AC1 に以下を明記してください。
repo root、
artifacts/<pr>/issue-metadata/pr_review.publish/を directory FD として順次 openopenat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)、またはopenat+O_DIRECTORY/O_NOFOLLOWによる FD-relative walkmarker を
O_RDONLY | O_NOFOLLOW | O_CLOEXECで open同一 FDから bytes を読み、SHA-256 を計算
fstatで regular file、st_nlink == 1、size 上限、必要なら owner を確認unlink 直前に directory entry の
st_dev/st_inoと開いている FDを再照合unlinkat(dir_fd, exact_name)相当で削除hardlink count も unlink 直前に再確認
openat()系が必要なのは、path prefix が並行して交換される race を pathname API だけでは避けられないためです。(man7.org)openat2のRESOLVE_BENEATH、RESOLVE_NO_SYMLINKS、必要に応じたRESOLVE_NO_XDEVがこの用途に対応します。(man7.org)P0-3. remote binding が marker schema より弱い
実際の
PR_REVIEW_PUBLISH_MARKER_V1には次が保存されています。pr_numberrepoidempotency_keyexpected_head_shareview_idreview_urlpublished_atところが #1602 の AC は
review_urlを中心に書かれ、より強い primary key であるreview_idの binding が明示されていません。archive executor は一覧検索ではなく、marker の
review_idを使用して exact review endpoint を取得し、以下を全部検証すべきです。response
id == marker.review_idhtml_url == marker.review_urlpull_request_urlが対象 repo / PR の canonical API URLstate == COMMENTEDcommit_id == expected_head_shasubmitted_atが有効body 末尾に
sha256(idempotency_key)[:32]由来 marker が exactly onceidempotency key から取り出した body SHA-256 と remote body が一致
review author を検証するか、検証対象外にするかを threat model で明示
GitHub の exact review API は
review_idを入力とし、state、html_url、pull_request_url、submitted_at、commit_idを返します。(GitHub Docs)また、「PR state が
MERGED」という文字列比較は REST 契約として曖昧です。専用の merged-check endpointを使い、HTTP204のみを merged と判定し、404は unmerged として拒否してください。(GitHub Docs)API 呼び出しには trusted hostname、recommended media type、明示的な supported API version を固定し、ambient な
gh設定に依存させない方が安全です。現在の GitHub 公式例はX-GitHub-Api-Version: 2026-03-10を使用しています。(GitHub Docs)P0-4. archive root の正本が未定義
Issue は「repo 外の固定 state root」としていますが、以下が未定義です。
root の具体的な locator
XDG_STATE_HOME、HOME、専用 env のどれを authority とするかrelative path、repo 内 path、symlink、他 UID owner、group/world writable root の扱い
mode
0700/ file0600destination collision
cross-filesystem
NFS・network filesystem
test override の認可条件
archive filename と repository identity の namespacing
関連 #1546 は既に、
XDG_STATE_HOME、既定$HOME/.local/state、repo 外、private owner/mode、create-once/no-overwrite という external state root 契約を定義しています。#1602 が #1546 を別 scope とするなら、依存せずに同等の resolver 契約を自己完結して定義するか、#1546 への明示的 dependency を追加すべきです。推奨 locator は次のような content-addressed 形式です。
archive final は no-overwrite にしてください。通常の rename は destination を atomic replacement するため、監査証跡の上書きに使ってはいけません。Linux では
renameat2(RENAME_NOREPLACE)、または archive-root 内 temp file と exclusive link/publish が候補です。cross-filesystem rename はEXDEVになります。(man7.org)P0-5. post-merge-cleanup の output contract に archive 結果を格納できない
現在の
POST_MERGE_CLEANUP_REPORT_V1には marker archive の専用 field がありません。worker は「Procedure(8ステップ)」を実行し、同 schema の全フィールドを必ず返すと固定しています。
このまま Skill に handoff を追記すると、次の問題が発生します。
archive 成功・拒否・partial failure の machine-readable 保存先がない
9番目の step を追加すると worker の「8ステップ」が stale になる
main thread が archive failure を routing-critical と判断できない
Codex worker も同じ
POST_MERGE_CLEANUP_REPORT_V1を返すため consumer inventory が必要少なくとも次を追加してください。
Allowed Paths には最低でも次を追加すべきです。
.claude/agents/post-merge-cleanup-worker.mdpost-merge integration / hookchain test
exact command policy を導入する場合はその policy と両 guard の tests
.agents/skills/post-merge-cleanup/SKILL.mdは canonical Claude skill を読む薄い wrapper なので、本文変更は不要ですが consumer inventory には含めるべきです。High priority
P1-1. tracked file を削除しない保証がない
post-merge SSOT は将来の削除 executor に
git ls-files/git statusによる untracked 確認を要求しています。executor は exact path が schema-validでも、次の場合は拒否すべきです。
index に登録済み
staged deletion/addition
submodule entry
skip-worktree / assume-unchanged の tracked entry
primary worktree 以外の source
default branch root と source repo root が不一致
P1-2. idempotency / recovery matrix が必要
最低限、以下を固定してください。
Source | Archive | 判定 -- | -- | -- present-valid | absent | normal archive present-valid | same hash・valid | source removal retry present-valid | different bytes | collision、fail-close absent | valid matching archive | already_archived absent | archive absent | indeterminate_source_missing absent | invalid archive | corruption、fail-close二重起動では一方だけが final archive を publishし、他方は既存 archive を再検証して収束する必要があります。
P1-3. archive envelope の exact schema がない
archive metadataという説明だけでは実装とテストが分岐します。少なくとも以下を exact-key schema としてください。schema/version
canonical repo full name と repository ID
source relative path
marker exact bytes または base64
marker SHA-256
source
st_dev/st_ino/st_mode/st_uid/st_sizePR number
review ID / URL / author / state / submitted_at / commit_id
expected head
idempotency key
remote merged verification method
archived_at
transaction ID
executor version
raw review bodyやtokenは保存せず、必要な hash と marker identity のみに限定するべきです。
P1-4. failure injection が不足
現状の3つの pytest nodeでは、以下を個別に固定できません。
short write、ENOSPC、EDQUOT、EIO
file
fsyncfailure、archive directoryfsyncfailuresource directory
fsyncfailuresource inode swap
hardlink の検証後追加
symlink ancestor swap
concurrent two-process execution
destination same-hash / different-hash collision
EXDEV
403 / 404 / 429 / 500 / 503
malformed GitHub JSON
wrong review ID / URL /
pull_request_urlmarker が body 中間にある
dismissed review
source absent recovery
post-merge report integration
archive 後に 実装: scope_rollup.run の GitHub inventory を完全 pagination で取得する #1593 preflight が実際に通る regression
#1593 の OWNER reviewでも、広い1コマンドの verification が実装前から通る問題と、page-level failure injection 不足が既に指摘されています。#1602 でも同じ失敗を繰り返さず、ACごとに狭い node ID を用意すべきです。
P1-5. 実装開始 base と shared-file 直列化が必要
source PR #1594 は merge 済みで、当該 head の CI、hook integrity、manifest workflow は成功しています。
ただし、その merge commit後にも main は進んでいます。
実装開始時に以下を記録してください。
current
origin/mainSHA.claude/skills/post-merge-cleanup/SKILL.mdの blob SHAdocs/dev/agent-skill-boundaries.mdの blob SHAoverlapping open PR の同一行変更有無
dependency / serial merge decision
改訂後の最低 Acceptance Criteria
Canonical source validation
--pr-numberだけを受け取り、source path は executor が導出する。dir-fd / inode-bound validation、exact schema、untracked、primary/default worktree を確認する。Exact remote verification
merged endpoint
204、exact review ID GET、review ID / URL / PR URL / state / commit / submitted time / trailing marker / body hash を検証する。Durable no-overwrite archive
private external root に immutable envelope を temp publishし、file + directoryを
fsync。既存 final は上書きしない。Bound source removal
open済み source inode と directory entry を再照合し、FD-relative unlink後に source directoryを
fsync。Honest failure states
unlink 前失敗は source retained。unlink 後の不明状態は
indeterminate。保証できない source retention を主張しない。Idempotent reconciliation
source/archive の全組み合わせ、concurrent invocation、partial transaction から決定論的に収束する。
Post-merge integration
POST_MERGE_CLEANUP_REPORT_V1に typed result を追加し、temp residue や他 artifact family の deletion authority は拡張しない。Runtime verification
実 filesystem、fake GitHub API、実 hookchain、archive 後の anchor preflight regressionを検証する。
結論
問題設定とスコープ分離は良好ですが、現状は implementation-ready ではありません。
特に、次の3点を直さずに実装へ進むべきではありません。
unlink 後も「失敗なら marker が残る」とする実現不能な AC
dir-fd / inode binding を欠く pathname TOCTOU
archive transaction と post-merge output schema の未定義
これらを修正すれば、preflight の generic allowlist を広げず、remote authority を維持したまま、安全に lifecycle を閉じられます。
GitHubへのコメント・Issue編集は行っていません。
# 判定REQUEST_CHANGES —
reframe_in_place。設計方向は正しいです。
pr_review.publishmarker を preflight 側で無視するのではなく、remote GitHub state を authority として限定的に repo 外へ退避する方針は妥当です。既存 publisher も local marker を cache/audit 扱いとし、remote readback を成功判定の正本にしています。ただし現契約のまま実装すると、「失敗時には marker を保持する」という AC を満たせない障害窓、TOCTOU による別ファイル削除、archive 証跡の上書き、post-merge report への結果欠落が残ります。Issue #1602 は現在 open、コメントはまだありません。
マージブロッカー
P0-1. AC3 の failure-atomicity は実現不能な形で矛盾している
現契約はおおむね次の順序です。
しかし、
unlinkが成功した直後に readback、directoryfsync、結果出力のいずれかが失敗した場合、marker はすでに存在しません。再生成による rollback を実装しても、unlinkと rollback の間にプロセス停止・OS crash が起きれば「失敗時は必ず marker を残す」は保証できません。さらに、ファイル本体への
fsyncだけでは directory entry の永続化は保証されず、archive 側と source 側それぞれの directory FD に対するfsyncが必要です。([man7.org]1)AC3 を以下のように分解してください。
indeterminateとして返すsource removed後の失敗に対して「marker を保持した」とは主張しない最低限、次の状態機械が必要です。
結果には
failed_before_archive、archive_durable_source_retained、archive_durable_source_state_indeterminate、archivedを区別して出すべきです。P0-2. pathname ベース検証では marker 差し替え競合を防げない
既存 publisher の入力検証は、各 component の
lstat、Path.resolve()、stat()、st_nlinkを順番に確認しています。しかし検証後、bytes 読み取り前、hash 後、unlink 前のどこでも path entry は別 inode に交換できます。
しかも現在の post-merge-cleanup SSOT 自身が、将来の削除 executor に対して「
Path.resolveではなく dir-fd chain で解決する」ことを要求しています。AC1 に以下を明記してください。
artifacts/<pr>/issue-metadata/pr_review.publish/を directory FD として順次 openopenat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)、またはopenat+O_DIRECTORY/O_NOFOLLOWによる FD-relative walkO_RDONLY | O_NOFOLLOW | O_CLOEXECで openfstatで regular file、st_nlink == 1、size 上限、必要なら owner を確認st_dev/st_inoと開いている FDを再照合unlinkat(dir_fd, exact_name)相当で削除openat()系が必要なのは、path prefix が並行して交換される race を pathname API だけでは避けられないためです。([man7.org]2)openat2のRESOLVE_BENEATH、RESOLVE_NO_SYMLINKS、必要に応じたRESOLVE_NO_XDEVがこの用途に対応します。([man7.org]3)P0-3. remote binding が marker schema より弱い
実際の
PR_REVIEW_PUBLISH_MARKER_V1には次が保存されています。pr_numberrepoidempotency_keyexpected_head_shareview_idreview_urlpublished_atところが #1602 の AC は
review_urlを中心に書かれ、より強い primary key であるreview_idの binding が明示されていません。archive executor は一覧検索ではなく、marker の
review_idを使用して exact review endpoint を取得し、以下を全部検証すべきです。id == marker.review_idhtml_url == marker.review_urlpull_request_urlが対象 repo / PR の canonical API URLstate == COMMENTEDcommit_id == expected_head_shasubmitted_atが有効sha256(idempotency_key)[:32]由来 marker が exactly onceGitHub の exact review API は
review_idを入力とし、state、html_url、pull_request_url、submitted_at、commit_idを返します。([GitHub Docs]4)また、「PR state が
MERGED」という文字列比較は REST 契約として曖昧です。専用の merged-check endpointを使い、HTTP204のみを merged と判定し、404は unmerged として拒否してください。([GitHub Docs]5)API 呼び出しには trusted hostname、recommended media type、明示的な supported API version を固定し、ambient な
gh設定に依存させない方が安全です。現在の GitHub 公式例はX-GitHub-Api-Version: 2026-03-10を使用しています。([GitHub Docs]5)P0-4. archive root の正本が未定義
Issue は「repo 外の固定 state root」としていますが、以下が未定義です。
XDG_STATE_HOME、HOME、専用 env のどれを authority とするか0700/ file0600関連 #1546 は既に、
XDG_STATE_HOME、既定$HOME/.local/state、repo 外、private owner/mode、create-once/no-overwrite という external state root 契約を定義しています。#1602 が #1546 を別 scope とするなら、依存せずに同等の resolver 契約を自己完結して定義するか、#1546 への明示的 dependency を追加すべきです。推奨 locator は次のような content-addressed 形式です。
archive final は no-overwrite にしてください。通常の rename は destination を atomic replacement するため、監査証跡の上書きに使ってはいけません。Linux では
renameat2(RENAME_NOREPLACE)、または archive-root 内 temp file と exclusive link/publish が候補です。cross-filesystem rename はEXDEVになります。([man7.org]6)P0-5. post-merge-cleanup の output contract に archive 結果を格納できない
現在の
POST_MERGE_CLEANUP_REPORT_V1には marker archive の専用 field がありません。worker は「Procedure(8ステップ)」を実行し、同 schema の全フィールドを必ず返すと固定しています。
このまま Skill に handoff を追記すると、次の問題が発生します。
POST_MERGE_CLEANUP_REPORT_V1を返すため consumer inventory が必要少なくとも次を追加してください。
Allowed Paths には最低でも次を追加すべきです。
.claude/agents/post-merge-cleanup-worker.md.agents/skills/post-merge-cleanup/SKILL.mdは canonical Claude skill を読む薄い wrapper なので、本文変更は不要ですが consumer inventory には含めるべきです。High priority
P1-1. tracked file を削除しない保証がない
post-merge SSOT は将来の削除 executor に
git ls-files/git statusによる untracked 確認を要求しています。executor は exact path が schema-validでも、次の場合は拒否すべきです。
P1-2. idempotency / recovery matrix が必要
最低限、以下を固定してください。
already_archivedindeterminate_source_missing二重起動では一方だけが final archive を publishし、他方は既存 archive を再検証して収束する必要があります。
P1-3. archive envelope の exact schema がない
archive metadataという説明だけでは実装とテストが分岐します。少なくとも以下を exact-key schema としてください。st_dev/st_ino/st_mode/st_uid/st_sizeraw review bodyやtokenは保存せず、必要な hash と marker identity のみに限定するべきです。
P1-4. failure injection が不足
現状の3つの pytest nodeでは、以下を個別に固定できません。
fsyncfailure、archive directoryfsyncfailurefsyncfailurepull_request_url#1593 の OWNER reviewでも、広い1コマンドの verification が実装前から通る問題と、page-level failure injection 不足が既に指摘されています。#1602 でも同じ失敗を繰り返さず、ACごとに狭い node ID を用意すべきです。
P1-5. 実装開始 base と shared-file 直列化が必要
source PR #1594 は merge 済みで、当該 head の CI、hook integrity、manifest workflow は成功しています。
ただし、その merge commit後にも main は進んでいます。
実装開始時に以下を記録してください。
origin/mainSHA.claude/skills/post-merge-cleanup/SKILL.mdの blob SHAdocs/dev/agent-skill-boundaries.mdの blob SHA改訂後の最低 Acceptance Criteria
Canonical source validation
--pr-numberだけを受け取り、source path は executor が導出する。dir-fd / inode-bound validation、exact schema、untracked、primary/default worktree を確認する。Exact remote verification
merged endpoint
204、exact review ID GET、review ID / URL / PR URL / state / commit / submitted time / trailing marker / body hash を検証する。Durable no-overwrite archive
private external root に immutable envelope を temp publishし、file + directoryを
fsync。既存 final は上書きしない。Bound source removal
open済み source inode と directory entry を再照合し、FD-relative unlink後に source directoryを
fsync。Honest failure states
unlink 前失敗は source retained。unlink 後の不明状態は
indeterminate。保証できない source retention を主張しない。Idempotent reconciliation
source/archive の全組み合わせ、concurrent invocation、partial transaction から決定論的に収束する。
Post-merge integration
POST_MERGE_CLEANUP_REPORT_V1に typed result を追加し、temp residue や他 artifact family の deletion authority は拡張しない。Runtime verification
実 filesystem、fake GitHub API、実 hookchain、archive 後の anchor preflight regressionを検証する。
結論
問題設定とスコープ分離は良好ですが、現状は implementation-ready ではありません。
特に、次の3点を直さずに実装へ進むべきではありません。
これらを修正すれば、preflight の generic allowlist を広げず、remote authority を維持したまま、安全に lifecycle を閉じられます。
GitHubへのコメント・Issue編集は行っていません。
squne121 commentedon Jul 18, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 18, 2026
Contract Review Result
squne121 commentedon Jul 18, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approved実装: マージ済み PR の pr_review.publish marker を限定 archive し preflight 阻害を防ぐ (…
fix: harden pr_review_marker_archive_exec.py against OWNER security r…
squne121 commentedon Jul 19, 2026
Contract Review Result
実装: マージ済み PR の pr_review.publish marker を限定 archive し preflight 阻害を防ぐ (…