Skip to content

実装: HEAD-bound TEST_VERDICT publisher transaction を追加する - #1827

Merged
squne121 merged 6 commits into
mainfrom
worktree-issue-1647-head-bound-test-verdict-publisher
Jul 28, 2026
Merged

squne121 merged 6 commits into
mainfrom
worktree-issue-1647-head-bound-test-verdict-publisher

Conversation

@squne121

@squne121 squne121 commented Jul 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Child A(protected execution artifact producer receipt)に束縛された current-head TEST_VERDICT だけを idempotent に公開できる、専用 test_verdict.publish transaction を追加した。generic issue_comment.publish は target PR HEAD を検証しないため、この新 command id は既存 pr_review.publish の expected head precondition / commit-bound postcondition の precedent を踏襲しつつ、target PR と linked Issue を別 field として検証する。

  • scripts/agent-guards/controlled_skill_mutation_policy.py: 新 command id test_verdict.publish と TEST_VERDICT_PUBLISH_INPUT_V1 closed input schema を CONTROLLED_SKILL_MUTATION_COMMAND_POLICY に追加。既存 command id(pr_review.publish の --pr-number grammar / _PR_REVIEW_PUBLISH_ONLY_FLAGS を含む)の schema/dispatch/argv/postcondition は不変。
  • scripts/agent-guards/controlled_skill_mutation_exec.py: _validate_test_verdict_publish_fields(target PR / linked Issue を独立 required field として検証)、pre/post publish の PR HEAD readback、linked Issue body SHA readback、marker precheck(duplicate 検出)、投稿後の author/marker/body 一致検証、idempotency marker 書き込みを実装。
  • テスト: test_test_verdict_publish_exec.py(新規)で AC1〜AC4 の成功経路・fail-closed 経路を検証。test_controlled_skill_mutation_policy.py に registry scope pin 更新を追加。
  • 既存 実装: pr_review.publish render mode の linked Issue / target PR 分離を復旧する #1822 由来の pr_review.publish render mode --pr-number 分離ロジック(enforce_issue_pr_match / _PR_REVIEW_PUBLISH_ONLY_FLAGS / command-id/mode grammar)は変更・削除していない。

受け入れ条件の達成状況

  • AC1: test_verdict.publish は target PR と linked Issue を別の required field として検証する — _validate_test_verdict_publish_fields が target_pr_number / linked_issue_number を独立に検証する。両者が同一値の場合は(別々の entity である PR と Issue が偶然同じ番号を持つことはあり得ないため)test_verdict_publish_target_pr_number_invalid として fail-closed で拒否する(fix_delta P1-3 でこの挙動を維持したまま本文の記述矛盾を修正、test_given_closed_request_when_validated_then_target_pr_and_linked_issue_are_independent, scripts/agent-guards/tests/test_test_verdict_publish_exec.py)。
  • AC2: valid receipt と expected HEAD が一致する場合だけ、unique TEST_VERDICT marker を含むコメントを公開する — _run_test_verdict_publish が pre-publish で _fetch_pr_head_sha / _fetch_linked_issue_body_sha256 を readback してから POST し、投稿後に marker/body/author を再検証する(test_given_current_receipt_when_publish_then_pre_and_post_head_and_comment_are_verified, 同ファイル:87)。
  • AC3: pre/post publish HEAD drift、receipt/body mismatch、author/marker mismatch、duplicate idempotency key は fail-closed で公開しない — test_given_pre_publish_head_drift_when_publish_then_post_is_not_attempted(同ファイル:113)、test_given_postcondition_author_or_marker_or_body_mismatch_when_published_then_fail_closed(同ファイル:133)、test_given_duplicate_marker_when_publish_then_fail_before_post(同ファイル:161)で検証済み。
  • AC4: generic issue_comment.publish request は TEST_VERDICT publish transaction の代替にならない — test_given_generic_issue_comment_command_when_test_verdict_is_requested_then_no_alias_exists(同ファイル:81)で COMMAND_ID_ISSUE_COMMENT_PUBLISH の input schema が TEST_VERDICT_PUBLISH_INPUT_V1 と異なることを検証。
  • AC5: producer_receipt は schemas/test-verdict-producer-receipt.schema.json に対して jsonschema.Draft202012Validator でフル検証される — _validate_producer_receipt_schema(test_given_receipt_missing_producer_field_when_validated_then_schema_rejects 等)。
  • AC6: receipt の producer/execution_artifact を GitHub API から live readback し、workflow run/job/check run の紐付けと head SHA、artifact メタデータを照合する — _verify_producer_run_and_job / _verify_execution_artifact_metadata(test_verify_producer_run_and_job_checks_run_repo_job_and_check_run_linkage 等)。
  • AC7: artifact archive を実ダウンロードして sha256 を再計算し receipt の digest と照合する — _download_and_verify_artifact_archive(test_download_and_verify_artifact_archive_recomputes_digest_and_extracts_per_ac 等)。
  • AC8: 公開 body は verified receipt から決定論的に生成され、PR/Issue/HEAD/artifact/result/per-AC coverage を receipt と cross-check する — _render_test_verdict_body / _cross_check_test_verdict_body。
  • AC9: idempotent retry 経路で fresh HEAD/Issue body 再検証と tracked-changes 再確認を行う — test_given_retry_path_head_drifts_between_readbacks_when_publish_then_stale。
  • AC10: marker 事前埋め込み拒否とPOST後marker再確認を行う — test_given_body_already_contains_marker_prefix_when_publish_then_rejected_before_post / test_given_post_marker_recheck_finds_more_than_one_when_publish_then_conflicted。
  • AC11: linked Issue が PR の場合は fail-closed で拒否する — _fetch_linked_issue_body_sha256(test_fetch_linked_issue_body_sha256_rejects_pull_request 等)。

