Skip to content

feat(guard): add gh_mutation_denied reason_code for gh issue/pr mutation block - #1118

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-1109-gh-mutation-reason-code
Jun 21, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-1109-gh-mutation-reason-code

Conversation

@squne121

@squne121 squne121 commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • REASON_GH_MUTATION = "gh_mutation_denied" を追加し、gh issue/pr mutation block に専用の reason_code を適用する(AC1)
  • gh issue close/comment/edit/reopen/delete/lock/unlock を gh_mutation_denied で block する(AC2)
  • gh pr checkout/edit/comment/merge/update-branch/review を gh_mutation_denied で block する(AC3)
  • gh issue view/list、gh pr view/list/status は readonly allow を維持する(AC4)
  • gh api への blanket allow は追加しない(AC5)
  • Claude/Codex 両テストファイルに同一 allow/deny matrix のテストクラスを追加する(AC6)
  • stderr recovery hint を GitHub mutation 文脈の文言に変更する(AC7)

regression anchor: Issue #107 impl-review-loop 実行ログで、gh issue close が reason_code: unparseable_branch_mutation として block され、GitHub mutation denied の実態が agent に伝わらなかった問題を修正する。

Checks

  • フィルターテスト(-k "gh_readonly or gh_deny or gh_mutation"): 64 件パス
  • 全体テスト: 275 件パス(baseline 235 件から 40 件増加)
  • Allowed Paths 内のみ変更(3 ファイル)
  • Claude/Codex テスト parity 確認済み

Schema Change Applicability

  • decision: not_schema_change
  • reason: JSON 構造・型・契約キーに変更はなく、スキーマ変更には該当しない。ただし reason_code telemetry vocabulary への backward-compatible additive 追加(gh_mutation_denied 新定数)であり、consumer 調査を実施済み。

Schema Consumer Inventory

reason_code telemetry vocabulary の additive 変更(gh_mutation_denied 追加)について consumer を調査済み:

  • scripts/agent-guards/local_main_branch_guard.py: REASON_GH_MUTATION = "gh_mutation_denied" を定義・使用(実装ファイル本体)
  • .claude/hooks/tests/test_local_main_branch_guard.py: TestGhMutationReasonCodeClaude で新 reason_code を明示検証
  • tests/codex/test_local_main_branch_guard.py: TestGhMutationReasonCode で同一 matrix を検証
  • docs/dev/hook-boundaries.md: reason_code 一覧を更新し gh_mutation_denied を追記(本 PR で対応)
  • scripts/check_hook_boundaries.py: SSOT prose 照合(validator 対象外の notes フィールドのため静的チェックなし、docs 更新で代替)

互換性: gh_mutation_denied は新定数の追加のみで既存 reason_code の挙動に影響しない。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
既存 branch mutation 検出が壊れない(gh pr checkout は block 継続) yes none 全体テスト 275 件パス(退行なし)、TestGhMutationReasonCode で gh pr checkout → gh_mutation_denied を検証 n/a
Claude/Codex parity が維持される yes none 両テストファイルに同一クラス・同一テストを追加、275 件全パスで確認 n/a

Notes

変更ファイル:

  • scripts/agent-guards/local_main_branch_guard.py: REASON_GH_MUTATION 定数追加・evaluate() 分岐更新・recovery hint 文言変更
  • .claude/hooks/tests/test_local_main_branch_guard.py: TestGhMutationReasonCodeClaude クラス追加(AC2/AC3/AC4/AC7 テスト)
  • tests/codex/test_local_main_branch_guard.py: TestGhMutationReasonCode クラス追加(AC2/AC3/AC4/AC7 テスト)

Issue #1109 をクローズする(Closes #1109)

@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1118 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.

PR #1118 レビュー結果 (review_subagent)

Allowed Paths Gate

changed files: 3 件すべてが Allowed Paths 内

  • scripts/agent-guards/local_main_branch_guard.py - ok
  • .claude/hooks/tests/test_local_main_branch_guard.py - ok
  • tests/codex/test_local_main_branch_guard.py - ok

