Skip to content

実装: Issue metadata mutation を controlled metadata executor 経由にする - #1295

Merged
squne121 merged 7 commits into
mainfrom
worktree-issue-1284-issue-metadata-mutation-worktree-control
Jul 2, 2026
Merged

squne121 merged 7 commits into
mainfrom
worktree-issue-1284-issue-metadata-mutation-worktree-control

Conversation

@squne121

@squne121 squne121 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Issue #1284 の実装: Issue metadata mutation(Contract Snapshot 投稿・Issue body 更新・Issue comment 投稿)を issue-specific worktree ではなく scripts/agent-guards/controlled_skill_mutation_exec.py の controlled executor lane から root/default branch で実行できるようにする。

controlled_skill_mutation_policy.py(Issue #1166)の CONTROLLED_SKILL_MUTATION_COMMAND_POLICY に 3 command id(issue_body.update / issue_comment.publish / contract_snapshot.publish)を追加し、controlled_skill_mutation_exec.py に対応する実行経路(stale-write 防止 / marker readback / per-command input schema / namespace 統一 artifacts/{issue_number}/issue-metadata/{command-id}/ / env binding optional-but-matching)を実装した。contract_snapshot.publish の publisher authority は .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py に固定し、shell=False argv-list で呼び出す。worktree_scope_guard.py の既存 exact-command-class allow(is_controlled_skill_mutation_exec_command)は executor script identity + argv 形状のみを検証するため、新 3 command id は追加の allowlist entry なしで同じ allow 経路に乗る(raw gh issue edit / gh issue comment は引き続き block)。issue-contract-review/SKILL.md を controlled executor lane 明記に更新した。

Checks

  • 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 / test_ac5_new_command_ids_allowed_via_executor_no_matching_worktree: PASS(実 PreToolUse hook 経路)
  • AC6 test_ac6_tracked_diff_fails_executor: 合格
  • AC7 test_skill_md_mentions_controlled_executor_lane / test_no_worktree_add_command_in_skill_md: 合格
  • AC8 test_ac8_contract_snapshot_publisher_authority_fixed / test_ac8_publisher_invoked_argv_list_shell_false / test_no_direct_post_flag_invocation_in_scripts: 合格
  • AC9 test_ac9_issue_body_update_stale_write_prevented / test_ac9_partial_match_not_success: 合格
  • AC10 test_ac10_per_command_input_schema_enforced: 合格
  • AC11 test_ac11_input_namespace_unified_to_artifacts: 合格
  • AC12 test_no_raw_gh_issue_edit_in_scripts / test_no_raw_gh_issue_comment_in_scripts / test_skill_md_does_not_cite_local_main_branch_guard_as_authorization: 合格
  • AC13 test_ac13_argv_only_shell_false_enforced: 合格
  • AC14 test_ac14_duplicate_marker_not_success 他: 検証合格
  • AC15 test_ac15_env_binding_optional_but_must_match 他: 検証合格
  • 既存回帰: scripts/agent-guards/tests/(397件)/ .claude/hooks/tests/ / .claude/skills/issue-contract-review/ / .claude/skills/impl-review-loop/tests/(合計 2097 passed, 1 skipped, 2 xfailed)
  • pnpm typecheck / pnpm lint / pnpm test(1303 tests)/ pnpm build: 合格
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: 21 passed

Schema Change Applicability

docs/schemas/ 配下の変更なし。CONTROLLED_SKILL_MUTATION_COMMAND_POLICY(Python dict、内部契約)への command id 追加のみ。

  • decision: not_schema_change

Schema Consumer Inventory

N/A(schema 変更なし。CONTROLLED_SKILL_MUTATION_COMMAND_POLICY の既存 consumer(worktree_scope_guard.py / local_main_branch_guard.py)は command-id 値に依存しない共有関数を使うため無変更で動作する)

Safety Claim Matrix

本 PR は .claude/hooks/ および .claude/skills/ 配下を変更するため safety-sensitive パスパターンに該当する。以下の表に、各安全性主張・実装状況・未制御事項・裏付けとなるテスト証跡・追加対応の要否を日本語で説明し、fail-closed 境界が退行していないことを示す。

Claim Implemented? Not controlled Evidence Follow-up
新 3 command id は既存の worktree_scope_guard exact-command-class allow に自動的に乗り、raw gh issue edit/gh issue comment は active issue + no-matching-worktree 状態で引き続き block される Yes .claude/hooks/tests/test_worktree_scope_guard_issue_metadata_executor.py(実 PreToolUse hook 経路、5 tests 合格) なし
issue_body.update は stale-write 防止(previous_body_sha256/previous_updated_at 不一致で mutation しない、片側一致も success にしない) Yes scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py::TestIssueBodyUpdate(3 tests 合格) なし
contract_snapshot.publish の publisher authority は ensure_contract_snapshot.py に固定され、executor は shell=False argv-list でのみ呼び出す。issue-contract-review production path に direct --post は存在しない Yes test_ac8_contract_snapshot_publisher_authority_fixed / test_ac8_publisher_invoked_argv_list_shell_false / test_no_direct_post_flag_invocation_in_scripts なし
readback / idempotency は false success を許さない(marker not found / duplicate marker / body hash mismatch は success にならない) Yes test_ac4_readback_mismatch_not_success / test_ac14_duplicate_marker_not_success なし

Notes

変更ファイル(Allowed Paths)

  • scripts/agent-guards/controlled_skill_mutation_policy.py: 3 command id 追加(issue_body.update / issue_comment.publish / contract_snapshot.publish)、namespace/schema/env-binding 定義追加
  • scripts/agent-guards/controlled_skill_mutation_exec.py: command_id dispatch を追加(legacy termination_report.publish は無変更のロジックを関数分離しただけ)、新 3 command id 用ハンドラ・readback/mutation ヘルパー追加
  • scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py: 新規、23 tests(AC1-AC15 カバー)
  • .claude/hooks/worktree_scope_guard.py: ドキュメントコメント追加のみ(機能変更なし、既存の共有 policy 関数が新 command id を自動的にカバーするため)
  • .claude/hooks/tests/test_worktree_scope_guard_issue_metadata_executor.py: 新規、5 tests(AC5、実 PreToolUse hook 経路)
  • .claude/skills/issue-contract-review/SKILL.md: Contract Snapshot 投稿手順を controlled executor lane に明記、Guardrails に metadata mutation lane を追記
  • .claude/skills/issue-contract-review/tests/test_contract_review_no_worktree_creation.py: 新規、8 tests(AC7/AC12)
  • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py: 無変更(既に gh api argv-list で mutation しており publisher authority の要件を満たしていたため)
  • docs/dev/agent-skill-boundaries.md: Issue metadata mutation executor lane セクションを追加
  • .github/ci/python-test-plan.json: 無変更(既存の scripts/agent-guards/tests/ / .claude/hooks/tests/ / .claude/skills/issue-contract-review/tests/ ディレクトリ target が新規テストを自動カバー)

Allowed Paths 外の変更(Scope Delta)

  • scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py(Allowed Paths 外): TestRegistryScope::test_only_known_command_ids が registry の key set を厳密固定するテストであり、Issue 実装: Issue metadata mutation を worktree ではなく controlled metadata executor 経由にする #1284 の In Scope な registry 拡張(同ファイル内の同一 registry への command id 追加)と直接衝突したため、known_ids に新 3 command id を追加した。これは Issue 自身が明示的に要求する拡張の直接帰結であり、Allowed Paths を再確認いただきたい。

既知の制約

  • issue_body.update / issue_comment.publish の GitHub mutation 経路(gh api --method PATCH/POST)は unit test で mock 化して検証しており、実 GitHub API に対する integration test は行っていない(既存 termination_report.publish の readback パターンを踏襲)。

Closes #1284(Issue #1284 をクローズします)

🤖 Claude Code で自動生成されました / Generated with Claude Code

…tion

Issue #1284: issue_body.update / issue_comment.publish / contract_snapshot.publish
を controlled_skill_mutation_exec.py の同一 executor lane に追加し、Contract Snapshot
投稿と Issue body/comment mutation が issue-specific worktree を作らず root/default
branch から実行できるようにする。stale-write 防止・marker readback・per-command
input schema・namespace 統一・env binding optional-but-matching を実装。

Scope Delta: scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py
(Allowed Paths 外)の registry scope-pin test を、Issue #1284 の In Scope な
registry 拡張と整合させるため更新した(同じ command id 集合を守る既存テストで、
拡張なしでは Issue の core ask が達成できないため)。
@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1295 closed).

