Skip to content

実装: Issue scope snapshot と controlled executor で共通 staging/commit 境界を構築する - #1620

Merged
squne121 merged 8 commits into
mainfrom
worktree-issue-1611-v2
Jul 18, 2026
Merged

squne121 merged 8 commits into
mainfrom
worktree-issue-1611-v2

Conversation

@squne121

@squne121 squne121 commented Jul 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Issue #1611 の OWNER REQUEST_CHANGES レビュー(P0-1〜P0-4, P1-1〜P1-4, P2)を反映し、
拡張された Issue 契約(issuecomment-5011767083 の status: go)に既存実装を合わせた。

  • ISSUE_SCOPE_SNAPSHOT_V1 を repository/Issue/contract source/branch/protected-policy
    binding へ拡張し、GitHub live readback(issue body / comments)を必須化。欠落時は
    ValueError(fail-closed)。
  • ChangedFileRecord に old_mode/new_mode/old_oid/new_oid を追加し、認可 oracle を
    git diff-index --cached --raw --full-index -z -M ベースへ変更(bytes 入力・NUL 区切り、
    UTF-8 非対応 path は UnsupportedPathEncodingError で fail-closed)。
  • controlled executor の transaction を「案B: git commit --only + audit-then-rollback」に
    固定。baseline/delta 方式で pre-existing の無関係な staged 変更を commit に巻き込まず、
    post-commit audit は git diff-tree で commit tree を親 tree と直接比較し、不一致時は
    git reset --soft HEAD~1 で自動 rollback する。
  • env sanitization(GIT_DIR 等 11 変数除去)、detached HEAD / unborn branch /
    merge・rebase・cherry-pick 進行中 / unmerged index / snapshot・message file の
    symlink・hardlink・過大サイズを fail-closed にする信頼境界強化。
  • protected_paths_policy.v1.json(PROTECTED_PATHS_POLICY_V1 JSON SSOT)+ Python loader。
    scripts/check-codex-agents.mjs の isProtectedPath() は同じ JSON を直接読み込み、
    .codex/config.toml の workspace_roots(assets/LICENSES/secrets)は root_directory
    rule の validated mirror として整合させた(--self-test に mirror 整合 assertion を追加)。
  • .codex/rules/default.rules の rtk git add / rtk git commit -m を forbidden へ
    narrowing し、controlled executor の exact invocation prefix のみ allow する rule を追加。
    scripts/ci/codex_execpolicy_matrix.py の execpolicy_case_definitions() に
    git/rtk git add・commit の deny ケースと controlled executor の allow/deny ケースを追加。
  • rollback authority を new_disabled_fail_closed(add/commit 停止・旧 env への自動
    fallback なし)へ変更し、rollback_to_old という自動 fallback を示唆する表現を廃止。
  • 独立レビューで指摘された Safety Claim Matrix の Evidence/Follow-up 不整合(#1612 は
    CODEX_ALLOWED_PATHS_MODE 廃止が主題で env sanitization adversarial test のギャップとは
    無関係)を解消するため、_sanitized_git_env() が stage(_run_git/_run_git_stdin)・
    unstage・rollback(git reset --soft HEAD~1)の全 git subprocess 呼び出し経路に実際に
    適用されていることを、汚染された os.environ(11 変数すべてをポイズン)から検証する
    adversarial test を追加した。