contract_source: #1109 (comment)

AC 検証

AC1 (REASON_GH_MUTATION = gh_mutation_denied 追加): scripts/agent-guards/local_main_branch_guard.py +47行目に REASON_GH_MUTATION = gh_mutation_denied 追加確認。covered

AC2 (gh issue close/comment/edit/reopen/delete/lock/unlock が gh_mutation_denied): evaluate() 関数内 is_gh_mutation_command 分岐で REASON_GH_MUTATION 返却に変更確認。両テストクラスで 7 コマンドの parametrize 確認。covered

AC3 (gh pr checkout/edit/comment/merge/update-branch/review が gh_mutation_denied): 同上ロジック。両テストクラスで 6 コマンドの parametrize 確認。covered

AC4 (gh issue view/list、gh pr view/list/status は allow): 両テストクラスに 5 コマンドの readonly allow テスト確認。covered

AC5 (gh api blanket allow なし): diff に gh api allow 追加なし。covered

AC6 (Claude/Codex 両 hook test に同じ allow/deny matrix): not_covered

  • Claude テスト (TestGhMutationReasonCodeClaude) は AC7 recovery hint test test_gh_mutation_recovery_hint_contains_approved を含む
  • Codex テスト (TestGhMutationReasonCode) は recovery hint test を含まない
  • これは parity gap であり AC6「同じ allow/deny matrix」の要件を満たしていない

AC7 (stderr recovery hint が GitHub mutation 用文言): _emit_block_stderr に REASON_GH_MUTATION 分岐追加、approved rtk/skill wrapper および designated issue workflow キーワード含む。covered(Claude テストは parity が取れているが Codex 側に対応テストなし → AC6 gap に内包)

CI 状態

  • build: success
  • lint: success
  • test: success
  • typecheck: success
  • e2e: success
  • actionlint: success
  • check-hook-integrity: success
  • validate-generated-artifact: success
  • deploy-pr: success
  • PR Body Japanese Check: failure (ブロッカー)
  • python-test: レビュー時点で in_progress

既存挙動への影響

branch mutation / compound command detection の変更なし。変更は gh mutation ブランチの reason_code を REASON_UNPARSEABLE から REASON_GH_MUTATION へ置き換えるのみ。test_unlisted_gh_mutations_are_blocked の期待値も両テストで正しく更新済み。

ブロッカー

  1. PR Body Japanese Check CI failure: PR 本文に全 prose block を日本語で記述する要件を満たしていない(project rule per-block 判定)。対応が必要。
  2. AC6 Claude/Codex parity gap: Codex テスト (tests/codex/test_local_main_branch_guard.py) に AC7 recovery hint に対応するテストが欠落。TestGhMutationReasonCode クラスに test_gh_mutation_recovery_hint_contains_approved 相当テストの追加が必要。

LOOP_VERDICT_V2:
verdict: REQUEST_CHANGES
pr_number: 1118
reviewed_head_sha: 1fff9d6
merge_ready: false
required_auto_actions: []
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
all_within_allowed_paths: true
contract_source_kind: issue_comment
contract_source_id: #1109 (comment)
blockers:
- id: B1
kind: ci_failure
description: PR Body Japanese Check が failure。PR 本文の全 prose block に日本語が必要(per-block 判定)
- id: B2
kind: ac_gap
ac: AC6
description: Codex テストに AC7 recovery hint に対応するテストが欠落しており、Claude/Codex parity が不完全
ac_coverage:
AC1: covered
AC2: covered
AC3: covered
AC4: covered
AC5: covered
AC6: not_covered
AC7: covered
notes: 3 changed files すべて Allowed Paths 内。既存 branch mutation / compound 検出ロジックへの影響なし。B1(PR本文日本語化)とB2(Codex recovery hintテスト追加)の2点を修正後に再レビューを要求する。