@squne121

squne121 commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

検証結果レポート

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

AC 確認コマンド 実行結果(要約) exit code 判定
AC1-4,6,8-11,13-14 uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q 23 passed 0 PASS
AC5 uv run --locked pytest .claude/hooks/tests/test_worktree_scope_guard_issue_metadata_executor.py -q 5 passed 0 PASS
AC7,12 uv run --locked pytest .claude/skills/issue-contract-review/tests/test_contract_review_no_worktree_creation.py -q 8 passed 0 PASS
Standard `pnpm typecheck` OK 0 PASS
Standard `pnpm lint` OK 0 PASS
Standard `pnpm build` OK 0 PASS
Standard `pnpm test` 88 Test Files, 1303 Tests passed 0 PASS
Standard `uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q` 21 passed 0 PASS

総合判定

  • 全 AC PASS: YES
  • FAIL した AC: なし
  • SKIP した AC: なし
  • human_review_required: NO
  • Merge State: BEHIND (base ブランチより古いのみ、OK)
  • Mergeable: MERGEABLE

統計

  • Verification Commands: 3 実行 / 3 PASS / 0 FAIL
  • Standard Verification: 5 実行 / 5 PASS / 0 FAIL
  • Total Tests: 36 VC tests + 1303 vitest + 21 pytest = 1360 tests PASS

```yaml
TEST_VERDICT:
result: PASS
mergeable: MERGEABLE
merge_state_status: BEHIND
branch_behind_main: true
baseline_only: false
verification_commands_pass: 3
verification_commands_fail: 0
verification_skipped_count: 0
head_sha: f984214
runtime_ac_results: []
```

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST_CHANGES

Mergeability

  • mergeable=MERGEABLE, merge_state_status=BEHIND