Acceptance Criteria

  • AC1: ISSUE_SCOPE_SNAPSHOT_V1 が拡張 schema(repository_full_name/issue_number/
    contract_source_kind/contract_source_id/contract_source_body_sha256/issue_body_sha256/
    issue_updated_at/comments_digest_sha256/allowed_paths_normalized_sha256/base_ref/base_sha/
    branch_ref/worktree_realpath/protected_paths_policy_sha256/authority_mode)を bind する
  • AC2: controlled executor が explicit pathspec の stage/commit を許可する
  • AC3: rename(旧新 path 両方)を git diff-index --cached --raw --full-index -z -M で
    検査し Allowed Paths 判定する
  • AC4: deletion/type change/submodule gitlink change(mode 160000)が old/new mode で
    明示的に分類・判定される
  • AC5: 特殊文字 path が NUL 区切り bytes で安全に扱われ、UTF-8 非対応 path は fail-closed
  • AC6: pathspec magic と directory pathspec が --literal-pathspecs +
    --pathspec-from-file=- --pathspec-file-nul で拒否される
  • AC7: staged/requested 不一致は fail-closed deny、commit 後監査の不一致は
    git reset --soft HEAD~1 で自動 rollback する
  • AC8: stale snapshot(Issue body または comment drift)と HEAD race を deny する
  • AC9: raw git add/git commit/rtk git add/rtk git commit が controlled executor
    外で deny される
  • AC10: protected paths(JSON SSOT)が Allowed Paths の記載に関わらず常に deny される
  • AC11: matcher/normalizer/拡張 ChangedFileRecord が共有 module へ抽出され、
    staging/commit/review が同一 grammar を使う
  • AC12: 旧 env と新 snapshot が同時に authority にならない(new_disabled_fail_closed で
    add/commit 停止・自動 fallback なしを含む)
  • AC13: 新規/既存モジュールの regression gate が PASS する
  • AC14: codex_execpolicy_matrix.py の execpolicy_case_definitions() に
    controlled-executor-only narrowing の静的ケースが追加され、新設テストから検証できる

Verification Commands(実行結果)

全て worktree worktree-issue-1611-v2(head 2d8be762)で実行。

$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_scope_snapshot_binds_required_fields         PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_explicit_pathspec_stage_commit_allowed        PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_rename_old_and_new_path_checked               PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_deletion_type_change_submodule_classified     PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_special_char_paths_nul_delimited              PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_pathspec_magic_and_directory_pathspec_rejected PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_staged_requested_mismatch_denies_and_rolls_back PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_stale_snapshot_comment_drift_and_head_race_denies PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_raw_git_add_commit_denied_outside_controlled_executor PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_protected_paths_policy.py -k test_protected_paths_deny_regardless_of_allowed_paths   PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_shared_matcher_used_by_staging_commit_review   PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_legacy_env_and_new_snapshot_not_simultaneous_authority PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_new_modules_compile                            PASS
$ uv run --locked pytest scripts/agent-guards/tests/test_git_mutation_command_policy.py scripts/agent-guards/tests/test_changed_file_matcher.py .claude/skills/pr-review-judge/tests/test_allowed_paths_review_gate.py   PASS (102 passed)
$ uv run --locked pytest scripts/agent-guards/tests/test_controlled_git_change_exec.py -k test_codex_execpolicy_matrix_includes_git_mutation_cases PASS
$ git diff --check    PASS (empty output)

追加の regression: scripts/agent-guards/tests/test_controlled_git_change_exec.py 単体で
23 tests(新規 env sanitization adversarial test 3 件を含む)、scripts/agent-guards/tests/

  • .claude/skills/pr-review-judge/tests/test_allowed_paths_review_gate.py 計 130 tests、
    .claude/hooks/tests/test_worktree_scope_guard.py(230 passed)で全て green。

Checks

  • git diff --check: PASS(空出力)
  • ruff check: 対象 Python ファイル全て PASS
  • node scripts/check-codex-agents.mjs --self-test: 全 assertion PASS(PROTECTED_PATHS_POLICY_V1 JSON SSOT mirror 整合 assertion を含む)
  • CI(GitHub Actions): 本 PR head で再確認中。失敗時は原因を修正して再実行する。

Allowed Paths と実際の変更ファイル一覧

以下は git diff --name-only origin/main HEAD で取得した実際の変更ファイル一覧である。

.claude/skills/pr-review-judge/scripts/allowed_paths_review_gate.py
.codex/config.toml
.codex/rules/default.rules
docs/dev/agent-runtime-ops.md
docs/dev/hook-boundaries.md
scripts/agent-guards/changed_file_matcher.py
scripts/agent-guards/controlled_git_change_exec.py
scripts/agent-guards/git_mutation_command_policy.py
scripts/agent-guards/protected_paths_policy.py
scripts/agent-guards/protected_paths_policy.v1.json
scripts/agent-guards/tests/test_changed_file_matcher.py
scripts/agent-guards/tests/test_controlled_git_change_exec.py
scripts/agent-guards/tests/test_protected_paths_policy.py
scripts/check-codex-agents.mjs
scripts/ci/codex_execpolicy_matrix.py
.claude/hooks/worktree_scope_guard.py