@squne121

Copy link
Copy Markdown
Owner Author

PR #1101 で issue #1086 は解決済みのため、こちらは superseded としてクローズします。

@squne121 squne121 closed this Jun 21, 2026
@squne121 squne121 reopened this Jun 21, 2026
@squne121

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #1118 は方向性としては妥当です。gh issue/pr の mutation を許可するのではなく、fail-closed のまま reason_code を unparseable_branch_mutation から gh_mutation_denied に分離する設計は、#1089/#1108 系の安全方針と整合しています。PR は現在 open / draft / mergeable true、head は 719e186c...、変更は 3 ファイルです。

ただし、このままマージ可にはできません。主な理由は hook boundary の正本ドキュメントが stale のままで、PR 自身の「telemetry 精度改善」という目的を満たし切っていないためです。


確認結果

Issue #1109 の契約は、gh issue/pr mutation block に専用 reason_code: gh_mutation_denied を追加し、telemetry と recovery hint を正確化することです。AC は gh issue close/comment/edit/reopen/delete/lock/unlock、gh pr checkout/edit/comment/merge/update-branch/review の block、readonly 系の allow、gh api blanket allow なし、Claude/Codex parity、stderr hint 更新を要求しています。

実装差分は契約の中心部分を満たしています。REASON_GH_MUTATION = "gh_mutation_denied" を追加し、is_gh_mutation_command() 分岐の返却 reason を REASON_UNPARSEABLE から REASON_GH_MUTATION に変更し、recovery hint も GitHub mutation 文脈へ変えています。

現在の diff では Claude 側・Codex 側の両方に、issue mutation、PR mutation、readonly allow、定数値、recovery hint のテストが入っています。古い review_subagent コメントは「Codex 側に recovery hint test がない」と指摘していますが、これは旧 head 1fff9d... に対する stale 指摘です。現行 head の Codex test には test_gh_mutation_recovery_hint_contains_approved が存在します。

CI はまだ完全には閉じていません。現行 head では Check Japanese Content、agent-session-manifest、check-hook-integrity、deploy-pages は success ですが、ci は in_progress です。ci 内では build/test/e2e/typecheck/lint/actionlint は success、python-test がまだ in_progress で後続ステップも pending です。


Blocker 1: docs/dev/hook-boundaries.md が新 reason_code と矛盾している

docs/dev/hook-boundaries.md は local_main_branch_guard の reason_code 一覧を正本として記述していますが、現状では readonly_command / branch_safe_maintenance_command / deterministic_checker_command / unparseable_branch_mutation(gh mutation・/tmp wrapper 含む) と書かれたままです。さらに gh mutation コマンド(edit/close/merge 等)と /tmp wrapper / python -c は fail-closed とだけ書いており、gh_mutation_denied を一切説明していません。

これは今回の PR の目的と直接衝突します。実装上は gh issue/pr mutation が REASON_GH_MUTATION を返すようになっているため、SSOT docs が「gh mutation は unparseable_branch_mutation に含まれる」と言い続けるのは telemetry contract drift です。

修正してください。

reason_code 一覧:
- readonly_command
- branch_safe_maintenance_command
- deterministic_checker_command
- gh_mutation_denied
- unparseable_branch_mutation

`gh_mutation_denied`:
  `gh issue/pr` のうち readonly allowlist に含まれない mutation 系コマンドを fail-closed した場合に使用する。

`unparseable_branch_mutation`:
  compound/wrapper/redirection、/tmp wrapper、python -c、parse failure 等に使用する。

Issue #1109 の allowed paths には docs/dev/hook-boundaries.md と scripts/check_hook_boundaries.py が含まれているため、これは scope 外ではありません。


Blocker 2: PR 本文の “not_schema_change” が過小評価

PR 本文は「スキーマ構造・型・契約キーに変更はないので not_schema_change」としています。物理的な JSON schema の形が変わらない、という意味なら理解できます。しかし reason_code は hook telemetry の公開 vocabulary です。新しい enum 値相当の値を追加する以上、schema structure ではなく telemetry vocabulary の additive change として扱うべきです。

