Skip to content

実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Issue metadata mutation を worktree 境界から分離し、controlled executor lane で決定論的に実行できる状態にする"
change_kind: mixed

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: Issue 本文修正・Contract Snapshot 投稿などの GitHub metadata mutation を、repo 作業木 mutation と同じ worktree 境界で扱わない
  • Desired Destination: metadata mutation は controlled executor lane、file mutation は worktree lane という二層構造の確立

Current Validated Scope

  • scripts/agent-guards/controlled_skill_mutation_policy.py に issue_body.update / issue_comment.publish / contract_snapshot.publish の command id を追加(command id ごとに個別 input schema・precondition・postcondition を持つ)
  • scripts/agent-guards/controlled_skill_mutation_exec.py に対応する実行経路と readback 検証・stale-write 防止を追加
  • contract_snapshot.publish の実 publisher authority を .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py に固定し、executor から shell=False argv で呼び出す
  • .claude/hooks/worktree_scope_guard.py に controlled executor 経由の metadata mutation を allow する exact command class を追加
  • .claude/skills/issue-contract-review/SKILL.md から worktree 作成経路を排除し、controlled executor lane を明記
  • 上記の adversarial テスト追加(must-block / must-allow 両軸、実 PreToolUse hook 経路)

Remaining Parent Gaps

Outcome

issue-contract-review の Contract Snapshot 投稿と Issue body/comment mutation が、issue-specific worktree を作らず root/default branch から controlled executor(policy 検証 + stale-write 防止 + readback 付き)で実行でき、対応するテストが CI で PASS している状態。

Background

issue-contract-review は「実装直前の deterministic preflight」であり、guardrails に code edit / branch / PR / worktree を作らないと明記されている。それにもかかわらず、worktree_scope_guard.py が gh issue comment / gh issue edit を mutating command に分類し、active issue 解決済みで対応 worktree がない場合に fail-closed で block するため、metadata mutation のためだけに worktree へ入る運用が発生している。

controlled mutation executor は現状 termination_report.publish のみを扱い(scripts/agent-guards/controlled_skill_mutation_policy.py、ALLOWED_WRITE_ROOTS = ["artifacts/"])、input schema・binding・readback は termination report の形に結合している。この lane を Issue body update / comment publish / contract snapshot publish に拡張する。

Contract Snapshot 投稿の既存実体は .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py にあり(run_contract_review_once.py は「API post は ensure_contract_snapshot.py が扱う」と明記)、body / updatedAt 再取得による stale check(stale_or_conflicting_snapshot)を既に実装している。本 Issue はこの publisher を executor lane に組み込み、direct 実行経路を production path から封鎖する。

また local_main_branch_guard.py には gh issue comment <N> --body-file tmp/... 等を条件付き allow する既存 lane があるが、本 Issue の成功経路の認可根拠としては使わない(責務差分を AC で固定する)。

In Scope

  • controlled_skill_mutation_policy.py への 3 command id(issue_body.update / issue_comment.publish / contract_snapshot.publish)追加。各 command は required repo binding / issue number binding / input file binding(artifacts/<issue_number>/issue-metadata/<command-id>/ subtree 内のみ)/ command id ごとの個別 input schema 検証 / idempotency(body sha256 または marker readback)を持つ
  • controlled_skill_mutation_exec.py の実行経路追加(mutation 後 readback 不一致は成功扱いしない、tracked diff 発生時は失敗、issue_body.update は previous_body_sha256 / previous_updated_at の precondition 比較で stale-write を防止)
  • contract_snapshot.publish は executor から ensure_contract_snapshot.py を subprocess.run([...], shell=False) で呼び出す。--artifact-dir の任意指定は executor policy で束縛し、executor を経由しない direct --post は production path から排除する
  • worktree_scope_guard.py に controlled executor の exact command class allow を追加(raw gh issue edit / gh issue comment の block は維持)
  • executor の issue number binding は --issue-number == input.issue_number + repo/origin binding を必須とし、LOOP_ISSUE_NUMBER env は存在する場合のみ一致必須(env 非存在は root 実行の正常系)
  • issue-contract-review/SKILL.md の Contract Snapshot 投稿手順を controlled executor 呼び出しに書き換え
  • 新テストの .github/ci/python-test-plan.json への登録