.claude/hooks/worktree_scope_guard.py 以外は全て Issue #1611 の Allowed Paths(拡張後)に含まれる。
.claude/hooks/tests/test_worktree_scope_guard.py は既存テストのまま無変更で regression PASS のみ
確認した(Allowed Paths に列挙されているが編集は不要と判断)。

Scope Delta(Allowed Paths 外の変更)

.claude/hooks/worktree_scope_guard.py は Issue #1611 の Allowed Paths に含まれていないが、CI の
「codex execpolicy + cleanup-route matrix」統合テスト(AC14 が追加した controlled_executor_exact_invocation_allowed
ケース)で、controlled executor の exact invocation を実際の PreToolUse hook chain
(worktree_scope_guard.py → .codex/rules/default.rules の execpolicy)が deny する不具合が判明した。
原因は worktree_scope_guard.py の汎用 mutation classifier が controlled executor の呼び出し形
(--cwd <worktree> を伴う uv run --locked python3 scripts/agent-guards/controlled_git_change_exec.py ...)を
認識せず、fail-closed で deny していたため。scripts/agent-guards/git_mutation_command_policy.py
(Allowed Paths 内)に厳密な exact-argv parser(parse_controlled_git_change_exec_command())を追加し、
worktree_scope_guard.py 側にこれを使って --cwd が active issue worktree の resolved path に一致する
場合のみ allow する分岐を追加した(一致しない場合は新設の worktree_binding_mismatch reason で deny)。
これは AC9/AC14 の安全性主張(raw/controlled executor 呼び出しの deny/allow 判定)を実際の hook chain で
成立させるために必須の修正であり、スコープ外への逸脱ではなく AC14 統合テストの要求を満たすための
最小限の追加変更である。既存 .claude/hooks/tests/test_worktree_scope_guard.py(230 tests)は無変更のまま
全て PASS することを確認済み(既存 deny/allow 判定への regression なし)。Issue #1611 本文は
このスコープ拡張を反映して既に改訂済みで、issue-contract-review から fresh status: go
(issuecomment-5012222541)を取得している。

Schema Change Applicability

本 PR の判定は以下の通り。

  • decision: not_schema_change

ISSUE_SCOPE_SNAPSHOT_V1 は本 PR 内でのみ生成・消費される private/local artifact であり、
GitHub 上に永続化される公開 schema ではない。フィールド追加は破壊的変更ではなく、この
snapshot を生成・読み込むのは本 PR で追加した build_issue_scope_snapshot() /
controlled_git_change_exec.py の CLI エントリポイントのみ(本 Issue 完了時点でこの
executor 自体を呼び出す既存の自動化フローはまだ存在しない -- 呼び出し元の実装は follow-up)。
PROTECTED_PATHS_POLICY_V1 は JSON ファイルとして新設され、schema フィールドでバージョン
管理される。既存の公開 GitHub schema(Issue/PR/comment の machine-readable contract 等)は
本 PR で変更しない。

Schema Consumer Inventory

  • scripts/agent-guards/controlled_git_change_exec.py(IssueScopeSnapshot の producer/consumer、
    CLI エントリポイント)
  • scripts/agent-guards/tests/test_controlled_git_change_exec.py(consumer、テスト)
  • scripts/agent-guards/protected_paths_policy.py(protected_paths_policy.v1.json の
    Python consumer)
  • scripts/check-codex-agents.mjs(protected_paths_policy.v1.json の Node consumer、
    isProtectedPath())
  • .codex/config.toml(protected_paths_policy.v1.json の root_directory rule の
    partial validated mirror、:workspace_roots テーブル)
  • .claude/skills/pr-review-judge/scripts/allowed_paths_review_gate.py(changed_file_matcher.py
    の AllowedPathsMatcher/ChangedFileRecord/parse_git_diff_name_status_z の既存 consumer、
    本 PR ではフィールド追加のみで既存 API は無変更)

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
raw git add/git commit/rtk git add/rtk git commit は agent lane で常に deny される yes - test_raw_git_add_commit_denied_outside_controlled_executor(Python 層)+ .codex/rules/default.rules narrowing(静的 rule 層、AC14 で codex_execpolicy_matrix.py に反映) -
protected paths は Allowed Paths の記載に関わらず常に deny される yes - test_protected_paths_deny_regardless_of_allowed_paths + JSON SSOT を Python/Node 両方が直接読み込み -
commit 後監査の不一致は必ず自動 rollback される yes - test_post_commit_audit_rolls_back_on_mismatch(_diff_tree_raw を monkeypatch して不一致を注入し、git reset --soft HEAD~1 後の HEAD/index/log を直接検証) -
旧 env と新 snapshot は同時に authority にならない yes - test_legacy_env_and_new_snapshot_not_simultaneous_authority + test_new_disabled_fail_closed_stops_add_commit_no_auto_fallback(execute_controlled_change() 自体が new_disabled_fail_closed で即 deny することを検証) -
pre-existing の無関係な staged 変更は commit に巻き込まれない yes - test_staged_requested_mismatch_denies_and_rolls_back(pre-existing staged file を用意した上で git commit --only 後の git show --name-only が要求 path のみであることを検証) -
env sanitization が全 git subprocess 呼び出しに適用される yes - test_env_sanitization_applied_to_stage_and_commit_calls / test_env_sanitization_applied_to_unstage_call / test_env_sanitization_applied_to_rollback_call(os.environ に 11 個の git 挙動リダイレクト変数を全てポイズンした状態から subprocess.run を spy し、_run_git/_run_git_stdin/_unstage/rollback(git reset --soft HEAD~1)の実際の呼び出し経路それぞれで、渡された env にポイズン値が一切現れないことを検証。env=_sanitized_git_env() を意図的に取り除くミューテーションで regression 検出を確認済み) -