Evidence Check

  • AC coverage: PR本文の ## Checks に AC1-AC15 全件 [x] 記載あり。AC5/AC9/AC14 等の該当テスト内容を独立閲覧し、stale-write precondition・readback mismatch・duplicate marker が実ロジックで検証されていることを確認(mock はネットワーク境界のみ)。
  • CI Verification: ci_verdict_summary.py --pr 1295 --expected-head-sha f9842141bdedbb84c97215216f32c6ea09cece64 → status: failed(exit 10)。branch protection required checks(typecheck/lint/test/build/python-test/validate-generated-artifact)は全て SUCCESS だが、PR Body Japanese Check(workflow: Check Japanese Content)が head 一致で FAILURE。
    • ログ: .claude/skills/issue-contract-review/SKILL.md の prose block 63件中 13件が日本語比率不足(aggregate=0.314 は閾値超えだが per-block 判定で fail)。
  • Allowed Paths 遵守(独立再計算, allowed_paths_review_gate.py): status: fail_closed。changed files 9件中 scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py が Issue #1284 の Allowed Paths 外。PR本文の Scope Delta 節で開示・理由記載済み(既存 test_only_known_command_ids の key-set pin と In-Scope registry 拡張が直接衝突するための更新)だが、Allowed Paths 自体の契約側拡張(Issue contract 再レビュー)は未実施であり、gate は merge-blocking として扱う。
  • .github/ci/python-test-plan.json 無変更の妥当性: 検証済み。.claude/hooks/tests/ / .claude/skills/issue-contract-review/tests/ / scripts/agent-guards/tests/ は既にディレクトリ単位で python-test-plan.json の target に登録されており、新規テストファイルは自動的にカバーされる(AC 要求と整合)。
  • 実装オラクル: worktree_scope_guard.py::_classify_gh は action-level(issue+comment/edit の sub-action)でのみ mutating 判定しフラグ非依存のため、Notes for Reviewer が要求する --delete-last/--edit-last/--web/--editor/--create-if-none/--yes の raw-path deny は既存の blanket 分類で構造的にカバーされる。executor 側も gh issue comment/gh issue edit CLI を一切呼ばず gh api 固定 argv のみを使うため、当該フラグの pass-through 経路が存在しない。専用テストケースは無いが、構造的に安全であるため blocker としては扱わない(non-blocker として記録)。

Blockers

  • ALLOWED_PATHS_GATE_RESULT_V1.status = fail_closed: scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py が Issue #1284 contract の Allowed Paths 外。修正には Issue contract 側の Allowed Paths 拡張(re-review)または当該変更の Allowed Paths 内ファイルへの再配置が必要。
  • CI PR Body Japanese Check が head f984214 で FAILURE(.claude/skills/issue-contract-review/SKILL.md の 13 prose block が日本語比率不足)。branch protection required set には含まれないが、実際の diff 内容欠陥であり要修正。

Non-blockers

  • --delete-last 等の gh 危険フラグの専用テストが無いが、構造的(action-level 分類 + executor の argv 固定)に安全。follow-up での明示テスト追加を推奨するのみ。
  • Draft PR 状態自体は blocker ではない。

LOOP_VERDICT_V2

verdict: REQUEST_CHANGES
reviewed_head_sha: "f9842141bdedbb84c97215216f32c6ea09cece64"
merge_ready: false
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "BEHIND"
blockers:
  - "ALLOWED_PATHS_GATE_RESULT_V1=fail_closed: scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py is outside Issue #1284 Allowed Paths (Scope Delta disclosed in PR body but contract not yet extended via re-review)"
  - "CI check 'PR Body Japanese Check' FAILURE at head f9842141 (.claude/skills/issue-contract-review/SKILL.md: 13/63 prose blocks below Japanese ratio threshold 0.1)"
required_auto_actions:
  - kind: update_branch
    executor: implementation-worker
    skill: implement-issue.update_branch
    blocking_merge_ready: true
    mechanical: true
    expected_head_sha: "f9842141bdedbb84c97215216f32c6ea09cece64"
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: fail_closed
  producer_role: review_subagent
  worker_report_used_as_canonical: false
  pr_number: 1295
  changed_files_count: 9
  violations:
    - file: "scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py"
      reason: "not in allowed_paths"
allowed_paths_gate_source: review_subagent

issue-contract-review/SKILL.md の見出し・リスト13 block と
agent-skill-boundaries.md 追加分の見出し6 block に日本語併記を追加し、
per-block 日本語比率検証を通過させる(意味論は変更しない)。

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

前回レビュー(iteration 0)の blocker 2件を確認した。

  1. allowed_paths_gate: Issue #1284 の Allowed Paths に scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py が追加された fresh contract snapshot(body_sha256=sha256:975e9d94...、issue comment 4866359529)に対して allowed_paths_review_gate.py を再計算した。head 60daf44 の変更ファイル9件すべてが Allowed Paths 内で status: ok。解消。
  2. Japanese Check: head 60daf44 で SKILL.md / agent-skill-boundaries.md に日本語見出し併記を追加。両ファイルの diff を確認したところ見出し・箇条書きラベルへの日本語併記のみで、手順・contract の意味論(コマンド、判定分岐、schema 定義、Allowed Paths、AC 対応)は無変更。CI「PR Body Japanese Check」も pass。解消。

CI は ci_verdict_summary.py(expected_head_sha=60daf442 一致)で全 required check green(status: all_pass, failed/pending なし)。

mergeStateStatus は BEHIND(main が先行)だが MEREGABLE であり衝突 blocker ではない。update_branch を required_auto_action とする。

verdict: APPROVE
reviewed_head_sha: "60daf44257322929c1f30d154c8b6d96c2890a1c"
merge_ready: false
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "BEHIND"
blockers: []
required_auto_actions:
  - kind: update_branch
    executor: implementation-worker
    skill: implement-issue.update_branch
    blocking_merge_ready: true
    mechanical: true
    expected_head_sha: "60daf44257322929c1f30d154c8b6d96c2890a1c"
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: ok
  produced_by: allowed_paths_review_gate.py
  producer_role: review_subagent
  worker_report_used_as_canonical: false
  pr_number: 1295
  base_ref: main
  base_sha: "5d5df912c687e3df25e1744c490ecea59301062f"
  head_sha: "60daf44257322929c1f30d154c8b6d96c2890a1c"
  reviewed_head_sha: "60daf44257322929c1f30d154c8b6d96c2890a1c"
  changed_files_source: git_diff_base_head
  allowed_paths_source: linked_issue_contract_snapshot
  changed_files_count: 9
  violations: []
  contract_fingerprint:
    issue_number: 1284
    contract_source_kind: issue_comment
    contract_source_id: "4866359529"
    contract_body_sha256: "sha256:975e9d943f593e4ff96c3d03b5c1651c3c16f57401d6aec790b896d4674942b5"
    allowed_paths_normalized_sha256: "69e5bc55c02808ed481b44b9fb1cb943465f042240aac1db84a7c160f6225b73"
    base_ref: main
    base_sha_at_snapshot: "5d5df912c687e3df25e1744c490ecea59301062f"
  reason: "All changed files are within allowed paths"

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE (再確認, update_branch 後)

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN(BEHIND 解消)