最低限、PR 本文を次のように修正してください。

## Schema / Telemetry Change Applicability

- decision: telemetry_vocabulary_change
- compatibility: backward-compatible additive reason_code
- added_value: gh_mutation_denied
- consumers_checked:
  - scripts/agent-guards/local_main_branch_guard.py
  - .claude/hooks/tests/test_local_main_branch_guard.py
  - tests/codex/test_local_main_branch_guard.py
  - docs/dev/hook-boundaries.md
  - scripts/check_hook_boundaries.py
- note: JSON shape / key structure は変更しないが、agent-facing reason_code vocabulary は追加される。

この修正なしだと、将来の agent / checker が gh_mutation_denied を未知値として扱うリスクを PR 本文が隠します。


Blocker 3: Draft + CI incomplete

現行 PR は draft です。さらに ci workflow が in_progress で、python-test も完了していません。

古い PR Body Japanese Check failure は、現行 head では Check Japanese Content success に見えるため、継続 blocker ではなさそうです。
ただし全 CI が完了するまでは merge-ready とは判定できません。


良い点

実装の評価順は妥当です。現在の evaluate() では、read-only、branch-safe maintenance、tmp/python-c fail-closed の後に gh mutation 分岐があり、gh issue/pr mutation は REASON_GH_MUTATION で block されます。

DISPLAY_READONLY_PATTERNS は gh issue view/list と gh pr view/list/status のみを read-only としており、gh api は含めていません。
is_gh_mutation_command() も gh issue/pr かつ readonly allowlist 以外を mutation として扱うため、今回の scope では fail-closed 方針が維持されています。

これは #1108 で懸念されていた「GitHub remote ops を read-only 扱いに巻き戻す」方向ではありません。関連レビューでも、gh issue edit/comment/close や gh pr checkout/merge/update-branch を fail-closed に維持する必要が指摘されています。


WEB調査を踏まえた設計評価

gh 系 mutation を雑に allow しない判断は正しいです。GitHub CLI の仕様上、gh pr create は現在 branch が push 済みでない場合に push 先や fork を尋ねる挙動があり、--head 等で明示しない限り local/remote state に絡みます。([GitHub CLI]1)

gh pr merge も引数なしでは current branch の PR を対象にし、--delete-branch により local / remote branch delete を伴い得ます。(GitHub CLI)

gh issue comment は body 未指定で対話入力になり、--body-file、--delete-last、--edit-last、--editor、--web なども持ちます。単純に comment subcommand 名だけで allow すると、コメント追加だけでなく編集・削除・外部 UI・ファイル読込をまとめて許すことになります。([GitHub CLI]3)

gh api も危険です。GitHub CLI docs では、field を追加すると default method が POST になり、@file による値読込や --input による request body 読込も可能です。issue comment 作成や PATCH の例も公式に示されています。([GitHub CLI]4) ([GitHub CLI]4)

したがって、#1118 は GitHub mutation を許可する修正ではなく、拒否理由を正しくする修正に留めている点で安全側です。この線は維持してください。


追加した方がよい hardening

必須 blocker ではありませんが、AC5 を「diff に gh api allow 追加なし」で済ませるのは弱いです。少なくとも次の regression を追加すると、将来 #1108 型の巻き戻しを検出できます。

@pytest.mark.parametrize("cmd", [
    "gh api repos/squne121/loop-protocol/issues/123/comments -f body=text | head -n 1",
    "gh api repos/squne121/loop-protocol/issues/123 -X PATCH -f title=new | head -n 1",
])
def test_gh_api_is_not_readonly_pipeline(self, tmp_git_repo: Path, cmd: str):
    result = eval_in_local_root(cmd, str(tmp_git_repo))
    assert result["status"] == "block"
    assert result["reason_code"] == REASON_UNPARSEABLE