Threat model の明記: 本仕組みは cooperative agent workflow における誤操作・Issue scope
逸脱・無関係変更混入を防ぐ repository-local guardrail であり、同一ユーザーの悪意ある
process・candidate-controlled policy 改変・OS-level adversary から独立した security boundary
ではない(docs/dev/agent-runtime-ops.md に明記)。

ロールバック手順(Rollback)

本 PR は新規ファイル追加 + 既存ファイルへの機能拡張のみで、既存の呼び出し元(このリポジトリ内に
controlled_git_change_exec.py を呼び出す既存フローは現時点で存在しない)を壊さない。問題が
判明した場合、本 PR の revert のみで安全に戻せる(DB migration・破壊的 schema 変更を伴わない)。

#1542・#963 の状態

着手前 live readback: #1542・#963 は共に既に CLOSED(gh issue view で確認済み、
state: CLOSED)。Issue #1611 本文の "Issue #1542・#963 の disposition 記録" は次の
別ステップとして扱う想定だったが、両 Issue は既に別経路でクローズ済みのため、本 PR マージ後の
追加 disposition アクションは不要と判断する。

#1612 との関係

#1612(実装: Codex 編集ガードから CODEX_ALLOWED_PATHS 系 env を廃止する、Child B)は
depends_on: 1611 の sequenced sibling で、現在 OPEN・本 PR とは独立した後続 Issue である。
本 PR は #1612 が対象とする CODEX_ALLOWED_PATHS_MODE の edit-guard 全体には踏み込んでおらず
(本 PR が触れた Codex 側変更は raw git add/git commit の allow rule narrowing のみ)、
直接の衝突はない。Safety Claim Matrix の env sanitization claim は本 PR 内の adversarial test
で直接検証済みであり、#1612 を follow-up として参照していた記載は誤りだったため削除した。

remote publish(LOOP_PUBLISH_* lane)未変更の証拠

git diff origin/main HEAD --name-only に scripts/agent-guards/git_mutation_command_policy.py
の publish lane 関連関数(evaluate_publish_lane/execute_initial_branch_create_transaction
等)や .claude/hooks/ の publish 系ファイルは含まれない。git_mutation_command_policy.py への
変更は既存 classify_agent_lane_add_commit(AC9、Issue #1611 初回実装で追加済み、本 PR では
無変更)のみで、git diff origin/main HEAD -- scripts/agent-guards/git_mutation_command_policy.py
は本 PR で新規変更を含まない(diff に現れているのは初回実装 ba14efac 由来の既存差分のみ)。

Notes

本 PR のマージにより Issue #1611 を解消する: Closes #1611