検証コマンド結果(fix_delta 反映後、head 1b00610c2da52e223a133998413ceb15061e2938)

  • uv run --locked pytest scripts/agent-guards/tests/test_test_verdict_publish_exec.py -q → 24 passed(AC1〜AC11。旧6件 + fix_delta 新規18件)
  • uv run --locked pytest scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py -q → 80 passed(実装: pr_review.publish render mode の linked Issue / target PR 分離を復旧する #1822 由来の TestPrReviewPublishPrNumberGrammar を含む既存テスト回帰なし)
  • uv run --locked pytest scripts/agent-guards/tests/test_controlled_pr_review_publish_exec.py -q → 51 passed(実装: pr_review.publish render mode の linked Issue / target PR 分離を復旧する #1822 由来の pr_review.publish テスト回帰なし)
  • uv run --locked ruff check scripts/agent-guards/controlled_skill_mutation_exec.py scripts/agent-guards/controlled_skill_mutation_policy.py scripts/agent-guards/tests/test_test_verdict_publish_exec.py scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py → All checks passed
  • pnpm policy:check → All checks passed(secret policy / session recording policy / CI performance assessment 108 tests 全 PASS)

Rebase 経緯

本 PR の base commit は旧 main(d1cae8fb1b5245a9d88f6994a109ec0be138fb8f)から分岐していたため、origin/main(765154b4729fba1b9c3bbf8ddafbff807c049cab、#1825 マージ後)へ git rebase した。controlled_skill_mutation_exec.py / controlled_skill_mutation_policy.py で #1822(pr_review.publish render mode の --pr-number 独立化・command-id/mode grammar)とコンフリクトが発生し、両方の変更意図を保持する形で手動解決した(#1822 側の enforce_issue_pr_match / _PR_REVIEW_PUBLISH_ONLY_FLAGS を維持しつつ、#1647 の test_verdict.publish dispatch を追加)。test_controlled_skill_mutation_policy.py はコンフリクトなく自動マージされ、#1822 由来の TestPrReviewPublishPrNumberGrammar と #1647 新規テストの両方が現存することを確認済み。

修正差分(Fix Delta): Issue #1647 の Scope Delta AC5〜AC11 への対応(PR #1827 REQUEST_CHANGES 反映)

人間 OWNER の敵対的レビュー(PR #1827 comment、REQUEST_CHANGES)で判明した P0×2/P1×4 に対応した。Issue #1647 の Scope Delta(issue comment)で追加された AC5〜AC11 を実装。新しい head: 1b00610c2da52e223a133998413ceb15061e2938。

  • AC5(P0-1 の一部): _validate_producer_receipt_schema を追加し、producer_receipt を schemas/test-verdict-producer-receipt.schema.json に対して jsonschema.Draft202012Validator でフル検証する(producer オブジェクト全体・execution_payload_sha256 を含む required + additionalProperties: false を強制)。scripts/agent-ops/test_verdict_execution_record_producer.py::_validate_against_schema と同じパターン。未知フィールド・producer 欠落・execution_payload_sha256 欠落は fail-closed で拒否する。
  • AC6(P0-1 の一部): _verify_producer_run_and_job / _verify_execution_artifact_metadata を追加し、receipt の producer.workflow_run_id / workflow_run_attempt / job_id / check_run_id を GitHub API(actions/runs/{id}/attempts/{attempt}、actions/jobs/{id}、check-runs/{id}、actions/artifacts/{id})から live readback する。workflow run の repository/head SHA、job の run 紐付けと head SHA、check run の job/run 紐付けと head SHA、artifact メタデータの id/非期限切れを照合し、不一致・readback 失敗は test_verdict_publish_receipt_live_readback_failed として fail-closed で拒否する。
  • AC7(P0-1 の一部): _download_and_verify_artifact_archive を追加し、gh api repos/{repo}/actions/artifacts/{id}/zip で execution-record artifact を実ダウンロードし、そのバイト列の sha256 を再計算して receipt の execution_artifact.artifact_archive_digest と照合する(scripts/agent-ops/test_verdict_execution_record_producer.py::_cmd_download_artifact と同じ zip 展開パターン)。展開した execution-record 自身の payload_sha256 自己検証、および receipt の execution_payload_sha256 との相互検証も行う。この artifact に含まれる per_ac coverage を後続の body 生成に用いる。
  • AC8(P0-2): _render_test_verdict_body を追加し、公開する comment body は自由入力を受け付けず、検証済み receipt(PR番号・Issue番号・HEAD・artifact_id・result・per-AC coverage)から決定論的に生成する。_cross_check_test_verdict_body で生成直後に自己 cross-check し、不一致があれば fail-closed で拒否する(防御的二重チェック)。_TEST_VERDICT_PUBLISH_ALLOWED_KEYS から body/body_sha256 を削除し、idempotency_key の式からも body_sha256 を除去した。
  • AC9(P1-1): idempotent retry 経路(既存 marker が1件見つかった場合)で、既存コメントの postcondition 検証後に PR HEAD と linked Issue body の 再度 fresh readback を追加した。drift があれば published_but_stale として扱い、_check_no_tracked_changes によるトラッキング済み変更の再確認も追加した(従来この経路には postcondition の tracked-changes チェックが欠落していた)。
  • AC10(P1-2): 入力 body(決定論的生成後)に TEST_VERDICT_PUBLISH_MARKER_PREFIX が既に含まれる場合は POST 前に fail-closed で拒否する。POST 後に marker 一覧を再取得し、該当 marker を持つコメントが1件以外なら test_verdict_publish_post_marker_recheck_failed として published_but_conflicted 扱いにする。完全な分散 exactly-once(workflow 側の concurrency group 設定等)は Out of Scope のまま(Safety Claim Matrix に明記)。
  • P1-3: target_pr_number == issue_number を拒否する現行実装は変更していない。PR 本文 AC1 の説明が「同一値でも受理する」ように読める記述だったため、実装の実際の挙動(同値は test_verdict_publish_target_pr_number_invalid で拒否)と一致するよう本文を修正した。
  • AC11(P1-4): _fetch_linked_issue_body_sha256 を、GitHub API レスポンスの pull_request フィールド有無(isPullRequest: has("pull_request") jq 式、_fetch_issue_content と同一パターン)で判定するよう変更し、対象が PR の場合は test_verdict_linked_issue_is_pull_request で fail-closed 拒否するようにした。

新規テスト18件(既存6件 + 新規18件 = 24件): schema検証失敗(producer欠落/execution_payload_sha256欠落/未知フィールド)、live readback失敗(workflow run head SHA mismatch)、artifact digest不一致、body/receipt cross-check不一致、retry経路でのHEAD drift検出、marker事前埋め込み拒否、POST後marker競合検出、linked issueがPRの場合の拒否を追加。

Allowed Paths 遵守

Allowed Paths(4ファイル):

  • scripts/agent-guards/controlled_skill_mutation_policy.py
  • scripts/agent-guards/controlled_skill_mutation_exec.py
  • scripts/agent-guards/tests/test_test_verdict_publish_exec.py
  • scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py

実際の変更ファイル(git diff --name-only origin/main...HEAD、4ファイル)は上記 Allowed Paths と完全一致し、範囲外の変更はない。

Checks

  • uv run --locked pytest scripts/agent-guards/tests/test_test_verdict_publish_exec.py -q → 24 passed(AC1〜AC11、fix_delta 反映後)
  • uv run --locked pytest scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py -q → 80 passed(実装: pr_review.publish render mode の linked Issue / target PR 分離を復旧する #1822 由来の既存テストも回帰なし)
  • uv run --locked pytest scripts/agent-guards/tests/test_controlled_pr_review_publish_exec.py -q → 51 passed(実装: pr_review.publish render mode の linked Issue / target PR 分離を復旧する #1822 由来の pr_review.publish テストも回帰なし)
  • uv run --locked ruff check scripts/agent-guards/controlled_skill_mutation_exec.py scripts/agent-guards/controlled_skill_mutation_policy.py scripts/agent-guards/tests/test_test_verdict_publish_exec.py scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py → All checks passed(lint エラーなし)
  • pnpm policy:check → All checks passed(secret policy / session recording policy / CI performance の全ゲート通過)

Schema Change Applicability

  • decision: schema_change
  • reason: CONTROLLED_SKILL_MUTATION_COMMAND_POLICY に新 command id test_verdict.publish と新 input schema TEST_VERDICT_PUBLISH_INPUT_V1 を追加した。

Schema Consumer Inventory

# before
CONTROLLED_SKILL_MUTATION_COMMAND_POLICY = {
    "termination_report.publish": {...},
    "issue_body.update": {...},
    "issue_comment.publish": {...},
    "contract_snapshot.publish": {...},
    "pr_review.publish": {...},
    "issue_scope_snapshot.materialize": {...},
    "issue_dependency.remove": {...},
}
# after
CONTROLLED_SKILL_MUTATION_COMMAND_POLICY = {
    "termination_report.publish": {...},
    "issue_body.update": {...},
    "issue_comment.publish": {...},
    "contract_snapshot.publish": {...},
    "pr_review.publish": {...},
    "issue_scope_snapshot.materialize": {...},
    "issue_dependency.remove": {...},
    "test_verdict.publish": {...},   # 新規追加。既存 entry は無変更。
}
Consumer ファイル 更新有無 備考
scripts/agent-guards/controlled_skill_mutation_exec.py 更新あり 新 command id の dispatch・pre/post HEAD readback・comment postcondition 検証を追加実装(既存 pr_review.publish render mode ロジックは不変)
scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py 更新あり 新 command id の registry scope pin を更新(#1822 由来の pr_review.publish grammar テストは無変更のまま存続)
scripts/agent-guards/tests/test_test_verdict_publish_exec.py 更新あり AC1〜AC4 の成功経路・fail-closed 経路テスト+fix_delta で AC5〜AC11 のテストを追加(計24テスト)
Step 2 consumer(materializer/adjudicator) 更新なし Child C の責務であり本 Issue のスコープ外(Out of Scope)

Safety Claim Matrix

# SAFETY_CLAIMS_V1
safety_claims:
    - claim: "test_verdict.publish は target PR 番号と linked Issue 番号を別の required field として独立に検証し、field 分離自体は維持される。同一値(PR と Issue が同じ番号)は fail-closed で拒否する(P1-3: この挙動は fix_delta で変更していない)"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_validate_test_verdict_publish_fields"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_closed_request_when_validated_then_target_pr_and_linked_issue_are_independent"
      not_controlled: []
      follow_up: []
    - claim: "投稿前に target PR HEAD と linked Issue body SHA を readback し、expected 値と一致しない限り comment POST を行わない(fail-closed, no network mutation on drift)"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_run_test_verdict_publish の pre-publish readback ブロック"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_pre_publish_head_drift_when_publish_then_post_is_not_attempted"
      not_controlled: []
      follow_up: []
    - claim: "投稿後に author/marker/body を再検証し、いずれかが不一致なら success を返さない(postcondition fail-closed)"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_validate_test_verdict_comment"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_postcondition_author_or_marker_or_body_mismatch_when_published_then_fail_closed"
      not_controlled: []
      follow_up: []
    - claim: "同一 idempotency key の marker が既に複数存在する場合は POST 前に fail-closed で拒否する(duplicate 検出)"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_run_test_verdict_publish の _find_test_verdict_marker_matches チェック"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_duplicate_marker_when_publish_then_fail_before_post"
      not_controlled: []
      follow_up: []
    - claim: "generic issue_comment.publish は test_verdict.publish の input schema を持たず、TEST_VERDICT 公開の代替経路にならない"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_generic_issue_comment_command_when_test_verdict_is_requested_then_no_alias_exists"
      not_controlled: []
      follow_up: []
    - claim: "producer_receipt は schemas/test-verdict-producer-receipt.schema.json に対して jsonschema.Draft202012Validator でフル検証される(producer / execution_payload_sha256 を含む required と additionalProperties: false を強制、未知フィールド・producer欠落・execution_payload_sha256欠落を fail-closed で拒否)"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_validate_producer_receipt_schema"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_receipt_missing_producer_field_when_validated_then_schema_rejects"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_receipt_missing_execution_payload_sha256_when_validated_then_schema_rejects"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_receipt_has_unknown_field_when_validated_then_schema_rejects"
      not_controlled: []
      follow_up: []
    - claim: "receipt の producer(workflow_run_id/workflow_run_attempt/job_id/check_run_id)と execution_artifact のメタデータを GitHub API から live readback し、workflow run の repository/head SHA、job の run 紐付けと head SHA、check run の job/run 紐付けと head SHA、artifact の id/非期限切れが receipt の値と一致することを確認する。不一致・readback失敗は fail-closed で拒否する"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_verify_producer_run_and_job"
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_verify_execution_artifact_metadata"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_verify_producer_run_and_job_checks_run_repo_job_and_check_run_linkage"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_verify_producer_run_and_job_detects_head_sha_mismatch"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_live_readback_of_workflow_run_fails_when_publish_then_fail_closed_before_post"
      not_controlled:
        - "実 GitHub Actions ワークフロー上での live end-to-end 実行検証(fixture/モックによる readback ロジックの unit test のみ、Issue #1647 Runtime Verification Applicability 参照)"
      follow_up:
        - "#1645"
    - claim: "execution-record artifact archive を実ダウンロードして sha256 を再計算し、receipt の artifact_archive_digest と一致することを確認する。展開した execution-record 自身の payload_sha256 自己検証、および receipt の execution_payload_sha256 との相互検証も行う。不一致は fail-closed で拒否する"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_download_and_verify_artifact_archive"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_download_and_verify_artifact_archive_recomputes_digest_and_extracts_per_ac"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_download_and_verify_artifact_archive_rejects_digest_mismatch"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_artifact_archive_digest_mismatch_when_publish_then_fail_closed_before_post"
      not_controlled:
        - "GitHub 側の upload-artifact digest 算出アルゴリズム自体の検証(本PRはダウンロード済みバイト列の client-side sha256 再計算のみを行う)"
      follow_up:
        - "#1645"
    - claim: "公開する comment body は自由入力を受け付けず、検証済み receipt(PR/Issue/HEAD/artifact/result/per-AC coverage)から決定論的に生成され、生成直後に自己 cross-check される"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_render_test_verdict_body"
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_cross_check_test_verdict_body"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_cross_check_test_verdict_body_detects_mismatch"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_cross_check_test_verdict_body_detects_per_ac_coverage_mismatch"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_render_test_verdict_body_passes_its_own_cross_check"
      not_controlled: []
      follow_up: []
    - claim: "idempotent retry 経路(既存marker1件)でも、既存コメント検証後に PR HEAD / linked Issue body の fresh readback を再度行い、drift を stale として扱い、tracked changes の再確認も行う"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_run_test_verdict_publish の retry 分岐(len(matches) == 1)"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_retry_path_head_drifts_between_readbacks_when_publish_then_stale"
      not_controlled: []
      follow_up: []
    - claim: "入力body(決定論的生成後)に marker literal が既に含まれる場合は POST 前に拒否する。POST後にmarker一覧を再取得し1件以外ならpublished_but_conflictedとして扱う(best-effort検出のみ)"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_run_test_verdict_publish の marker preembed / post-POST recheck ブロック"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_body_already_contains_marker_prefix_when_publish_then_rejected_before_post"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_post_marker_recheck_finds_more_than_one_when_publish_then_conflicted"
      not_controlled:
        - "複数 executor 間の完全な分散 exactly-once(workflow 側の concurrency group 設定等、repo外のCI設定変更)。POST後の再確認は同時実行を検知するのみで防止はしない"
      follow_up:
        - "#1645"
    - claim: "linked Issue が pull_request フィールドを持つ(PRである)場合は fail-closed で拒否し、regular Issue のみを linked Issue として受理する"
      implemented: "yes"
      evidence:
        - "scripts/agent-guards/controlled_skill_mutation_exec.py::_fetch_linked_issue_body_sha256"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_fetch_linked_issue_body_sha256_rejects_pull_request"
        - "scripts/agent-guards/tests/test_test_verdict_publish_exec.py::test_given_linked_issue_is_pull_request_when_publish_then_fail_closed"
      not_controlled: []
      follow_up: []
    - claim: "実 GitHub PR に対する live 動作検証(decision: immediate)は fixture ベースの read-only integration として fake gh でユニットテスト済みであり、実運用の live end-to-end 実行検証は本 PR の scope 外"
      implemented: "no"
      evidence:
        - "Issue #1647 Runtime Verification Applicability セクション(mode: read_only_github_integration、fixture/read-only integration によりユニットテストで決定論的に検証)"
      not_controlled:
        - "実 GitHub API に対する live end-to-end 実行の検証(materializer/adjudicator/Step 2 consumer 側の責務、Out of Scope)"
      follow_up:
        - "#1645"

Notes

@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1827 closed).

@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

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • Linked Issue: #1647(Closes #1647 確認済み)。parent #1645、Child A=#1646 マージ済み。
  • rebase コンフリクト解決確認: #1822 由来の _PR_REVIEW_PUBLISH_ONLY_FLAGS / enforce_issue_pr_match が破壊されず現存することをコード直接確認。
  • AC1-AC4: _validate_test_verdict_publish_fields / _run_test_verdict_publish を直接読解し、target_pr_number/linked_issue_number独立検証、pre/post HEAD readback fail-closed、duplicate marker precheck、genericなissue_comment.publishとのschema非同一性を確認。
  • 実テスト実行: test_test_verdict_publish_exec.py 6 passed、test_controlled_skill_mutation_policy.py 80 passed(回帰なし)、test_controlled_pr_review_publish_exec.py 51 passed(回帰なし)。
  • CI Verification: 全 required CI PASS。
  • Allowed Paths: review_subagent 独立再計算(正しい current base sha使用)で changed files 4件、Allowed Paths 4件と完全一致、violations なし。

Blockers

  • なし

Non-blockers

  • なし

LOOP_VERDICT_V2

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "f4ac8887285851e6658c1e38f3281c8d38efd224"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  allowed_paths_gate:
    status: "ok"
    producer_role: "review_subagent"
    worker_report_used_as_canonical: false
    pr_number: 1827
    changed_files_count: 4
    violations: []
    contract_fingerprint:
      contract_source_kind: "github_issue"
      contract_source_id: "1647"
      contract_body_sha256: "sha256:69e52cdb0a80edded6501fafb94dc3a1b83f8913d30223d7daedda7efa568114"
      base_ref: "main"
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES — merge_ready: false

PR #1827 は現在 open・draft、HEAD は f4ac8887285851e6658c1e38f3281c8d38efd224 です。CI は成功していますが、保護された producer receipt による trust boundary が成立していません。既存レビューは本文上 APPROVE ですが、GitHub 上の review state は COMMENTED で、以下の欠陥を見落としています。

Findings

P0-1: protected producer receipt を検証しておらず、自己申告JSONでPASSを公開できる

親 Issue #1645 の目的は、手書き入力や self-attested JSON だけでは current-head PASS を公開できない trust chain です。Issue #1647 も「Child A の protected receipt だけを受け取る」ことを中核要件としています。

しかし _validate_test_verdict_publish_fields() が receipt について確認するのは、実質的に次の一部分だけです。

  • schema、schema_version
  • 自己申告の pass_eligible: true
  • target PR、HEAD、linked Issue、Issue body SHA
  • artifact ID、任意の非空URL、SHA形式の文字列
  • 呼び出し側自身が計算した receipt SHA

producer、execution_payload_sha256、subject.head_repository_id、contract.command_manifest_sha256 は検証されません。未知フィールドも拒否されず、workflow run、run attempt、job、check run、artifact の live readback もありません。

これは既存の正式な receipt schema と明確に不一致です。同 schema は execution_payload_sha256 と producer を必須とし、producer 内でも workflow path、source ref/SHA、run ID、attempt、job ID、check run ID を要求しています。各objectも additionalProperties: false です。

さらに新規テストの「正常入力」は、必須の producer と execution_payload_sha256 を丸ごと省略し、artifact URL に example.invalid を設定しています。それでも正常として扱われています。CI は実装の正しさではなく、壊れたfixtureとの一致を証明しているだけです。

Child A の producer 自体は、REST artifact ID・repository identity・run identity・HEAD・digest・downloaded payload SHAまで確認して receipt を組み立てています。この保証を Child B がすべて捨てています。

GitHub の公式APIでは、artifact IDから digest、expired、workflow run ID、repository ID、head repository ID、head SHAを取得できます。workflow jobも run ID、HEAD、conclusion、check run URLをreadbackできます。これらを検証しない理由はありません。([GitHub Docs]1)

必要な修正

入力として任意の nested receipt を受け取る設計をやめ、少なくとも次を行う必要があります。

  1. schemas/test-verdict-producer-receipt.schema.json を Draft202012Validator で完全検証する。
  2. workflow run、attempt、job、check run、artifact をGitHub APIから再取得する。
  3. artifact archiveをダウンロードし、digestとexecution payloadを再計算する。
  4. downloaded execution record の subject、contract、per-AC coverage、payload SHAとreceiptを照合する。
  5. 入力側が計算した receipt_sha256 は署名でもauthorityでもないため、それ単独を信用しない。

P0-2: コメント本文がreceiptに束縛されておらず、任意の「PASS」本文を投稿できる

本文検証は、非空文字列であることと、どこかに文字列 TEST_VERDICT_MACHINE/v2 が含まれることだけです。その後に本文自身のSHAを確認していますが、これは「入力された文字列が変化していない」ことしか証明しません。

以下はすべて検証されません。

  • repository、Issue番号、PR番号
  • current/reviewed/diff HEAD
  • contract body SHA
  • workflow run ID、attempt、job/check run ID
  • artifact ID、digest、payload
  • result: PASS
  • per-AC coverage
  • receiptとの意味的な一致

Step 2 の既存仕様は、これらのidentity、artifact、command coverageを検証し、不一致や欠落をfail-closedにする契約です。

したがって、現在は次のような本文でも投稿できます。

TEST_VERDICT_MACHINE/v2
result: PASS

さらに、入力本文に生成予定のmarkerをあらかじめ埋め込むと、executorは同じmarkerをもう一度追加してPOSTします。その後、markerが一意でないためpostconditionで失敗しますが、不正コメントは既にGitHub上へ公開済みです。これは「marker mismatchなら公開しない」というAC3を満たしません。markerは本文追加前に検出して拒否する必要があります。

必要な修正

body を自由入力にしないことが最善です。検証済みexecution recordとreceiptからpublisher側が決定論的に本文を生成してください。

自由入力を残す場合は、完全な TEST_VERDICT_MACHINE/v2 schemaとしてparseし、全identity・artifact・result・per-AC fieldをverified receiptとcross-checkする必要があります。


P1-1: idempotent retry経路では、comment readback後のHEAD・Issue再検証がない

既存markerが1件ある経路では、処理順が次のようになっています。

  1. PR HEADとIssue bodyを取得
  2. authenticated loginを取得
  3. 既存commentをreadback
  4. commentを検証
  5. そのまま成功を返す

手順1と手順5の間でPR HEADまたはIssue本文が更新されても、staleなTEST_VERDICTを already_published 成功として返します。

既存の pr_review.publish は、retry時にもfresh review readback後にcurrent HEADを取得し、expected HEADと比較しています。PR本文が「このprecedentを踏襲した」とする主張と実装が一致していません。

retry経路では _check_no_tracked_changes() も呼ばれておらず、fresh publish経路とのpostcondition symmetryも崩れています。

必要なテスト

  • 最初のHEAD取得はexpected、comment readback後の2回目は別SHAとなるfixture。
  • Issue body SHAについても同じdrift fixture。
  • retry経路でもtracked changesを拒否するfixture。

P1-2: marker precheckとPOSTがatomicではなく、並列実行で重複投稿される

現在のidempotencyは次のcheck-then-actです。

  1. marker付きコメントを一覧取得
  2. 0件ならPOST

2つのexecutorが同時に実行されると、両方が0件を観測して両方がPOSTできます。POST後にmarker一覧を再取得して一意性を確認する処理もありません。

GitHub Actionsは、concurrencyを設定しない限り同一workflowの複数runを並列実行できます。したがって、単なる理論上の競合ではありません。([GitHub Docs]2)

必要な修正

  • protected publisherの全呼出しを、PR・HEAD・receipt単位のconcurrency groupで直列化する。
  • ローカル/複数ホストからも実行可能なら、workflow側の直列化を正規経路にする。
  • POST後にもmarker全件を再取得し、1件以外なら published_but_conflicted として扱う。
  • ただしPOST後確認だけでは重複を防げないため、直列化が必須です。

P1-3: target_pr_number == linked_issue_number の仕様・説明・テストが矛盾している

validatorは target_pr_number == issue_number を明示的に拒否します。

一方、PR本文は「両者が同一値でも別fieldとして要求する」と主張しています。新規テストも同値の正常ケースを検証しておらず、CLI Issue番号が1647のまま linked_issue_number だけ42へ変更し、当然発生するbinding mismatchを確認しているだけです。

GitHubではPRもissue番号空間上のissueです。同じrepoで同じ番号なら「別のregular IssueとPR」ではなく、そのPR自身です。([GitHub Docs]3)

したがって、実装側の同値拒否を維持するなら、PR本文とSafety Claim Matrixを修正すべきです。同値を許可する契約なら、validatorを変更し、なぜPR自身をlinked Issueとして認めるのかを明文化する必要があります。


P1-4: linked Issueがregular Issueであることを検証していない

_fetch_linked_issue_body_sha256() は /issues/{number} のbodyをハッシュするだけで、そのresponseに pull_request fieldが存在するかを確認していません。したがって、targetとは別番号の別PRを「linked Issue」として指定できます。

GitHubのissues APIはPRにも使用されるため、endpointが成功しただけではregular Issueである証明になりません。([GitHub Docs]3)

linked Issueが通常Issueでなければならない契約なら、pull_request fieldの存在をPOST前に拒否してください。

テスト不足

最低限、以下のnegative testが必要です。

  • receiptから producer を削除すると拒否
  • execution_payload_sha256 欠落を拒否
  • nested unknown fieldを拒否
  • boolのartifact IDなどJSON Schema不適合型を拒否
  • artifact URL/ID/digestのlive readback不一致を拒否
  • downloaded execution payloadとreceipt subject/contractの不一致を拒否
  • body内のPR、Issue、HEAD、artifact、resultがreceiptと異なる場合を拒否
  • 入力bodyにmarkerが含まれる場合、POST前に拒否
  • retry readback後のHEAD/Issue driftを拒否
  • 2並列publisherでPOSTが1件だけになることを検証
  • linked Issueとして別PRを指定した場合を拒否

JSON Schema draft 2020-12では、required と additionalProperties は実際のvalidation boundaryとして機能します。既存schemaを持ちながら独自の部分validatorで迂回する設計は不適切です。([JSON Schema]4)

その他の品質問題

PRは新しいmachine-readable request schemaを導入しています。リポジトリのschema governanceでは、producer/consumer境界を越えるJSONやTEST_VERDICTをschemaと定義していますが、TEST_VERDICT_PUBLISH_INPUT_V1 の独立したschema定義やcatalog登録はありません。PR本文のconsumer inventoryも、policy moduleを直接consumeするguard群を網羅していません。

また、security-sensitiveなexecutor変更に広範なformatting-only churnが混在しています。PR #1825とのrebase conflict後のコードである以上、機能変更と整形を分離し、semantic diffを縮小すべきです。

結論

このPRは、HEAD readback、author readback、remote marker検索など個々の部品は既存precedentを利用しています。しかし、最重要の「receiptがprotected producer由来である」というauthority chainと、「公開本文がreceiptの内容を正確に表す」というsemantic bindingがありません。

現状の実装は、protected receipt publisherではなく、自己申告receiptと自己申告本文をHEAD確認付きで投稿するpublisherです。P0-1とP0-2の解消まではマージ不可です。

GitHub上へのレビューコメント投稿や REQUEST_CHANGES 操作は行っていません。

squne121 and others added 2 commits July 29, 2026 01:23
…back + deterministic body (#1647 fix_delta)

Addresses PR #1827 REQUEST_CHANGES (P0-1/P0-2/P1-1/P1-2/P1-4, Issue #1647
Scope Delta AC5-AC11):

- AC5: producer_receipt is now fully validated against
  schemas/test-verdict-producer-receipt.schema.json with
  jsonschema.Draft202012Validator (required producer / execution_payload_sha256,
  additionalProperties: false). Unknown fields / missing producer /
  missing execution_payload_sha256 are fail-closed.
- AC6: live GitHub Actions readback of the receipt's workflow run / job /
  check run identity (repository, head SHA, run<->job<->check-run linkage)
  before any mutation.
- AC7: the execution-record artifact archive is downloaded and its sha256
  is recomputed against the receipt's artifact_archive_digest; the
  archived record's own payload_sha256 is cross-checked against the
  receipt's execution_payload_sha256, and its per_ac coverage feeds the
  published body.
- AC8: the published comment body is no longer accepted as free-form
  caller input -- it is rendered deterministically from the verified
  receipt (PR/Issue/HEAD/artifact/result/per-AC coverage) and
  self-cross-checked before POST.
- AC9: the idempotent-retry path now performs a second fresh PR HEAD /
  linked Issue body readback (and a tracked-changes recheck) after
  validating the existing comment, to catch drift that occurred during
  that validation window.
- AC10: rejects any rendered body that already embeds the marker literal
  before POST, and re-lists markers after POST -- anything other than
  exactly one match is treated as published_but_conflicted (best-effort
  only; full distributed exactly-once is out of scope, documented in the
  Safety Claim Matrix).
- AC11: _fetch_linked_issue_body_sha256 now rejects endpoints that carry
  a pull_request field (mirrors _fetch_issue_content's
  isPullRequest: has("pull_request") pattern).

scripts/agent-guards/tests/test_test_verdict_publish_exec.py: 24 tests
(was 6), covering schema-validation failures, live-readback failures,
artifact digest mismatch, body/receipt cross-check mismatch, retry-path
HEAD/Issue drift, marker pre-embed rejection, post-POST marker conflict,
and linked-issue-is-a-PR rejection.

Verification:
- uv run --locked pytest scripts/agent-guards/tests/test_test_verdict_publish_exec.py -q -> 24 passed
- uv run --locked pytest scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py -q -> 80 passed
- uv run --locked pytest scripts/agent-guards/tests/test_controlled_pr_review_publish_exec.py -q -> 51 passed
- uv run --locked ruff check (4 files) -> All checks passed
- pnpm policy:check -> All checks passed

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

@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

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • 人間 OWNER の敵対的レビュー(REQUEST_CHANGES、https://github.com/squne121/loop-protocol/pull/1827#issuecomment-5106705482)で指摘された P0×2/P1×4 を、Issue #1647 Scope Delta(AC5-AC11)で契約更新後、fix_delta で修正。
  • AC5: _validate_producer_receipt_schema で jsonschema.Draft202012Validator によるフルスキーマ検証をコード直接確認。
  • AC6/AC7: workflow run/job/check run/artifactのGitHub API live readback、artifact archiveの実ダウンロード・digest再計算・内部execution recordの自己整合性確認を実装、実際に呼び出されていることを確認。
  • AC8: receiptから決定論的body生成+cross-check、自由入力bodyフィールド廃止を確認。
  • AC9: retry経路でのHEAD/Issue body再fresh readback実装確認。
  • AC10: marker事前埋め込み拒否+POST後marker再確認(published_but_conflicted)実装確認。
  • AC11: linked issueのpull_requestフィールド確認実装確認。
  • テスト実測: 隔離環境で155 tests合計PASS(新規24件含む)。
  • CI Verification: 全 required CI PASS。
  • Allowed Paths: 4変更ファイル、Allowed Paths完全一致。

Blockers

  • なし

Non-blockers

  • なし

LOOP_VERDICT_V2

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "1b00610c2da52e223a133998413ceb15061e2938"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  allowed_paths_gate:
    status: "ok"
    producer_role: "review_subagent"
    worker_report_used_as_canonical: false
    changed_files_count: 4
    violations: []
    contract_fingerprint:
      contract_source_kind: "issue_comment"
      contract_source_id: "5106786451"
      contract_body_sha256: "sha256:adb43021ed2beb4d42d714bbdb4e30a9642a0c90f136f1df9bfe084fd13ffd22"
      base_ref: "main"
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121
squne121 marked this pull request as ready for review July 28, 2026 16:55
@squne121
squne121 merged commit bc703b4 into main Jul 28, 2026
29 checks passed
@squne121
squne121 deleted the worktree-issue-1647-head-bound-test-verdict-publisher branch July 28, 2026 16:56
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.

実装: HEAD-bound TEST_VERDICT publisher transaction を追加する

1 participant