また、gh issue comment 123 --body text | head -n 1 や gh issue close 123 && git switch main のような compound/pipeline 形が allow されないことも、別テストで固定しておく価値があります。現在の readonly pipeline classifier は first segment が read-only でない場合に reject し、redirection や compound tokens も reject する設計なので、実装方針とは整合します。


GitHub に投げるレビューコメント案

## 判定: REQUEST_CHANGES

現行 head `719e186c9ed59326a62a6b01f578ec8477339356` を確認しました。

旧 review_subagent の AC6 指摘(Codex 側 recovery hint test 欠落)は stale です。現行 diff では Claude/Codex の両方に `test_gh_mutation_recovery_hint_contains_approved` が存在します。

ただし、以下は merge blocker です。

### B1: `docs/dev/hook-boundaries.md` が新 reason_code と矛盾しています

実装は `gh issue/pr` mutation block の reason_code を `gh_mutation_denied` に変更していますが、hook boundary SSOT はまだ

- `unparseable_branch_mutation(gh mutation・/tmp wrapper 含む)`
- `gh mutation コマンド(edit/close/merge 等)と /tmp wrapper / python -c は fail-closed`

という記述のままです。

今回の目的は telemetry 精度改善なので、SSOT が旧 reason_code を正としている状態では完了扱いにできません。

修正要求:

- `reason_code` 一覧に `gh_mutation_denied` を追加する
- `gh mutation` と `/tmp wrapper / python -c / parse failure` を `unparseable_branch_mutation` から分離して説明する
- `scripts/check_hook_boundaries.py` を実行し、未検出なら「validator 対象外だが SSOT prose を更新した」と PR 本文に明記する

### B2: PR 本文の schema 判定が過小評価です

JSON shape は変わらないとしても、`reason_code` vocabulary は増えています。`not_schema_change` ではなく、少なくとも `telemetry_vocabulary_change / backward-compatible additive reason_code` として consumer inventory を更新してください。

### B3: CI / Draft

PR は draft で、現行 head の `ci` はまだ in_progress です。`python-test` 完了まで merge-ready とは判定しません。

上記修正後に再レビューしてください。

この PR は「実装本体」はかなり近いです。止めるべきポイントはロジックではなく、SSOT docs と telemetry vocabulary の契約更新漏れです。

squne121 and others added 5 commits June 21, 2026 23:30
…ion block

Closes #1109

Issue #107 impl-review-loop log で gh issue close が unparseable_branch_mutation として
block され、GitHub mutation denied であることが伝わらなかった問題を修正。

- REASON_GH_MUTATION = "gh_mutation_denied" を追加
- gh issue close/comment/edit/reopen/delete/lock/unlock を gh_mutation_denied で block
- gh pr checkout/edit/comment/merge/update-branch/review を gh_mutation_denied で block
- gh issue view/list、gh pr view/list/status は readonly allow を維持
- recovery hint を GitHub mutation 文脈の文言に変更
- Claude/Codex 両 hook test に gh_mutation_denied matrix を追加
AC6 requires identical allow/deny matrix in both Claude and Codex test files.
Add test_gh_mutation_recovery_hint_contains_approved to TestGhMutationReasonCode
in tests/codex/test_local_main_branch_guard.py to match the Claude test suite.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Fixed closing line: を close する → をクローズする (ratio: 0.097 → 0.233)
@squne121
squne121 force-pushed the worktree-issue-1109-gh-mutation-reason-code branch from e4964fe to eb9eb90 Compare June 21, 2026 14:31
@squne121
squne121 marked this pull request as ready for review June 21, 2026 14:40
@squne121
squne121 merged commit f749960 into main Jun 21, 2026
17 checks passed
@squne121
squne121 deleted the worktree-issue-1109-gh-mutation-reason-code branch June 21, 2026 14:40
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.

feat(guard): gh mutation block に専用 reason_code を追加し telemetry 精度を向上する

1 participant