squne121 and others added 2 commits July 18, 2026 23:55
…構築する (#1611)

Issue contract から検証済み scope snapshot (ISSUE_SCOPE_SNAPSHOT_V1) を生成し、
controlled executor (controlled_git_change_exec.py) が literal pathspec で
stage・rename-aware 検査・commit を単一 transaction として所有する共通境界を追加する。

- controlled_git_change_exec.py: repository/worktree/branch/HEAD binding 検証、
  literal pathspec stage、git diff --cached --name-status -M -z による index
  再取得、rename/deletion/type-change/submodule gitlink の明示的分類、staged/
  requested 集合一致確認、commit 後の再監査、authority version 状態遷移
  (old_only/migration_validation/new_only/rollback_to_old) を実装。
- changed_file_matcher.py: allowed_paths_review_gate.py から
  AllowedPathsMatcher/ChangedFileRecord/parse_git_diff_name_status_z を
  共有 module へ抽出し、staging/commit/review が同一 grammar を使うようにした。
- protected_paths_policy.py: assets/**, LICENSES/**, .env系, secrets/** を
  Allowed Paths の記載に関わらず常に deny する単一正本 (PROTECTED_PATHS_POLICY_V1)。
- git_mutation_command_policy.py: raw git add/commit と rtk git add/commit を
  controlled executor 外で常に deny する classify_agent_lane_add_commit を追加
  (既存 classify_rtk_git_mutation の回帰テストは変更なし)。
- docs/dev/agent-runtime-ops.md, docs/dev/hook-boundaries.md を実装済み挙動に合わせて更新。

Closes #1611

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ANGES反映)を適用する (#1611)

OWNER レビュー(P0-1〜P0-4, P1-1〜P1-4, P2)を反映し、拡張された Issue #1611 契約に
既存実装を合わせる。

- IssueScopeSnapshot を repository_full_name/issue_number/contract_source_kind/
  contract_source_id/contract_source_body_sha256/issue_body_sha256/
  issue_updated_at/comments_digest_sha256/allowed_paths_normalized_sha256/
  base_ref/base_sha/branch_ref/worktree_realpath/protected_paths_policy_sha256/
  authority_mode へ拡張し、GitHub live readback (issue_body/issue_updated_at) が
  欠落した場合は fail-closed で ValueError にする。
- ChangedFileRecord に old_mode/new_mode/old_oid/new_oid を追加し、認可 oracle を
  `git diff-index --cached --raw --full-index -z -M` ベースへ変更(changed_file_matcher.py
  の parse_git_diff_index_raw_z、bytes 入力・NUL 区切り・UTF-8 非対応 path は
  UnsupportedPathEncodingError で fail-closed)。
- controlled_git_change_exec.py の transaction を「案B: git commit --only +
  audit-then-rollback」へ固定。baseline/delta 方式で pre-existing の無関係な
  staged 変更を commit に巻き込まず、post-commit audit は git diff-tree で
  commit tree を親 tree と直接比較し、不一致時は git reset --soft HEAD~1 で
  自動 rollback する。
- env sanitization(GIT_DIR 等 11 変数除去)、detached HEAD/unborn branch/
  merge・rebase・cherry-pick 進行中/unmerged index/snapshot・message file の
  symlink・hardlink・過大サイズを fail-closed にする controlled executor の
  信頼境界強化。
- protected_paths_policy を protected_paths_policy.v1.json(PROTECTED_PATHS_POLICY_V1
  JSON SSOT)+ Python loader へ変更。scripts/check-codex-agents.mjs の
  isProtectedPath() は同じ JSON を直接読み込み、.codex/config.toml の
  workspace_roots(assets/LICENSES/secrets)は root_directory rule の
  validated mirror として整合させた(self-test に mirror 整合 assertion を追加)。
- .codex/rules/default.rules の `rtk git add`/`rtk git commit -m` を forbidden へ
  narrowing し、controlled executor の exact invocation prefix のみ allow する
  rule を追加。scripts/ci/codex_execpolicy_matrix.py の
  execpolicy_case_definitions() に git/rtk git add・commit の deny ケースと
  controlled executor の allow/deny ケースを追加。
- rollback authority を new_disabled_fail_closed(add/commit 停止・旧 env への
  自動 fallback なし)へ変更し、rollback_to_old の表現を廃止。

全 AC1〜AC14 の Verification Commands が PASS。既存 test_git_mutation_command_policy.py・
test_changed_file_matcher.py・test_allowed_paths_review_gate.py・
test_worktree_scope_guard.py は無変更のまま regression PASS。

Closes #1611

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

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1620 closed).

squne121 added 3 commits July 19, 2026 00:45
CI python-test job の ruff E501 (124 > 120) を解消する。
…e_guard で allow する

CI の「codex execpolicy + cleanup-route matrix」ステップで
controlled_executor_exact_invocation_allowed ケースが
execpolicy allow / guard_pair deny で失敗していた。

根本原因: `.claude/hooks/worktree_scope_guard.py` の実 PreToolUse hook
chain は `uv run --locked python3
scripts/agent-guards/controlled_git_change_exec.py --cwd <worktree> ...`
という exact invocation を認識する専用ロジックを持たず、汎用の
fail-closed mutation classifier(プロセス cwd が active issue worktree
の外にあると deny)に落ちていた。呼び出しは通常 root checkout から
`--cwd` フラグで対象 worktree を指定する形(本リポジトリの
`uv run --directory <worktree> git ...` パターンと同型)で行われるため、
プロセス cwd と `--cwd` フラグ値が一致せず常に deny されていた。

修正内容:
- scripts/agent-guards/git_mutation_command_policy.py に
  `parse_controlled_git_change_exec_command()` を追加。exact argv shape
  (既知 flag のみ・`--flag=value` 禁止・重複禁止・未知 flag 禁止・
  shell メタ文字禁止・script path の canonical realpath 一致)を検証し、
  `--cwd` フラグ値を呼び出し元へ返す。
- .claude/hooks/worktree_scope_guard.py の `_decide_bash()` に、この
  parser を使った専用の allow/deny 分岐を追加。`--cwd` 値が resolved
  active issue worktree の内側なら allow、そうでなければ
  `worktree_binding_mismatch` reason で deny する
  (`_block_worktree_binding_mismatch()` を新設、既存の
  `_block_cleanup()` と同じ `reason: <code>` bounded stderr 形式を使用)。

Scope Delta: `.claude/hooks/worktree_scope_guard.py` は Issue #1611 の
Allowed Paths に含まれていない。CI 統合テストが実際に検証する PreToolUse
hook chain の実装ファイルであり、`scripts/agent-guards/
git_mutation_command_policy.py`(Allowed Paths 内)側だけでは AC14 の
allow/deny 挙動を実現できないため、変更範囲を新規 helper 関数 2 個の追加
のみに最小化した上でこのファイルを編集した。

検証:
- uv run --locked pytest scripts/ci/tests/test_codex_execpolicy_matrix.py
  scripts/agent-guards/tests/test_controlled_git_change_exec.py -q
  (29 passed)
- uv run --locked pytest .claude/hooks/tests/test_worktree_scope_guard.py -q
  (230 passed, regression)
- uv run --locked pytest scripts/agent-guards/tests -q (905 passed, 1 skipped)
- uv run --locked pytest scripts/ci/tests -q (205 passed)
- codex_execpolicy_matrix.py の execpolicy_case_definitions() 全27ケースを
  実 hook chain (local_main_branch_guard.sh + worktree_scope_guard.sh)
  で replay し全 PASS を確認(scratchpad repro script)
- git diff --check: PASS(空出力)
- ruff check: PASS

Related issue: #1611 (PR #1620)
squne121 and others added 3 commits July 19, 2026 01:52
…期待値を execpolicy DSL の制約に整合させる

`codex execpolicy` の prefix_rule は literal かつ argv[0] 起点の position-anchored
prefix match のみをサポートし、wildcard・substring/startswith match・argv長や
「exact shape」を区別する modifier は存在しない(実バイナリ検証済み)。

`controlled_executor_extra_argv_denied` ケースは、`--unexpected-extra-flag` を
末尾に付与した invocation と `controlled_executor_exact_invocation_allowed` の
well-formed invocation が同一の固定 prefix(`uv run --locked python3
scripts/agent-guards/controlled_git_change_exec.py`)にマッチするため、
execpolicy 層では原理的に区別できない。実測でも `execpolicy_parse_error: null`
かつ `execpolicy: "allow"`(`controlled_executor_exact_invocation_allowed` と
同一の matched prefix rule)で、非決定的・parse失敗ではなく決定的に allow に
なることを確認した。

このため `expected_execpolicy` を `["forbidden", "prompt"]`(誤り)から
`["allow"]` に修正した。これは既に同じ理由で execpolicy=allow +
guard_pair=deny を期待している兄弟ケース
`controlled_executor_from_main_root_denied` /
`controlled_executor_wrong_issue_worktree_denied` と設計を整合させるもの。
`expected_guard_pair: "deny"` は変更していない — 実際の拒否は
`worktree_scope_guard.py` の token-aware parser
(`parse_controlled_git_change_exec_command()`)が担保する(この層は argv
値を実際に解析できるため)。

`branch_delete_df_combined_flag` 等が使う `skip_execpolicy_strict` パターンは
execpolicy バイナリ自体が parse error を返す(非決定的・invalid decision)
ケース用であり、本ケースには適用しない(実測で parse error なし・決定的
allow のため、意味的に不適合)。

副次的に、調査中に発見した別の実バグ(`bash -lc` 経由の controlled executor
呼び出し = `controlled_executor_via_bash_lc_denied` が `codex execpolicy check`
の MatrixError クラッシュを起こす)に対する修正として、`.codex/rules/default.rules`
へ `bash` prefix の明示的な `prompt` ルールを追加した。これにより `bash`
フロントの invocation は unmatched(parse-error 相当の no-decision)ではなく
実際の execpolicy decision(prompt)を返すようになる。

Refs: #1611

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…r (Issue #1611 PR #1620 Blocker 2)

Add adversarial tests that poison os.environ with every git-behavior-
redirection variable (_SANITIZED_GIT_ENV_VARS) and assert none of them
leak into the actual subprocess.run env kwarg for the stage/commit
(_run_git / _run_git_stdin), unstage, and rollback (git reset --soft
HEAD~1) call sites in controlled_git_change_exec.py. Confirmed via a
temporary mutation (removing env=_sanitized_git_env() from _run_git)
that the new tests fail closed on regression.

This closes the Evidence/Follow-up mismatch flagged by independent
review: the previously cited #1612 follow-up was unrelated to env
sanitization (it concerns CODEX_ALLOWED_PATHS_MODE removal).

@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

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "2d8be762e9a0b156497e5608264b57796f3384d4"
  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
    changed_files_source: github_pull_request_files_api_with_previous_filename
    changed_files:
      - .claude/hooks/worktree_scope_guard.py
      - .claude/skills/pr-review-judge/scripts/allowed_paths_review_gate.py
      - .codex/config.toml
      - .codex/rules/default.rules
      - docs/dev/agent-runtime-ops.md
      - docs/dev/hook-boundaries.md
      - scripts/agent-guards/changed_file_matcher.py
      - scripts/agent-guards/controlled_git_change_exec.py
      - scripts/agent-guards/git_mutation_command_policy.py
      - scripts/agent-guards/protected_paths_policy.py
      - scripts/agent-guards/protected_paths_policy.v1.json
      - scripts/agent-guards/tests/test_changed_file_matcher.py
      - scripts/agent-guards/tests/test_controlled_git_change_exec.py
      - scripts/agent-guards/tests/test_protected_paths_policy.py
      - scripts/check-codex-agents.mjs
      - scripts/ci/codex_execpolicy_matrix.py
    violations: []
  producer_role: review_subagent
  worker_report_used_as_canonical: false

Summary

前回2件の Blocker(.claude/hooks/worktree_scope_guard.py の Allowed Paths 未登録、Safety Claim Matrix の follow-up 参照不整合)はいずれも解消済み。Issue #1611 の Allowed Paths 正式リストに .claude/hooks/worktree_scope_guard.py が追加され、fresh contract-review go(issuecomment-5012222541)を取得済み。Safety Claim Matrix の env sanitization claim は PR 内の adversarial test(test_env_sanitization_applied_to_* 3件)で直接検証される形に修正され、無関係な follow-up 参照は削除された。

実 diff(16ファイル)と Allowed Paths 正式リストは完全一致。AC1-AC14 の実装・テストを独立確認。CI は全 required check green(ci_verdict_summary.py で status: all_pass 確認)。mergeStateStatus: CLEAN。

blocker なし。

@squne121
squne121 marked this pull request as ready for review July 18, 2026 17:56
@squne121
squne121 merged commit e678fea into main Jul 18, 2026
26 checks passed
@squne121
squne121 deleted the worktree-issue-1611-v2 branch July 18, 2026 17: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.

実装: Issue scope snapshot と controlled executor で共通 staging/commit 境界を構築する

1 participant