update_branch 後の diff 監査

  • 前回 APPROVE head 60daf44 → 現 head 27b4a15 は gh pr update-branch の merge commit(main の b196a072〈#1278〉取り込み)のみ。compare/60daf442...27b4a158 の commit は main 側 b196a072 と merge commit の2件だけで、PR branch 独自の新規実装 commit は無い。
  • gh pr diff --name-only(GitHub 側の実効 PR diff, 現在の base 基準)は9ファイルで iteration 1 と同一。新規混入なし。

Allowed Paths 遵守(独立再計算)

  • allowed_paths_review_gate.py --base-sha <snapshot base 5d5df912> は triple-dot diff に main 側の unrelated 3ファイル(.claude/skills/issue-refinement-loop/**, #1278 由来)を含めてしまい fail_closed を返す。これは update_branch で head に main 先行 commit が merge されたことで、snapshot-time base(5d5df912)基準の triple-dot diff が stale になったことによるスクリプト側の既知の限界(fingerprint と diff-base が同一パラメータに結合されており、post-update-branch のケースを想定していない)。
  • 代わりに GitHub 正本の gh pr diff --name-only(現在の base 基準、update_branch 後の実効差分)を用いて Allowed Paths 照合をやり直したところ、9ファイル全てが Issue #1284 contract snapshot(issue comment 4866359529, body_sha256=sha256:975e9d94...)の Allowed Paths 12件以内に収まることを確認した。violations なし。
  • --base-sha に現在の merge-base(b196a072, main tip)を与えると fingerprint 側の base_sha_at_snapshot が snapshot 記録値(5d5df912)と不一致になり stale_snapshot を返すのも同じ既知限界(診断のみで実 violation ではない)。

CI

ci_verdict_summary.py --pr 1295 --expected-head-sha 27b4a158... → status: all_pass。failed/pending/stale なし。branch protection required checks 全 SUCCESS。

Blockers

なし。

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "27b4a1586d5d43b7625aef223e053ed018a70ce6"
merge_ready: true
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: ok
  produced_by: allowed_paths_review_gate.py + gh_pr_diff_cross_check
  producer_role: review_subagent
  worker_report_used_as_canonical: false
  pr_number: 1295
  base_ref: main
  base_sha: "5d5df912c687e3df25e1744c490ecea59301062f"
  head_sha: "27b4a1586d5d43b7625aef223e053ed018a70ce6"
  reviewed_head_sha: "27b4a1586d5d43b7625aef223e053ed018a70ce6"
  changed_files_source: gh_pr_diff_name_only_post_update_branch
  allowed_paths_source: linked_issue_contract_snapshot
  changed_files_count: 9
  violations: []
  contract_fingerprint:
    issue_number: 1284
    contract_source_kind: issue_comment
    contract_source_id: "4866359529"
    contract_body_sha256: "sha256:975e9d943f593e4ff96c3d03b5c1651c3c16f57401d6aec790b896d4674942b5"
    allowed_paths_normalized_sha256: "69e5bc55c02808ed481b44b9fb1cb943465f042240aac1db84a7c160f6225b73"
    base_ref: main
    base_sha_at_snapshot: "5d5df912c687e3df25e1744c490ecea59301062f"
  reason: "All 9 GitHub PR-diff files are within allowed paths; local triple-dot diff against stale snapshot base_sha included 3 unrelated main-origin files (#1278) due to update_branch merge, verified as not a scope violation via gh pr diff cross-check"

@squne121

squne121 commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。
PR #1295 の方向性、つまり gh issue edit/comment 直叩きを worktree lane から切り離し、Issue metadata mutation を controlled executor lane に寄せる設計自体は正しいです。PR は Issue #1284 実装で、取得時点のメタデータでは open / draft / mergeable、差分は 9 files・+1522/-84 です。
ただし、現在の実装は remote GitHub state を source of truth にしきれておらず、local marker だけで success を返せる経路が残っています。これは Issue #1284 の AC14「false success を許さない」と衝突します。


Blocker 1: issue_body.update が local marker だけで成功できる

_run_issue_body_update() は、issue_body_update.marker.json が存在し、その new_body_sha256 が input と一致すれば、GitHub Issue body を再取得せずに _ok() を返します。

これは stale-write 防止の本質を壊します。攻撃・事故シナリオは単純です。

  1. executor が Issue body を更新し、local marker を書く。
  2. その後、人間または別 automation が GitHub 側の Issue body を再編集する。
  3. 同じ input で再実行すると、local marker だけを見て already_applied として成功する。
  4. 実際の GitHub Issue body は new_body_sha256 と一致していない。

この PR は通常実行時には mutation 前 body_sha256 / updatedAt を確認し、mutation 後にも body hash を readback しています。そこは良い実装です。 しかし marker hit 経路だけがその保証を完全に bypass しています。

修正要求: marker は authority ではなく cache / audit artifact に落としてください。marker hit 時も必ず GitHub から current body を readback し、current_body_sha256 == input.new_body_sha256 を確認するべきです。不一致なら stale_marker_remote_mismatch のような deterministic failure にしてください。追加テストは最低限 local marker exists + remote body hash != new_body_sha256 => rc != 0 and no success が必要です。


Blocker 2: issue_comment.publish も local marker だけで false success する

_run_issue_comment_publish() も同じ欠陥を持ちます。local marker が存在し、その marker が input と一致すると、remote comments を再取得せずに _ok() を返します。

これにより、以下が success になります。

  • GitHub 側のコメントが削除済み。
  • GitHub 側のコメント本文が編集され、marker だけ残った。
  • GitHub 側に duplicate marker が発生している。
  • local marker は残っているが、別 repo / 別 issue / 別 body hash の artifact が混入している。

Issue #1284 の reviewer comment は、issue_comment.publish について marker precheck / postcheck を要求しており、marker count が 0 または exact prior success であること、postcheck で marker count が 1 かつ body hash が一致することを求めています。 現実装は marker file を remote proof と同一視しており、この要求を満たしていません。

修正要求: local marker hit 時も _readback_by_marker_literal() を呼び、remote 側に exactly one match があること、comment_id / comment_url / body_sha256 が marker file および input 由来の期待値と一致することを確認してください。remote が 0 件または複数件なら success 不可です。


Blocker 3: issue_comment.publish は remote marker precheck 前に POST してしまう

現在の flow は POST comment -> marker readback です。_post_gh_comment() が先に呼ばれ、その後 _readback_by_marker_literal() で marker absent / duplicate を検出します。 _readback_by_marker_literal() 自体は 0 件・複数件を error にできますが、それは 投稿後 です。

これは controlled executor として弱いです。local marker が欠落しているが remote には既に同一 marker コメントがある場合、実装はもう 1 件コメントを投稿し、その後 duplicate marker と判定して fail します。つまり fail した transaction が remote side effect を残す。

修正要求: POST 前に remote marker precheck を入れてください。

期待される分岐は次です。

remote_matches == 0:
  post -> readback exactly 1 -> success

remote_matches == 1 and body/comment identity matches expected:
  no-op already_published -> success

remote_matches == 1 but body/comment identity mismatch:
  conflict -> fail before mutation

remote_matches > 1:
  duplicate_marker_conflict -> fail before mutation

追加テストは remote marker already exists + local marker missing => _post_gh_comment not called を必須にしてください。


Blocker 4: contract_snapshot.publish の input schema が薄すぎる

_validate_contract_snapshot_publish_fields() は repo が input に無ければ args.repo を採用し、一致確認だけで通します。 実質的に { "schema": "CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1", "issue_number": 1284 } だけで ensure_contract_snapshot.py --mode auto --post を起動できます。

Issue #1284 のレビュー履歴では、contract_snapshot.publish は target_issue_body_sha256、latest contract review status が still go、newer blocked result が無いこと、marker/comment readback exact などを pre/postcondition として固定すべきと指摘されています。 現PRはこのうち多くを publisher 側に委譲していますが、executor input contract としては mutation authority が広すぎます。

修正要求: CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1 に少なくとも以下を持たせてください。

{
  "schema": "CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1",
  "repo": "squne121/loop-protocol",
  "issue_number": 1284,
  "target_issue_body_sha256": "sha256:...",
  "expected_latest_contract_review_status": "go",
  "expected_contract_marker": "...",
  "operation_reason": "contract_snapshot_publish"
}

executor か publisher のどちらで検証するかは実装都合で構いませんが、input schema に束縛されない auto --post は controlled mutation として広すぎます。


Blocker 5: contract_snapshot.publish は legacy executor と同等の env / import boundary を継承していない

legacy termination_report.publish では、child process に渡す env から PUBLISH_ARTIFACT_DIR、PYTHONPATH、PYTHONHOME、editor/browser 系を除去し、GH_PROMPT_DISABLED も設定しています。 さらに module realpath / import origin check もあります。

一方、contract_snapshot.publish の subprocess 呼び出しは env= を指定していません。 main() 側でも module realpath check は legacy command のみです。 publisher である ensure_contract_snapshot.py は内部で gh を名前解決し、run_contract_review_once.py も subprocess で呼びます。

これは #1166 の前例と比べて退行です。#1166 は repo / issue / input / artifact / env / import / postcondition / idempotency を束縛した controlled remote mutation transaction を目的にしていました。

修正要求: contract_snapshot.publish でも metadata 専用 sanitizer を作り、少なくとも PYTHONPATH / PYTHONHOME / editor/browser / prompt 系 / artifact-dir override を制御してください。加えて、ensure_contract_snapshot.py、run_contract_review_once.py、contract_review_result_parser.py の canonical realpath / import origin を検証対象に入れるべきです。


Blocker 6: command-specific namespace を謳う一方で postcondition の write root が広い

input file は新 command ID ごとに artifacts/{issue}/issue-metadata/{command-id}/ に縛られています。 しかし _check_no_tracked_changes() は artifacts/{issue}/ 配下の任意変更を許可します。 policy も ALLOWED_WRITE_ROOTS = ["artifacts/"] を全 command で共有しています。

これは「namespace は command-id ごとに分離」という設計説明より緩いです。意図しない artifact、別 command の marker、または issue-scoped な unrelated JSON を書いても postcondition が通ります。

修正要求: 新 3 command ID では write root も artifacts/{issue}/issue-metadata/{command-id}/ に縮めてください。legacy termination_report.publish だけ artifacts/{issue}/ を維持する分岐で十分です。


技術選定の評価: raw gh issue を避けた点は正しいが、REST transaction の粒度をもっと固定すべき

GitHub CLI の gh issue edit は body だけでなく assignee、label、project、sub-issue など広い issue metadata を変更できます。(GitHub CLI) gh issue comment も stdin body、--delete-last、--edit-last、--editor、--web など interactive / destructive な枝を持ちます。([GitHub CLI]2) したがって、このPRが raw gh issue edit/comment ではなく gh api --method PATCH/POST に寄せている点は正しいです。

ただし gh api -F/--field は @<path> でファイルを読み、@- で stdin を読む仕様です。([GitHub CLI]3) したがって、body=@tmp_path を使うなら、その tmp file 生成・削除・env・PATH・stdin禁止・readback まで executor transaction の一部として扱う必要があります。Python subprocess は shell を暗黙には使わず、shell=True にした場合は shell injection 防止の quoting 責任がアプリ側に移るため、argv-list / shell=False の方針自体は妥当です。([Python documentation]4)

REST API 側でも、Issue update は body を更新でき、403/404/410/422/503 などの status を返します。([GitHub Docs]5) ([GitHub Docs]5) ([GitHub Docs]5) Issue comment 作成は owner/repo/issue_number/body を要求し、201/403/404/410/422 を返します。([GitHub Docs]6) ([GitHub Docs]6) ([GitHub Docs]6) 現在の _patch_issue_body() / _post_gh_comment() は stderr slice を返すだけなので、ensure_contract_snapshot.py と同じ粒度で HTTP error を分類した方がよいです。


テストが false green を許している

テストは増えていますが、今の blocker を捕まえません。

tmp_project fixture は ensure_contract_snapshot.py を "# stub\n" として作るだけで、実 publisher の import / env / gh 呼び出し境界を検証していません。 contract_snapshot.publish の success test は subprocess.run を丸ごと fake success に差し替えています。 これでは authority fixed という文字列検査に近く、publisher transaction の安全境界は確認できません。

また issue_comment.publish の duplicate marker test は、_post_gh_comment() が成功した後に _readback_by_marker_literal() が duplicate を返す形です。 つまり「副作用後に失敗する」ケースを許容しており、「mutation 前に deny する」ことを検証していません。

追加すべき最小テストは以下です。

issue_body.update:
- local marker exists, remote body hash != input.new_body_sha256 => rc=1, status!=ok
- local marker exists, remote body hash == input.new_body_sha256 => ok
- local marker exists but marker repo/issue/input_sha mismatch => rc=1 or rc=2

issue_comment.publish:
- local marker exists, remote marker absent => rc=1, status!=ok
- local marker exists, remote duplicate marker => rc=1, status!=ok
- remote marker exists before run, local marker missing => _post_gh_comment not called
- remote marker exists with different body_sha256 => conflict before mutation

contract_snapshot.publish:
- child env contains no PYTHONPATH/PYTHONHOME/editor/browser override
- ensure_contract_snapshot.py / parser / run_contract_review_once.py realpath mismatch => deny
- input missing target_issue_body_sha256 or expected status => rc=2
- publisher returns ok but artifact/readback marker missing => rc=1

Non-blocker: stale documentation

controlled_skill_mutation_exec.py の冒頭 docstring はまだ termination_report.publish only、LOOP_ISSUE_NUMBER mandatory、Issue #1166 の説明に寄っています。 実装は #1284 の新 command IDs を扱っているため、安全境界を説明するファイルとしては誤誘導です。これは単独 blocker ではありませんが、security-sensitive な executor では修正すべきです。


まとめ

このPRは、raw gh issue edit/comment を直接許可しない方向、argv-list / shell=False、input file の subtree validation、mutation 後 readback など、重要な部品は入っています。is_controlled_skill_mutation_exec_command() も shell metachar、duplicate flag、--flag=value、script path mismatch を拒否する設計で、入口の形状制御はかなり良いです。

ただし現状では idempotency marker が remote proof ではなく local shortcut になっている ため、Issue #1284 の主目的である “controlled metadata mutation” の安全境界が閉じていません。issue_body.update と issue_comment.publish の marker hit 経路を remote readback 必須にし、issue_comment.publish の pre-mutation idempotency check を追加し、contract_snapshot.publish に legacy executor と同等の env/import boundary を適用するまで merge 不可です。

squne121 added 2 commits July 3, 2026 06:45
…se successを解消

PR #1295 の人間レビュー REQUEST_CHANGES(Blocker 1-6)を反映。

- issue_body.update / issue_comment.publish: local marker を authority から
  cache/audit に格下げし、marker hit 時も必ず remote readback で判定する
  (stale_marker_remote_mismatch)。
- issue_comment.publish: POST 前に remote marker precheck を追加し、
  duplicate/conflict を mutation 前に fail closed にする
  (remote_matches 0/1一致/1不一致/2+ の4分岐)。
- contract_snapshot.publish: CONTRACT_SNAPSHOT_PUBLISH_INPUT_V1 に
  target_issue_body_sha256 / expected_latest_contract_review_status /
  expected_contract_marker / operation_reason を必須化し、legacy publisher
  と同等の env sanitizer・module realpath 検証(ensure_contract_snapshot.py /
  run_contract_review_once.py / contract_review_result_parser.py)を追加。
- 新3 command の postcondition write root を
  artifacts/{issue}/issue-metadata/{command-id}/ に縮小(legacy
  termination_report.publish は artifacts/{issue}/ を維持)。
- gh api エラーを ensure_contract_snapshot.py と同粒度で HTTP status 分類。
- レビューが要求した最小テスト(marker/remote mismatch・pre-mutation
  precheck・env sanitizer・realpath deny・required field 欠落)を追加。

Issue #1284, PR #1295 iteration 2.
…ta-mutation-worktree-control' into worktree-issue-1284-issue-metadata-mutation-worktree-control
@squne121

squne121 commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author
TEST_VERDICT:
  result: PASS
  mergeable: MERGEABLE
  merge_state_status: BEHIND
  branch_behind_main: true
  baseline_only: false
  verification_commands_pass: 49
  verification_commands_fail: 0
  verification_skipped_count: 0
  runtime_ac_results:
    - ac: AC1
      command: "uv run --locked pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q"
      exit_code: 0
      status: pass
      fallback_detected: false
      artifact_present: not_required
      human_review_required: false
      stop_condition_triggered: false
      notes: "36 passed (coverage AC1-4, AC6, AC8-11, AC13-15)"
    - ac: AC5
      command: "uv run --locked pytest .claude/hooks/tests/test_worktree_scope_guard_issue_metadata_executor.py -q"
      exit_code: 0
      status: pass
      fallback_detected: false
      artifact_present: not_required
      human_review_required: false
      stop_condition_triggered: false
      notes: "5 passed"
    - ac: AC7
      command: "uv run --locked pytest .claude/skills/issue-contract-review/tests/test_contract_review_no_worktree_creation.py -q"
      exit_code: 0
      status: pass
      fallback_detected: false
      artifact_present: not_required
      human_review_required: false
      stop_condition_triggered: false
      notes: "8 passed (coverage AC7, AC12)"

Summary

All 15 acceptance criteria verified PASS via 3 pytest test suites (49 tests total).

Standard Checks

  • pnpm typecheck: PASS
  • pnpm lint: PASS (no issues)
  • pnpm test: PASS (1305 tests, 89 test files)
  • pnpm build: PASS
  • gemini-cli-headless-delegation: PASS (21 tests)

PR Status

  • mergeable: MERGEABLE
  • mergeStateStatus: BEHIND (branch is behind main but no conflicts)
  • head SHA: 7cbb462

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE(人間 Blocker 6件 再検証、iteration 2)

Mergeability

mergeable=MERGEABLE, merge_state_status=BEHIND(衝突なし、update_branch を required_auto_action とする)

Blocker 別コード検証(head 7cbb462, worker 自己申告でなく実コード・実テスト実行で確認)

  1. issue_body.update marker hit → remote readback 必須: scripts/agent-guards/controlled_skill_mutation_exec.py:999-1032 (_run_issue_body_update)。marker 存在時も必ず _fetch_issue_body_and_updated_at() で remote readback し、current_body_sha256 != new_body_sha256 なら stale_marker_remote_mismatch で _fail(success にならない)。marker はもはや authority でなく consistency check(issue_number/repo)のみに限定。テスト test_local_marker_remote_hash_mismatch_denied(L323-347)を分離 worktree で実行し pass 確認(mock_patch.assert_not_called() 相当は無いが _patch_issue_body mock で mutation 未実行を検証)。解消。
  2. issue_comment.publish marker hit → remote readback 必須: L1124-1149。local marker の有無に関わらず _find_marker_matches() で remote 状態を先に取得し、1件一致時のみ already_published で success、_write_marker は refresh のみ。0件/複数件/body不一致は local marker と無関係に判定される。テスト test_remote_marker_exists_local_marker_missing_post_not_called(L466-495)で mock_post.assert_not_called() かつ rc==0 を確認、実行 pass。解消。
  3. POST 前の remote marker precheck 4分岐: L1128-1156。_find_marker_matches() を _post_gh_comment() より前に必ず呼び、>1件→duplicate_marker_conflict_pre_mutation/1件+body不一致→remote_marker_identity_conflict_pre_mutation/1件+body一致→already_published no-op/0件→POSTの4分岐を実装。「mutation 前 deny」の要求どおり _post_gh_comment 呼出前に fail する。テスト test_ac14_pre_mutation_duplicate_denied_before_post(L440-464, mock_post.assert_not_called())と test_remote_marker_body_sha256_mismatch_conflict_before_mutation(L497-519, 同様に assert_not_called)を分離 worktree で実行し pass 確認。「副作用後に fail」の形には戻っていない。解消。
  4. contract_snapshot.publish input schema 必須束縛: _validate_contract_snapshot_publish_fields()(L449-468)が repo 一致に加え target_issue_body_sha256 / expected_latest_contract_review_status / expected_contract_marker / operation_reason の4フィールドを非空文字列として必須化。人間指摘の最小 input(schema+issue_number のみ)は test_contract_snapshot_publish_missing_required_field_rc2(L687-703)で rc=2 拒否を確認、実行 pass。解消。
  5. env sanitizer + realpath/import origin 検証: _build_metadata_sanitized_env()(L183-195)が ENV_SANITIZE_KEYS(editor/browser系)+ PYTHONPATH/PYTHONHOME 除去 + GH_PROMPT_DISABLED/GH_NO_UPDATE_NOTIFIER を設定し、_run_contract_snapshot_publish()(L1291-1296)で subprocess.run(cmd, ..., shell=False, env=sanitized_env) として実際に渡している(env= 未指定だった人間指摘は解消)。_check_contract_snapshot_module_realpaths()(L201-222)が ensure_contract_snapshot.py/run_contract_review_once.py/contract_review_result_parser.py の3モジュールを realpath/shadowing 検証し、_run_contract_snapshot_publish() の schema 検証直後(mutation 前)に呼ばれる。テスト test_metadata_sanitized_env_removes_pythonpath_pythonhome/removes_editor_browser/disables_prompts、test_contract_snapshot_publish_realpath_mismatch_denied を実行し全 pass。解消。
  6. write root の command-id scoping: _check_no_tracked_changes()(L707-747)が allowed_prefix 引数を追加、新3コマンドは artifacts/{issue}/issue-metadata/{command_id}/ を明示的に渡す(_run_issue_body_update L990/1069、_run_issue_comment_publish L1103/1167、_run_contract_snapshot_publish L1279/1320)。allowed_prefix=None の legacy termination_report.publish は既定値 artifacts/{issue}/ を維持(L730-731)。解消。
  • docstring 更新(non-blocker): モジュール冒頭 docstring が termination_report.publish (legacy, Issue #1166) と issue_body.update / issue_comment.publish / contract_snapshot.publish (Issue #1284 issue metadata mutation) を併記する形に更新済み(L8-26 付近)。解消。

テスト実在検証(fresh clone + fresh worktree、self-report ではなく独立実行)

/tmp/pr1295check/repo(head 7cbb462 を fetch/checkout)で uv run pytest scripts/agent-guards/tests/test_controlled_issue_metadata_exec.py -q → 36 passed(vacuous/skip なし)。人間要求の最小テスト(stale marker mismatch / duplicate marker pre-mutation / remote-exists-local-missing no-op / contract_snapshot 必須フィールド欠落 rc=2 / env sanitize / realpath deny)はすべて実在し、mutation 前 assert(mock_post.assert_not_called() / mock_patch.assert_not_called())で「副作用後 fail」ではなく「mutation 前 deny」を検証している。

CI

ci_verdict_summary.py --pr 1295 --expected-head-sha 7cbb4628... → status: all_pass。failed/pending/stale なし。

Allowed Paths(独立再計算)

allowed_paths_review_gate.py(snapshot base 5d5df912固定・triple-dot diff)は fail_closed(5 violations)を返すが、これは前回 iteration と同一の既知限界(BEHIND による update_branch 未実施時点の snapshot-base diff に main 側の unrelated commit が混入するため)。gh pr diff --name-only(GitHub 正本の実効 PR diff)で cross-check したところ 9 ファイル全てが Issue #1284 contract snapshot(issue comment 4866359529, body_sha256=sha256:975e9d94...、allowed_paths_normalized_sha256=69e5bc55... 一致)の Allowed Paths 12件以内。violations なし。status: ok(gh_pr_diff cross-check 経由)。

Blockers

なし。

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "7cbb462892651af6f85cd5e57bdedd52ce81025d"
merge_ready: false
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "BEHIND"
blockers: []
required_auto_actions:
  - kind: update_branch
    executor: implementation-worker
    skill: implement-issue.update_branch
    blocking_merge_ready: true
    mechanical: true
    expected_head_sha: "7cbb462892651af6f85cd5e57bdedd52ce81025d"
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: ok
  produced_by: allowed_paths_review_gate.py + gh_pr_diff_name_only_cross_check
  producer_role: review_subagent
  worker_report_used_as_canonical: false
  pr_number: 1295
  base_ref: main
  base_sha: "5d5df912c687e3df25e1744c490ecea59301062f"
  head_sha: "7cbb462892651af6f85cd5e57bdedd52ce81025d"
  reviewed_head_sha: "7cbb462892651af6f85cd5e57bdedd52ce81025d"
  changed_files_source: gh_pr_diff_name_only
  allowed_paths_source: linked_issue_contract_snapshot
  changed_files_count: 9
  violations: []
  contract_fingerprint:
    issue_number: 1284
    contract_source_kind: issue_comment
    contract_source_id: "4866359529"
    contract_body_sha256: "sha256:975e9d943f593e4ff96c3d03b5c1651c3c16f57401d6aec790b896d4674942b5"
    allowed_paths_normalized_sha256: "69e5bc55c02808ed481b44b9fb1cb943465f042240aac1db84a7c160f6225b73"
    base_ref: main
    base_sha_at_snapshot: "5d5df912c687e3df25e1744c490ecea59301062f"
  reason: "gh pr diff --name-only (9 files) all within allowed paths; local snapshot-base triple-dot diff stale due to BEHIND state, same known limitation as prior iteration"
allowed_paths_gate_source: review_subagent

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

verdict: APPROVE(update_branch 後の確定レビュー、iteration 2 完了)

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "26b5cda57391a273d675884486b14758516eb015"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []
  allowed_paths_gate:
    schema: ALLOWED_PATHS_GATE_RESULT_V1
    producer_role: review_subagent
    worker_report_used_as_canonical: false
    status: ok
    changed_files_source: gh_pr_diff_name_only_cross_check
    notes: "全9ファイルがcontract Allowed Pathsに完全一致。update_branch由来の混入なし。"

確認結果

  1. 差分確認: head 26b5cda は 7cbb462 に main の merge commit(#1293由来の1コミット d4894b4 + merge commit 26b5cda5自体)を取り込んだのみ。gh pr diff --name-only で得た PR 自体の changed files は 9 ファイルで、7cbb4628 時点の実装変更と同一。新規実装変更なし。
  2. Allowed Paths gate: gh pr diff --name-only の 9 ファイル全てが Issue #1284 contract の Allowed Paths と完全一致。逸脱なし(status: ok)。
  3. CI: ci_verdict_summary.py --expected-head-sha 26b5cda5... で status: all_pass, exit 0。全 required check(ci/typecheck, lint, test, build, e2e, python-test, node-backed-hook-tests, actionlint, check-hook-integrity, PR Body Japanese Check, validate-generated-artifact, deploy-pr)SUCCESS。head_sha 一致(stale なし)。
  4. Mergeability: mergeable: MERGEABLE, mergeStateStatus: CLEAN(BEHIND 解消)。よって required_auto_actions: [], merge_ready: true。

iteration 2 の APPROVE(review 4621394565)で確認済みの人間 Blocker 6件解消・AC15項目・Safety Claim Matrix・Schema Consumer Inventory は再変更なしのため再確定。blocker なし。

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.

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

1 participant