Out of Scope

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 全 AC が pytest による決定論的検証(実 PreToolUse hook 経路の subprocess 統合テストを含む)で CI 内に完結し、静的品質ゲート外の runtime 証跡を要しない

Acceptance Criteria

  • AC1: Contract Snapshot 投稿が issue-specific worktree を作らず root/default branch から controlled executor で実行できる
  • AC2: issue_body.update は input file が policy で許可された artifacts/<issue_number>/issue-metadata/<command-id>/ subtree 外の場合 fail-closed する
  • AC3: wrong repo / wrong issue number / absolute path / .. / symlink / schema mismatch は mutation 前に exit 2 で拒否される
  • AC4: mutation 後の readback で body hash または marker が一致しない場合、成功扱いにならない
  • AC5: worktree_scope_guard.py の active issue + no matching worktree 状態で raw gh issue edit / gh issue comment は引き続き block され、controlled executor の exact command は allow される
  • AC6: tracked file に diff が出た場合 executor は失敗する
  • AC7: issue-contract-review/SKILL.md に worktree 作成経路が残っておらず、metadata mutation は controlled executor lane と明記されている
  • AC8: contract_snapshot.publish の実 publisher authority が ensure_contract_snapshot.py に固定されている。executor は同スクリプトを shell=False argv で呼び、--artifact-dir の任意 write 先指定は policy 検証済みの値のみ許可され、executor を経由しない direct --post が issue-contract-review production path に存在しないことが negative test で固定されている
  • AC9: issue_body.update は stale-write 防止を持つ。input の previous_body_sha256 / previous_updated_at が mutation 直前の readback と一致しない場合は mutation せず、mutation 後の body_sha256 が input の new_body_sha256 と一致しない限り success にしない。片側のみ一致するズレも success にしない
  • AC10: 3 command id は個別 input schema(ISSUE_BODY_UPDATE_INPUT_V1 / ISSUE_COMMENT_PUBLISH_INPUT_V1 / CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1)を fixture で固定し、command id と schema の不一致は mutation 前に deny される
  • AC11: input file namespace は artifacts/ に統一されている。policy registry / executor validation / issue-contract-review/SKILL.md / tests の namespace 表記不一致は test fail になる
  • AC12: issue-contract-review の production path は raw gh issue edit / gh issue comment を呼ばず、local_main_branch_guard.py の既存 raw gh allowlist を成功経路の認可根拠として使わないことが test で固定されている
  • AC13: executor invocation と publisher invocation は argv-list / shell=False のみを使い、bash -lc / sh -c / python -c / --body-file -(stdin)/ shell metachar / duplicate flags は mutation 前に deny される
  • AC14: readback / idempotency は false success を許さない。marker absent / duplicate marker / body hash mismatch / comment readback mismatch / GitHub API error(403・422・429)/ JSON parse failure / timeout は success にならない
  • AC15: executor は LOOP_ISSUE_NUMBER env が存在しなくても --issue-number == input.issue_number と repo binding が成立すれば実行でき、env が存在して --issue-number と不一致の場合は mutation 前に拒否される

Verification Commands

# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC5
$ uv run --locked pytest .claude/hooks/tests/test_worktree_scope_guard_issue_metadata_executor.py -q
# AC6
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC7
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_contract_review_no_worktree_creation.py -q
# AC8
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC9
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC10
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC11
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC12
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_contract_review_no_worktree_creation.py -q
# AC13
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC14
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q
# AC15
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q

Allowed Paths

  • scripts/agent-guards/controlled_skill_mutation_policy.py
  • scripts/agent-guards/controlled_skill_mutation_exec.py
  • scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py
  • scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py
  • .claude/hooks/worktree_scope_guard.py
  • .claude/hooks/tests/test_worktree_scope_guard_issue_metadata_executor.py
  • .claude/skills/issue-contract-review/SKILL.md
  • .claude/skills/issue-contract-review/tests/test_contract_review_no_worktree_creation.py
  • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
  • docs/dev/agent-skill-boundaries.md
  • .github/ci/python-test-plan.json

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

なし

Scope Delta(任意)

N/A

Notes for Reviewer

  • VC は check_vc_scope の bare path 規約(Allowed Paths と完全一致のみ narrow)に従い file-level 実行とする。AC ごとの対応テスト関数は以下を実装すること: AC1=test_ac1_contract_snapshot_publish_from_root, AC2=test_ac2_input_file_outside_artifacts_subtree_fails_closed, AC3=test_ac3_binding_violations_rejected_before_mutation, AC4=test_ac4_readback_mismatch_not_success, AC5=test_ac5_raw_gh_issue_mutation_still_blocked, AC6=test_ac6_tracked_diff_fails_executor, AC7=test_ac7_skill_md_uses_controlled_executor_lane, AC8=test_ac8_contract_snapshot_publisher_authority_fixed, AC9=test_ac9_issue_body_update_stale_write_prevented, AC10=test_ac10_per_command_input_schema_enforced, AC11=test_ac11_input_namespace_unified_to_artifacts, AC12=test_ac12_production_path_uses_executor_only, AC13=test_ac13_argv_only_shell_false_enforced, AC14=test_ac14_readback_idempotency_no_false_success, AC15=test_ac15_env_binding_optional_but_must_match
  • fail-closed guard の変更を含むため、must-block / must-allow 両軸の adversarial テスト(実 PreToolUse hook 経路、stdin JSON + 実 git worktree)を必須とする
  • 新テストは .github/ci/python-test-plan.json への登録まで含める
  • executor / publisher の GitHub mutation は subprocess.run([...], shell=False, capture_output=True, text=True, timeout=...) のみを使い、hand-crafted shell string を組み立てない
  • negative matrix の最低ライン: unknown command id は mutation 前 exit 2 / tmp/../x.json 等の traversal deny / symlink・hardlink・absolute path・stdin - deny / input JSON の repo・issue_number・schema・body hash mismatch deny / marker duplicate の deterministic 分類 / gh issue comment の --delete-last・--edit-last・--web・--editor・--create-if-none・--yes は raw path・executor path 双方で deny / updatedAt のみ変化した stale ケースの block
  • 本 Issue は 実装: hooks: publish_termination_report 用 controlled mutation policy を分離する #1166(termination_report.publish executor)で後追い指摘された input-file resolution・issue_number 検証・readback/idempotency/import-origin 束縛の類型を contract に最初から含めている。実装: implement-issue の worktree bootstrap を controlled executor 化し、rtk/raw git policy 衝突を解消する #1209(worktree bootstrap executor)と同粒度で「direct route 封鎖」まで含めて閉じること

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Jul 2, 2026
  2. squne121 commented on Jul 2, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    方向性は正しいです。Issue #1284 は、gh issue edit/comment のような GitHub metadata mutation を worktree lane から切り離し、issue_body.update / issue_comment.publish / contract_snapshot.publish を controlled executor lane に載せる設計です。Issue 本体は 2026-07-02 時点で open、コメントは 0 件でした。

    ただし、このまま実装すると false green になります。最大の問題は、Issue #1284 が「何を通すか」は書いている一方で、「既存のどの publisher 実体を置換・封鎖するか」「tmp/ と artifacts/ の authority をどう統一するか」「issue body update の stale-write をどう防ぐか」が契約化されていない点です。


    P0-1: contract_snapshot.publish の実体が Allowed Paths から漏れている

    Issue #1284 は issue-contract-review/SKILL.md の Contract Snapshot 投稿手順を controlled executor 呼び出しに書き換える、としています。 しかし、現在の issue-contract-review 本体は「go の場合に Contract Snapshot コメントを投稿する」とだけ規定し、実際の投稿実装は run_contract_review_once.py ではなく impl-review-loop/scripts/ensure_contract_snapshot.py 側にあります。run_contract_review_once.py 自身も「API post は ensure_contract_snapshot.py が扱う」と明記しています。

    ensure_contract_snapshot.py は check-only / auto / dry-run と --post を持ち、gh api --method POST repos/{repo}/issues/{issue}/comments でコメント投稿し、body / updatedAt / comments digest の再取得による atomicity check も実装しています。 しかし Issue #1284 の Allowed Paths にはこのファイルも既存テストも入っていません。

    修正要求: contract_snapshot.publish は次のどちらかに固定してください。

    1. ensure_contract_snapshot.py を controlled executor から呼ぶ正式な publisher とする。この場合、Allowed Paths に ensure_contract_snapshot.py と対応テストを追加し、--artifact-dir など任意 write capability を executor 側で封鎖する。
    2. ensure_contract_snapshot.py を呼ばず、controlled_skill_mutation_exec.py 内または新規 allowed helper に Contract Snapshot 投稿を再実装する。この場合、既存の direct ensure_contract_snapshot --post 経路を Issue 実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284 の対象外として明示し、skill path が必ず executor を通る negative test を追加する。

    現契約のままだと、SKILL.md の文面だけが変わり、実際の mutation path は旧来のまま残る可能性が高いです。


    P0-2: tmp/ と artifacts/ の authority が衝突している

    Issue #1284 は input file binding を「canonical tmp subtree 内のみ」と書いています。 一方、既存の controlled_skill_mutation_policy.py は ALLOWED_WRITE_ROOTS = ["artifacts/"] を持ち、現 executor は artifacts/<issue>/ 配下の input と marker を前提にしています。

    さらに local_main_branch_guard.py には、gh issue comment <N> --body-file tmp/... や gh issue edit <N> --repo squne121/loop-protocol --body-file tmp/... を限定的に許可する既存ロジックがあります。 つまり、Issue #1284 の「metadata mutation は controlled executor lane」という設計と、既存の「local main で一部 raw gh mutation を許可する lane」が重なります。

    修正要求: authority root を 1 つに決めてください。候補は次のいずれかです。

    • artifacts/<issue>/issue-metadata/<command-id>/input.json
    • tmp/issue-metadata/<issue>/<command-id>/input.json

    ただし、tmp/ を使うなら idempotency marker や audit artifact の永続性が弱くなります。artifacts/ を使うなら Issue #1284 本文の “canonical tmp subtree” を修正してください。現状のままでは、実装者が tmp/ と artifacts/ の両方を正当化でき、review が不可能になります。


    P0-3: 3 command ID を足すだけでは安全境界にならない

    既存 executor は termination_report.publish 専用です。input schema も TERMINATION_REPORT_INPUT_V1 前提で、issue_number の一致、artifact subtree、symlink / hardlink 拒否、marker readback などが termination report の形に強く結合しています。

    Issue #1284 は issue_body.update / issue_comment.publish / contract_snapshot.publish を追加しますが、この 3 つは同じ mutation ではありません。GitHub CLI でも gh issue edit は body だけでなく title, label, project, assignee, milestone, parent/sub-issue など多数の metadata を編集できます。(GitHub CLI) gh issue comment も --edit-last, --delete-last, --create-if-none, --web, --editor, --yes など mutation / interactive / destructive な枝を持ちます。([GitHub CLI]2)

    修正要求: policy registry は command ID ごとに最低限これを持つべきです。

    issue_body.update:
      input_schema: ISSUE_BODY_UPDATE_INPUT_V1
      mutation: update_issue_body_only
      required_precondition:
        repo: exact squne121/loop-protocol
        issue_number: cli == input == active binding
        previous_body_sha256: must match current readback
        previous_updated_at: must match current readback
      postcondition:
        body_sha256: must equal expected_new_body_sha256
        tracked_diff: none
    
    issue_comment.publish:
      input_schema: ISSUE_COMMENT_PUBLISH_INPUT_V1
      mutation: create_issue_comment_only
      idempotency:
        marker: deterministic command/repo/issue/body hash
        precheck: marker count == 0 or exact prior success
        postcheck: marker count == 1 and comment body hash matches
    
    contract_snapshot.publish:
      input_schema: CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1
      mutation: create_contract_snapshot_comment_only
      precondition:
        target_issue_body_sha256: must match current issue body
        latest_contract_review_status: still go
        no newer blocked result
      postcondition:
        marker/comment readback exact

    GitHub REST API の Update an issue は issue owner / push access / Triage role で issue を編集でき、body field を更新対象にできます。([GitHub Docs]3) Create an issue comment は owner, repo, issue_number, body を必須にし、201/403/404/410/422 などの status を返します。([GitHub Docs]4) CLI で実装する場合でも、executor 内では REST のこの粒度に対応する pre/postcondition を固定すべきです。


    P0-4: Issue body update には stale-write 防止が必要

    Issue #1284 の AC4 は「mutation 後 readback 不一致は成功扱いしない」としています。 これは必要ですが不十分です。issue_body.update は readback 後に一致しても、直前に人間または別プロセスが本文を更新していた場合、その更新を上書きして成功できます。

    既存の ensure_contract_snapshot.py はこの問題を一部認識しており、最初に body と updatedAt を取得し、投稿直前に再取得して body_sha256 や updatedAt が変わっていれば stale_or_conflicting_snapshot にしています。 Issue #1284 の issue_body.update は、これより強い precondition を持つ必要があります。

    修正要求: issue_body.update input には少なくとも次を必須化してください。

    {
      "schema": "ISSUE_BODY_UPDATE_INPUT_V1",
      "repo": "squne121/loop-protocol",
      "issue_number": 1284,
      "previous_body_sha256": "sha256:...",
      "previous_updated_at": "2026-07-02T...",
      "new_body_sha256": "sha256:...",
      "body_file_sha256": "sha256:...",
      "operation_reason": "contract_refinement"
    }

    実行順序は read current -> compare previous_body_sha256/updatedAt -> mutate -> read current -> compare new_body_sha256 です。updatedAt が変わったが body hash は同じ、または body hash が変わったが updatedAt が同じ、といった片側だけのズレも human_judgment か stale_or_conflicting_snapshot に倒すべきです。


    P0-5: raw gh issue edit/comment の block claim が guard ごとに違う

    worktree_scope_guard.py は gh issue edit / gh issue comment を mutating command と分類し、controlled skill mutation executor を先に exact allow する構造になっています。 したがって Issue #1284 の「active issue + no matching worktree では raw gh を block」は worktree guard の話としては妥当です。

    しかし local_main_branch_guard.py 側には、既に限定的な GitHub issue mutation allowlist があります。gh issue comment <N> --body-file tmp/... や gh issue edit <N> --repo squne121/loop-protocol --body-file tmp/... は条件付きで allow されます。 その後、未許可の gh issue/pr mutation は fail-closed で block されます。

    修正要求: AC5 を次のように分割してください。

    • AC5a: worktree_scope_guard.py の active issue + no matching worktree 状態では、raw gh issue edit/comment は block、controlled executor exact command は allow。
    • AC5b: issue-contract-review / impl-review-loop の production path は raw gh issue edit/comment を一切呼ばない。
    • AC5c: local_main_branch_guard.py の既存 raw gh allowlist は本 Issue の認可根拠ではない。必要なら別 Issue で deprecate する。

    この分割がないと、レビュー時に「worktree guard では block」「local main では一部 allow」の両方が同時に真になり、AC が曖昧になります。


    P0-6: LOOP_ISSUE_NUMBER 必須は root/no-worktree 目標と衝突しうる

    現 executor は LOOP_ISSUE_NUMBER が存在しないと error にし、存在しても --issue-number と一致しないと error にします。 一方、Issue #1284 は「root/default branch から issue-specific worktree なしで実行できる」ことを求めています。

    ここで危険なのは、root session が active issue env を持たない場合です。inline env で LOOP_ISSUE_NUMBER=1284 ... を付ける回避は local_main_branch_guard.py が明示的に block する設計です。

    修正要求: 次のどちらかに決めてください。

    • executor は env binding を必須にせず、--issue-number == input.issue_number と repo/origin binding だけで許可する。ただし hook が active issue を解決できる場合は一致必須。
    • env binding を必須にするなら、SKILL.md に「inline env ではなく hook/process environment として LOOP_ISSUE_NUMBER が供給される」ことを明記し、no-env negative test と valid-env positive test を追加する。

    現状の AC1 は、実運用で「worktree は不要だが env がなくて executor が常に失敗する」可能性を潰せていません。


    P1: 実装方式は shell=False + argv list に固定すべき

    Issue #1284 の reviewer note は「raw command は gh issue edit --body-file / gh issue comment --body-file に限る、hand-crafted shell string は不要」と書いています。 これは正しい方向です。Python 公式 docs でも、subprocess.run() は argv sequence が一般に推奨され、escaping/quoting を subprocess 側に任せられると説明しています。([Python documentation]5) shlex は shell-like lexical split であり、非 POSIX shell では quoting が安全とは限らないため、shell=False の list argv を使うべきです。([Python documentation]6)

    修正要求: AC に以下を明記してください。

    • executor 内の GitHub mutation は subprocess.run([...], shell=False, capture_output=True, text=True, timeout=...) のみ。
    • bash -lc, sh -c, python -c, process substitution, redirection, pipe は executor invocation と publisher invocation の両方で deny。
    • gh api を使うなら、GitHub CLI docs が示す通り --method を明示し、-F/--field の @file 読み込み semantics を input-file validation と同じ root で束縛する。([GitHub CLI]7)
    • gh issue edit/comment を使うなら、CLI の --body-file - は stdin freeform なので必ず deny する。gh issue edit と gh issue comment はどちらも --body-file <file> があり、- は stdin 読み込みです。([GitHub CLI]1) ([GitHub CLI]2)

    P1: Hook は sandbox ではないので、test は “real hook path” が必要

    Claude Code の PreToolUse は tool call 実行前に走り、allow / deny / ask / defer が可能です。([Claude Platform Docs]8) ただし command hooks はユーザー権限で shell command を実行でき、入力 validation、path traversal block、absolute path 使用などが best practice として明記されています。([Claude Platform Docs]8) Codex 側も PreToolUse は guardrail であり完全な enforcement boundary ではなく、すべての shell call を捕捉するわけではないと説明しています。([OpenAI Developers]9)

    Issue #1284 の reviewer note は real PreToolUse hook path と actual git worktree を使った must-block / must-allow adversarial tests を要求しています。 これは必須です。unit test だけでは、hook matcher、cwd、active issue resolution、worktree presence、local root / linked worktree の差分を検証できません。

    追加すべき negative matrix:

    • uv run python3 ... --command-id unknown.command ... は guard allow 後 executor が mutation 前に exit 2。
    • --command-id issue_comment.publish --input-file tmp/../x.json は deny。
    • symlink component / hardlink / absolute path / stdin - は deny。
    • input JSON の repo / issue_number / schema / body hash mismatch は mutation 前に deny。
    • marker duplicate は no-op か conflict として deterministic に分類。
    • marker absent after publish、marker 2 件、comment body hash mismatch は success 不可。
    • gh issue comment --delete-last, --edit-last, --web, --editor, --create-if-none, --yes は raw path でも executor path でも deny。gh issue comment はこれらの flags を公式に持っています。([GitHub CLI]2)
    • issue_body.update は pre-read と post-read の両方を fixture 化し、updatedAt だけ変わるケースも block。
    • ensure_contract_snapshot.py --artifact-dir /tmp/out のような arbitrary write capability は executor 経由で deny または無効化。現在 CLI は --artifact-dir を受け取り、指定先へ JSON artifact を保存します。

    関連 Issue / PR から見た設計リスク

    #1166 は termination_report.publish を単一 executor 経由にする親実装で、repo / issue / input / artifact / env / import / postcondition / idempotency を束縛することを求めていました。 PR #1182 はそれを実装して merged された PR ですが、PR 本文の safety matrix が “yes” とした後でも、後続の敵対的レビューでは input-file resolution mismatch、input issue_number 未検証、readback/idempotency/import-origin 束縛不足が REQUEST_CHANGES として指摘されています。

    この履歴から、#1284 は単に「#1166 の command ID を 3 つ増やす」では不足です。#1166 で後から潰した種類のバグを、#1284 の contract / AC / VC に最初から入れるべきです。

    また、#1209 の worktree bootstrap executor は raw git worktree add を controlled executor に置換し、exact argv / repo root / default branch / idempotent readback / shell=False subprocess を固定した前例です。 #1284 も同じ粒度で「raw gh を消す」だけでなく、「executor の入出力・readback・idempotency・direct route 封鎖」を contract 化する必要があります。

    #1287 は edit-issue / issue-author の transaction script 化が #1284 の controlled executor lane に依存すると明記しています。 #1289 は PreToolUse fast-path / telemetry dedupe を別 Issue に切り出しています。 したがって #1284 では、transaction script 化や hook optimization に逃げず、metadata executor の authority 境界だけを閉じるべきです。


    修正版 AC 案

    既存 AC に追加するなら、最低限この形にしてください。

    - [ ] AC8: `contract_snapshot.publish` の実 publisher authority を固定する。
          `ensure_contract_snapshot.py` を呼ぶ場合は同ファイルと tests を Allowed Paths に含め、
          `--artifact-dir` / direct `--post` / temp-file write を executor policy で封鎖または検証する。
          呼ばない場合は production path が executor 実装のみを使うことを negative test で固定する。
    
    - [ ] AC9: `issue_body.update` は stale-write 防止を持つ。
          input.previous_body_sha256 と input.previous_updated_at が mutation 直前 readback と一致しない場合は mutation しない。
          mutation 後は body_sha256 が input.new_body_sha256 と一致しない限り success にしない。
    
    - [ ] AC10: 3 command ID は個別 schema を持つ。
          `ISSUE_BODY_UPDATE_INPUT_V1`, `ISSUE_COMMENT_PUBLISH_INPUT_V1`,
          `CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1` を fixture で固定し、
          command ID と schema の不一致は mutation 前に deny する。
    
    - [ ] AC11: input file namespace を `tmp/...` または `artifacts/...` のどちらかに統一する。
          policy registry, executor validation, SKILL.md, tests, python-test-plan の表記不一致を fail にする。
    
    - [ ] AC12: worktree_scope_guard と local_main_branch_guard の責務差分を固定する。
          worktree guard では raw `gh issue edit/comment` を block し exact executor を allow。
          local_main の既存 raw gh allowlist は #1284 の success path として使わない。
    
    - [ ] AC13: executor invocation は argv-list / shell=False だけを使う。
          `bash -lc`, `sh -c`, `python -c`, `--body-file -`, shell metachar, duplicate flags,
          `--flag=value` が mutation 前 deny されることを fixture 化する。
    
    - [ ] AC14: readback/idempotency は false success を許さない。
          marker absent, duplicate marker, body hash mismatch, comment id/url mismatch,
          GitHub 403/429/422, JSON parse failure, timeout は success ではない。

    最終コメント

    Issue #1284 は、metadata mutation と worktree mutation を分離する設計としては必要です。ただし現本文は、既存の ensure_contract_snapshot.py、local_main_branch_guard.py の raw gh allowlist、artifacts/ 前提の termination_report.publish executor を十分に織り込めていません。

    このまま実装すると、「executor command ID は増えたが、旧 direct publisher が残る」「Contract Snapshot だけ別ルートで投稿される」「tmp/ と artifacts/ が混在する」「body update が stale overwrite できる」という形で、AC は通っても安全境界は閉じません。修正後に着手すべきです。

  3. squne121 commented on Jul 2, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 2, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-02T12:56:51Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1284
      body_sha256: "sha256:0752e990e151ab21d0b3f26a49343e2cc6852a95bfc75ee7adca3d34088a5716"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. squne121 commented on Jul 2, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-02T13:39:04Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1284
      body_sha256: "sha256:975e9d943f593e4ff96c3d03b5c1651c3c16f57401d6aec790b896d4674942b5"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions