Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "#1540 の linked issue worktree を、active branch の live-verified origin head へ単一 trusted transaction 内の rtk git merge --ff-only だけで安全に同期できるようにする"
change_kind: workflowParent Issue
なし(#1540 を unblock する単独 follow-up)
Parent Goal Ref
- Goal: 実装: pr_review_only VC の current-head adjudication を修正する #1540 / PR fix: pr_review_only VC の current-head 判定を修正する #1544 の dedicated worktree を、root checkout の default branch を動かさず current remote branch head に同期して実装ループを再開できるようにする。
- Desired Destination: linked issue worktree 内でのみ、live remote 検証済み active branch head への exact fast-forward を、単一の trusted execution boundary が安全に実行する。
Current Validated Scope
scripts/agent-guards/git_mutation_command_policy.pyのclassify_rtk_git_mutationはrtk git add、commit、pushだけを bounded に判定し、mergeは unknown に倒している。- 同ファイルには既に
execute_initial_branch_create_transaction(Issue 実装: publish laneに新規branch初回publish用のatomicなbranch作成laneを追加する #1449 / PR 実装: publish laneに新規branch初回publish用のatomicなbranch作成laneを追加する #1479 OWNER review 由来)という前例パターンが実装されている:classify_rtk_git_mutation自身が、verify(HEAD/branch/origin binding 確認)→ probe(livegit ls-remote --refs --exit-codereadback)→ 実際の remote write → 事後 readback、を単一 trusted execution boundary 内で完結させ、常に元の raw shell command を "deny" として返す(呼び出し元コマンドを別途再実行させない)。merge lane もこの既存パターンに従う必要がある。 .claude/hooks/worktree_scope_guard.pyの_decide_bashは shared policy が返した結果を、active Issue の linked worktree 内に限って反映する。scripts/agent-guards/local_main_branch_guard.pyのevaluateは Codex wrapper からも利用され、local root context で RTK Git mutation を許可しない。.codex/rules/default.rulesは現在rtk git mergeを他の破壊的 git 操作(checkout/rebase/reset/cherry-pick 等)と同じ generic prompt bucket(line 122-130 付近)に分類しており、exact--ff-only形状の専用 allow rule は存在しない。一方rtk git push originは既に専用の prefix allow rule を持つ(initial_branch_create lane 用)。.claude/settings.jsonにはrtk git系コマンドの exact allow エントリはない(Claude 側の許可判断はpermissionDecisionを返す hook 自体が担う。push origin lane も settings.json 変更なしで成立している)。- 実装: pr_review_only VC の current-head adjudication を修正する #1540 の clean linked worktree は PR fix: pr_review_only VC の current-head 判定を修正する #1544 branch の verified remote SHA
885087598eac7453544f08e468bc9b8ff6c29cf4への fast-forward が RTK/guard allowlist 不在で停止している。
Remaining Parent Gaps
- 実装: pr_review_only VC の current-head adjudication を修正する #1540 の VC adjudication 実装、PR fix: pr_review_only VC の current-head 判定を修正する #1544 の conflict resolution、テスト、PR review、merge は本 Issue 完了後に 実装: pr_review_only VC の current-head adjudication を修正する #1540 / PR fix: pr_review_only VC の current-head 判定を修正する #1544 側で再開する。
Background
根本原因は shared RTK Git mutation policy が merge を未認識として fail-closed にすることにある。当初案は「guard が状態を検証してから、別プロセスで元の raw rtk git merge --ff-only を許可する」設計だったが、これは検証した状態と実際に mutation される状態を原子的に結び付けられず、TOCTOU window(検証後に branch/HEAD/tracking ref が変化しうる)を閉じられない。また refs/remotes/origin/<branch> はローカル tracking ref であり、live remote head と一致する保証がない。
リポジトリには既にこの種の問題を解決した前例(execute_initial_branch_create_transaction、Issue #1449 / PR #1479)があり、classify_rtk_git_mutation 自身が verify・live remote probe・実際の mutation・事後 readback を単一 trusted execution boundary 内で完結させ、元の raw shell command は常に deny する構造を採用している。merge lane もこの既存パターンを踏襲し、prompt 注記や raw Git への迂回、root checkout・reset・force push・任意 commit への merge を許可する workaround は採用しない。
さらに、OWNER による敵対的レビュー(PR #1609 https://github.com/squne121/loop-protocol/pull/1609#issuecomment-5011054192)を受け、`classify_rtk_git_mutation` が merge の副作用を持つ設計は、worktree_scope_guard 側の認可(active Issue解決・matching worktree一意・cwd一致・branch番号一致・linked worktree判定)より前に実際の merge を実行してしまう P0 欠陥を含むと判明した。この修正のため、classify_rtk_git_mutation の merge 分岐は副作用なしの pure shape classifier へ変更し、認可判断と transaction 実行の責務を .claude/hooks/worktree_scope_guard.py 側に一本化した。また Codex execpolicy は「先勝ち」ではなく forbidden > prompt > allow の最も厳しい decision を採用するため、rtk git merge --ff-only の allow rule は既存の generic rtk git merge -> prompt に飲み込まれ実質 prompt のままだった。これを解消するため、専用の Codex-allowlist executor script(scripts/agent-ops/verified_ff_merge_exec.py)を新設し、Codex の allow rule はこの exact executor コマンドのみを対象とする。
Outcome
classify_rtk_git_mutation(scripts/agent-guards/git_mutation_command_policy.py)が、linked issue worktree の attached non-default active branch から呼ばれた exact rtk git merge --ff-only <40-hex-target-sha> を認識した場合、副作用のない pure shape classifier として allow(authorization pending)を返す。実際の merge 実行は .claude/hooks/worktree_scope_guard.py が active Issue 解決・matching worktree 一意性・cwd binding・linked worktree 判定を全て認可した後にのみ、既存の execute_initial_branch_create_transaction と同じ単一 trusted execution boundary パターンに従う新規 execute_verified_ff_merge_transaction を呼び出す形で行う。この transaction は以下を全て満たす場合のみ git merge --ff-only <target_sha> を実行する:
- clean worktree/index/submodule であり、進行中の git operation(
MERGE_HEAD、CHERRY_PICK_HEAD、rebase state 等、per-worktreegit rev-parse --git-pathで解決)が存在しない - attached HEAD が active non-default issue branch である
- origin の effective fetch URL(push URL ではない)が canonical repo と一致する
- 対象 remote に対する live
git ls-remote --refs --exit-code origin refs/heads/<active-branch>の結果が target SHA と一致する(absent/mismatch/probe error は fail-closed で deny) - target が local commit object であり、local HEAD が target の ancestor である
- merge 実行直前に branch/HEAD が変化していないことを再確認する(race window を狭める)
merge 実行後は、active branch 不変・HEAD == target_sha・worktree/index clean・operation residue なし(post-merge hook による副作用が発生した場合は成功扱いにしない)を確認する。timeout/transport exception が発生した場合は、spawn前の OSError(execution_not_started)、timeout後に target HEAD・clean・branch不変(transport_error_but_merged_and_verified)、timeout後にold HEAD・clean(transport_error_no_merge_observed)、その他(transport_error_state_ambiguous)の4分類に区別し、いずれの場合も無条件で postcondition readback を行う。SHA は大文字小文字を区別せず lowercase 変換前の raw 入力で shape 検証し、uppercase SHA は shape 不一致として deny する。classify_rtk_git_mutation は常にこの transaction の結果を理由に元の raw rtk git merge 呼び出しを "deny" として返し(reason_code に transaction outcome を格納)、呼び出し元コマンドを別途再実行させない。
.codex/rules/default.rules は、専用の Codex-allowlist executor script scripts/agent-ops/verified_ff_merge_exec.py --target-sha <sha> の exact invocation のみを allow とする。この executor は自身の authorization(active Issue / matching worktree / cwd binding)を独立に行った上で、共有 Python guard の trusted transaction を呼ぶ。generic rtk git merge(--ff-only を伴う/伴わないに関わらず)は既存の generic prompt bucket のままとし、shadowing を避ける。root checkout・reset・force push・他の merge 形状は引き続き拒否される。
In Scope
git_mutation_command_policy.pyにexecute_verified_ff_merge_transactionを追加する(execute_initial_branch_create_transactionと同じ構造: validate → probe(live ls-remote、canonical fetch URL に対して実行)→ head 再確認 →git merge --ff-only実行(argv list,shell=False)→ readback)。classify_rtk_git_mutation(_classify_rtk_git_merge)は exactrtk git merge --ff-only <40-hex-sha>を認識する副作用のない pure shape classifier とし、merge 実行や cwd/branch/remote 検査は一切行わない。.claude/hooks/worktree_scope_guard.pyに、active Issue 解決・matching worktree 一意性・cwd binding・linked worktree(非 root)判定を全て認可した後にのみexecute_verified_ff_merge_transactionを呼び出す専用関数(_decide_rtk_git_merge等)を追加する。transaction には認可済みのexpected_worktree_realpath・Issue 番号・expected branch を渡して再検証する。- target SHA が active non-default issue branch の live remote head(
git ls-remote --refs --exit-code origin refs/heads/<active-branch>against canonical fetch URL)と一致し、current local HEAD が target の ancestor であることを、transaction 内で決定論的に確認する。 - 新規
scripts/agent-ops/verified_ff_merge_exec.py(Codex 専用 executor)を追加する。この executor は独自の authorization(active Issue / matching linked worktree / cwd binding)を行った上でexecute_verified_ff_merge_transactionを呼ぶ。 .codex/rules/default.rulesに、上記 executor の exact invocation のみを allow する専用 rule を追加する。genericrtk git merge(--ff-onlyの有無を問わず)は既存の prompt bucket に残し、shadowing を避ける。- local root/Codex shared guard(
local_main_branch_guard.py系)が root default branch でこの command class を許可しないことを維持する。 - isolated repository + 実際の
git worktree addlinked-worktree fixture + bare origin fixture を使い、以下を回帰テストで固定する: 正常な fast-forward、non-fast-forward、stale/mismatched remote-tracking ref、live remote SHA mismatch、短縮/非hex SHA、uppercase SHA、flag順序変更、追加 option、raw git、他の merge 形状、detached HEAD、default branch、dirty tracked/untracked/submodule、進行中 operation残留(per-worktree git-path 解決)、branch/HEAD の検証後変更、root context、reset、force push、canonical fetch URL と push URL の不一致、timeout/transport exception の4分類、codex execpolicy checkによる executor allow / generic merge prompt の検証、hook-level authorization-ordering(HEAD 不変性)。 - 既存
scripts/agent-guards/tests/test_git_mutation_command_policy.py、.claude/hooks/tests/test_worktree_scope_guard.py、.claude/hooks/tests/test_local_main_branch_guard.py、tests/codex/test_local_main_branch_guard.pyを、新規 command class 追加によるディスパッチ順序・fail-closed fallback の意味論変更に合わせて更新する。 docs/dev/hook-boundaries.mdに trusted transaction の内容、exact allow 条件、Codex allow rule、deny 境界、authorization-ordering の設計原則を記録する。
Out of Scope
- 実装: pr_review_only VC の current-head adjudication を修正する #1540 の VC adjudication、fix: pr_review_only VC の current-head 判定を修正する #1544 のコード・PR本文・conflict resolution・review・merge。
- root checkout または default branch での merge 許可。
- raw
git merge、rtk proxy、shell wrapper、--no-ff、rebase、reset、force push、--ff-onlyを伴わない他の merge 形状の許可。 - remote fetch(live
ls-remotereadback のみで完結し、fetch 自体は行わない)、remote branch update、GitHub branch protection、RTK 本体の一般的な subcommand 許可拡張。 - 既存
execute_initial_branch_create_transaction/ push origin lane 自体の変更。 .claude/settings.jsonの変更(Claude 側の許可判断は hook のpermissionDecisionで完結し、既存 push origin lane も settings.json 変更なしで成立しているため)。
Acceptance Criteria
- AC1: 新規
execute_verified_ff_merge_transactionは、attached non-default active branch・clean worktree/index/submodule・canonical origin fetch URL binding・livegit ls-remoteが target SHA と一致・local HEAD が target の ancestor、を全て満たす場合のみgit merge --ff-only <target_sha>を実行し、成功後に branch 不変・HEAD == target_sha・clean・no operation residue を確認して transaction 成功を返す。 - AC2:
classify_rtk_git_mutationは exactrtk git merge --ff-only <40-hex-sha>を認識すると副作用のない pure shape classifier としてallow(authorization pending)を返し、実際の merge 実行と常時 deny 応答は.claude/hooks/worktree_scope_guard.pyの認可済み transaction 呼び出しでのみ行われる。 - AC3: short/non-hex SHA、uppercase SHA、ローカル tracking ref 不一致、live remote SHA mismatch(absent/probe error 含む)、active branch 不一致、non-fast-forward、flag順序変更、追加 option、raw git、他の merge 形状は transaction 実行前に fail-closed で deny される。
- AC4: worktree scope guard は resolved active Issue の clean linked worktree でのみ、active Issue解決・matching worktree一意・cwd一致・linked worktree判定をすべて認可した後にのみ transaction を呼び、dirty worktree・root context・unresolved/ambiguous worktree・進行中 git operation残留(per-worktree git-path 解決)を deny する。
- AC5: local main/Codex shared guard は root default branch でこの command class を許可せず、reset と force push の既存 deny を維持する。
.codex/rules/default.rulesは専用 executor script の exact invocation のみを allow とし、genericrtk git merge(--ff-onlyの有無を問わず)は shadowing を避けて既存の prompt bucket のままとする。 - AC6: Hook 境界 SSOT(
docs/dev/hook-boundaries.md)に trusted transaction の内容・exact allow 条件・Codex allow rule・deny 境界・authorization-ordering の設計原則が記録され、実装: pr_review_only VC の current-head adjudication を修正する #1540 / PR fix: pr_review_only VC の current-head 判定を修正する #1544 の実装内容を変更しない。
Runtime Verification Applicability
runtime_verification_applicability:
decision: immediate
reason: "実際の git merge 実行、live git ls-remote 呼び出し、post-merge hook 副作用、実 Claude/Codex hook wrapper 経由の subprocess 実行、codex execpolicy check を伴うため、一時 git repository + 実際の git worktree add fixture + bare origin を使った統合テストで正常系・異常系・race 条件・authorization-ordering を決定論的に検証する必要があり、静的 parser テストだけでは検証できない。"
applicable_acs: [AC1, AC2, AC3, AC4, AC5]
execution_environment: "一時ローカル git repository + 実際の git worktree add linked worktree + bare origin remote(`tmp_path` fixture)。ネットワークアクセス・外部サービス・実 GitHub API 呼び出しは不要。codex execpolicy check は codex CLI が存在する場合のみ実行し、存在しない環境では該当テストを SKIP する。"
skip_conditions: "git バイナリ、pytest tmp_path fixture、または codex CLI が実行環境に存在しない場合のみ該当部分を SKIP とし、SKIP は PASS として扱わない。"
fallback_policy: "runtime verification が環境要因で実行不能な場合は human_judgment として停止し、static-only 判定へのフォールバックは行わない。"
artifact_requirements: "pytest 実行ログ(transaction の allow/deny 理由コード、live ls-remote 呼び出し結果、postcondition 検証結果、codex execpolicy check の decision を含む)をテスト assertion メッセージまたは CI ログに残す。"Verification Commands
# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_rtk_ff_only_merge_policy.py::test_transaction_allows_live_verified_ancestor_target
# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_rtk_ff_only_merge_policy.py::test_classify_always_denies_raw_command_after_transaction
# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_rtk_ff_only_merge_policy.py::test_rejects_noncanonical_merge_shapes_and_unverified_targets
# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_rtk_ff_only_merge_policy.py::test_worktree_guard_rejects_dirty_root_and_unresolved_contexts
# AC5
$ uv run --locked pytest scripts/agent-guards/tests/test_rtk_ff_only_merge_policy.py::test_local_main_and_codex_flavors_keep_root_and_destructive_denies
# AC6
$ rg -n "rtk git merge --ff-only" docs/dev/hook-boundaries.mdAllowed Paths
scripts/agent-guards/git_mutation_command_policy.py.claude/hooks/worktree_scope_guard.pyscripts/agent-guards/tests/test_rtk_ff_only_merge_policy.py(新規)scripts/agent-guards/tests/test_git_mutation_command_policy.py(既存、ディスパッチ順序更新).claude/hooks/tests/test_worktree_scope_guard.py(既存、command class 追加に伴う更新).claude/hooks/tests/test_local_main_branch_guard.py(既存、root/Codex deny 維持の回帰確認)tests/codex/test_local_main_branch_guard.py(既存、Codex flavor の回帰確認).codex/rules/default.rules(既存、専用 executor の exact invocation 用 allow rule 追加)docs/dev/hook-boundaries.mdscripts/agent-ops/verified_ff_merge_exec.py(新規、Codex 専用 executor。PR 実装: linked issue worktree の verified fast-forward を RTK guard で許可する #1609 への OWNER 敵対的レビューで P1 blocker 対応として追加)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- active branch の live remote head と full target SHA の同一性、または HEAD ancestry を local guard 内で決定論的に確認できない場合
- clean linked worktree の判定に root checkout、PR fix: pr_review_only VC の current-head 判定を修正する #1544、または 実装: pr_review_only VC の current-head adjudication を修正する #1540 の実装変更が必要になる場合
execute_initial_branch_create_transaction自体の変更が必要になる場合
Required Skills
- Python
- pytest
- Git fast-forward / ref safety / live remote readback
Required Design References
docs/dev/workflow.md#Worktree 配置規約docs/dev/hook-boundaries.mddocs/dev/agent-skill-boundaries.md- Issue 実装: pr_review_only VC の current-head adjudication を修正する #1540
- PR fix: pr_review_only VC の current-head 判定を修正する #1544
- Issue 実装: publish laneに新規branch初回publish用のatomicなbranch作成laneを追加する #1449 / PR 実装: publish laneに新規branch初回publish用のatomicなbranch作成laneを追加する #1479(
execute_initial_branch_create_transaction前例パターン)
Scope Delta(任意)
OWNER レビュー(https://github.com/squne121/loop-protocol/issues/1589#issuecomment-5010752989)を受け、設計を「guard が raw rtk git merge を許可する」方式から「classify_rtk_git_mutation 自身が単一 trusted transaction 内で merge を実行し常に raw command を deny する」既存 execute_initial_branch_create_transaction パターンへ転換した。Allowed Paths に .codex/rules/default.rules と既存4テストファイルを追加し、Runtime Verification Applicability を not_applicable から immediate に変更した。.claude/settings.json は既存 push origin lane と同様に変更不要と判断した。
2回目の Scope Delta(2026-07-19): PR #1609(本 Issue の実装 PR)に対する OWNER の敵対的レビュー(https://github.com/squne121/loop-protocol/pull/1609#issuecomment-5011054192)で、以下の P0/P1/P2 blocker が指摘され修正した。
- P0:
classify_rtk_git_mutationの merge 分岐が merge実行の副作用を持ち、worktree_scope_guardの認可より前に実際の merge を実行していた。副作用なしの pure shape classifier へ変更し、認可判断と transaction 実行の責務をworktree_scope_guard側に一本化した。 - P1: Codex allow rule が既存の generic
rtk git merge -> promptに shadowing され実質 prompt のままだった。専用 executor scriptscripts/agent-ops/verified_ff_merge_exec.py(Allowed Paths に追加)を新設し、Codex の allow rule はこの exact executor コマンドのみを対象とした。 - P1: operation state 検査が
git rev-parse --git-common-dirを使い linked worktree の operation pseudo-ref を誤検出していた。git rev-parse --git-pathベースに修正。 - P1: canonical remote 検証が push URL のみ確認し、live probe は fetch URL(remote名)を使うため不一致ですり抜け可能だった。fetch URL を一意に解決し検証・probe の両方に使うよう統一。
- P1: timeout/transport exception 時に常に DENIED を返し、実際の merge完了の可能性を無視していた。4分類の timeout 判定 + 無条件 readback を追加。
- P2: uppercase SHA を
.lower()してから regex 検査していたため受理してしまっていた。raw 入力に対する shape 検証へ修正。
この Scope Delta により Allowed Paths に scripts/agent-ops/verified_ff_merge_exec.py を追加した。Outcome / In Scope / AC1・AC2・AC5 / Runtime Verification Applicability も上記修正内容を反映するよう更新した。#1540 / PR #1544 側の scope の変更は行っていない。
Scope Collision Preflight
ISSUE_OVERLAP_PREFLIGHT_RESULT_V1 は decision: overlap_requires_comment、policy_class: C1、GitHub search/read-back ともに ok。
- related_issue: 実装: worktree bootstrap を direct Python/no-project-mutation launcher に統一する #1588、実装: workspace モードと Git staging guard の Allowed Paths 契約を整合させる #1542、実装: session_manifest_coordinator.sh 経由の legacy-state diagnostic e2e 可観測性を検証する #1432、実装: update_branch.py を canonical branch-update executor に統一し、入力・race・postcondition を自己検証する #1429、実装: schema-governance.md の Initial Known Schemas を catalog から生成するスクリプト(#131 FU-5) #521、実装: playtest-log の JSON Schema / validator の追加 #420、改善: VC 設計ガイドラインに否定パターン誤マッチ防止チェックを追加 #237、実装: rate limit / API error 由来の停止を StopFailure hook でログ保存し resume playbook を整備する #225、実装: normal Stop による未完了 LOOP_STATE を一度だけ補正する Stop hook safety net を導入する #224、改善: executable bit audit CI guard の適用範囲を .claude/skills 外のスクリプトへ拡張する #213、実装: .claude/skills 配下スクリプトの executable bit を監査し CI guard を追加する #205。
- overlapping_paths:
.claude/hooks/worktree_scope_guard.py、docs/dev/hook-boundaries.md、scripts/agent-guards/git_mutation_command_policy.py。追加された.codex/rules/default.rules・既存4テストファイル・scripts/agent-ops/verified_ff_merge_exec.pyは、現時点で related_issue 側の変更範囲との明示的な重複は確認されていない(実装開始時に再確認する)。 - non_conflict_reason: 実装: workspace モードと Git staging guard の Allowed Paths 契約を整合させる #1542 は add/commit の Allowed Paths mode、実装: update_branch.py を canonical branch-update executor に統一し、入力・race・postcondition を自己検証する #1429 は raw GitHub update-branch mutation、実装: worktree bootstrap を direct Python/no-project-mutation launcher に統一する #1588 は worktree bootstrap launcher を扱う。本 Issue は merge の exact SHA / live-remote検証 / ancestry / clean-worktree admission を追加し、各 Issue の function contract と policy paragraph を置換しない。残る候補は広い scripts/docs/hooks path による一致である。
- edit_intent: shared policy に merge 専用の closed command class(単一 trusted transaction 実行を含む)を追加し、worktree guard の clean linked-worktree gate・Codex execpolicy の専用 allow rule・Hook 境界の専用段落だけを更新する。
- dependency_ordering: 機能的な先行依存はない。実装開始時に各 Open Issue/PR(特に 実装: workspace モードと Git staging guard の Allowed Paths 契約を整合させる #1542)の live head を再取得し、同じ function または同じ Hook 境界段落が変更済みなら C2 として直列化する。
Delivery Rule
- 1 Issue = 1 PR とし、dedicated linked worktree で実装して Draft PR を作成する。
- 実装前に issue-contract-review で fresh
CONTRACT_REVIEW_RESULT_V1 status: goを取得する。 - normal commit / push のみを使用し、force push、guard bypass、hook disable を行わない。
Activity
squne121 commentedon Jul 18, 2026
判定
Issue #1589 は現在オープンで、Issue コメントはありません。実装PRもリポジトリ検索では確認できませんでした。問題意識自体は妥当ですが、現状の契約のまま実装すると「検証済み fast-forward」という安全性主張が実装より強くなります。
重大な指摘
P0 — 検証と merge 実行が分離しており、TOCTOU を閉じていない
Issue は
classify_rtk_git_mutationとworktree_scope_guardで HEAD、branch、cleanliness、tracking SHA、ancestor 関係を確認してから、元のrtk git merge --ff-only <sha>を許可する設計です。しかし現行の
worktree_scope_guardは shared policy がallowを返した後、単に hook を exit 0 にしており、実際のコマンドはその後に別境界で実行されます。その間に別エージェントやプロセスが次を変更できます。refs/remotes/origin/<branch>一方、既存の initial-branch push lane は、この問題を明示的に認識し、probe・write・readback を同一 trusted transaction 内で実施し、呼び出し元の raw command を再実行させない設計です。merge lane だけ旧式の classify-then-allow に戻すのは、リポジトリ内の既存安全基準に反します。
必須修正: raw
rtk git mergeの許可ではなく、例えば次の exact executor を唯一の経路にしてください。executor 内で検証、
git merge --ff-only <sha>、事後検証まで完了させます。rawgit mergeと汎用的なrtk git mergeは引き続き拒否または prompt のままにすべきです。P1 — 「verified」がローカル tracking ref の検証なのか、現在の remote の検証なのか曖昧
Issue は
refs/remotes/origin/<active-branch>との一致を要求しながら、remote fetch を Out of Scope にしています。remote-tracking ref は fetch 等によって更新されるローカルキャッシュであり、現在の GitHub 上の branch head と一致する保証はありません。Git の upstream も常にorigin・同名branchとは限らず、branch.<name>.remoteとbranch.<name>.mergeで構成されます。 (Git)さらに、現行の publish policy はこの違いを認識しており、remote の現況を主張する場合はローカル tracking ref ではなく、live
git ls-remoteだけを信頼済み readback source としています。契約は次のどちらかに固定する必要があります。
git ls-remote --refs --exit-codeを実行し、live SHA と target SHA の一致も要求する。後者でも、live SHA がローカルに存在しない場合は deny すればよいため、fetch 自体を本Issueに含める必要はありません。
P1 — Codex の配布ルールが変更対象外で、実際には prompt が残る
現行の
.codex/rules/default.rulesはrtk git add/commit/pushだけを allow し、rtk git mergeを明示的にpromptに分類しています。Issue #1589 の Allowed Paths にはこのファイルが含まれていません。したがって hook が許可しても、Codex 側で「承認不要の branch 同期」が成立しません。Claude 側も
.claude/settings.jsonに exactrtk git merge許可はありません。PreToolUse hook で明示的に auto-approve する場合はpermissionDecision: "allow"が定義されていますが、deny・ask rules はそれより優先されます。現状の plain exit 0 だけで対象環境すべてが無人実行できることは、契約・テストのどちらでも証明されていません。 ([Claude]2)必須修正: 少なくとも次を Allowed Paths と検証対象に追加してください。
.codex/rules/default.rules.claude/settings.jsoncodex execpolicy checkの実行結果ただし、汎用
rtk git mergeの静的 allow ではなく、exact executor invocation だけを allow するべきです。P1 — RTK はこの操作の安全性境界ではない
RTK は主として外部CLIの出力を圧縮する proxy です。upstream 実装では専用処理のない Git サブコマンドを external-subcommand 経路へ渡すため、
rtk git mergeは実質的に rawgit mergeの passthrough です。RTK 自体が target SHA、branch identity、cleanliness、ancestor 関係を保証するわけではありません。 ([GitHub]3)そのため、検証すべき配布物は RTK の表示結果ではなく、以下です。
rtk --versionP1 — merge の副作用モデルが不足している
--ff-onlyは non-fast-forward を拒否しますが、成功時には branch、index、working tree を更新します。また Git は成功した merge 後にpost-mergehook を実行し、hook directory はcore.hooksPathで差し替え可能です。 ([Git]4)最低限、executor は次を確認すべきです。
MERGE_HEAD、CHERRY_PICK_HEAD、rebase state 等が存在しないHEAD == target_sha、clean を確認するP1 — Runtime Verification を N/A にしてはいけない
これは parser の静的テストだけでは検証できない runtime mutationです。Issue の Runtime Verification を
immediateに変更し、temporary repository と bare origin を使った隔離テストを必須にすべきです。必要なケースは以下です。
post-mergehook がファイルを変更するケースcodex execpolicy checkP2 — #1542 と同一関数を変更するため、C1扱いだけでは弱い
Issue #1542 も
git_mutation_command_policy.pyと既存 classifier tests を変更します。現時点で必ずしも機能衝突しているとは限りませんが、両Issueが同時実装されると merge conflictだけでなく、subcommand dispatch順序や fail-closed fallback の意味論が変わる可能性があります。実装開始時とPR作成直前に #1542 のheadを再取得し、同時進行なら直列化してください。また新規テストファイルだけでなく、既存の以下も更新対象です。
scripts/agent-guards/tests/test_git_mutation_command_policy.py.claude/hooks/tests/test_worktree_scope_guard.py.claude/hooks/tests/test_local_main_branch_guard.pytests/codex/test_local_main_branch_guard.py推奨する契約
GitHubコメント案
Verdict: REQUEST_CHANGES
目的は妥当ですが、現行契約のままでは verified fast-forward を保証できません。
Blockers
TOCTOU
rtk git mergeを別実行として許可します。remote freshness の意味が不明確
refs/remotes/origin/<branch>はローカル tracking ref であり、live remote head ではありません。git ls-remoteによる current remote verification まで行うのかを契約に明記してください。Codex permission scope が不足
.codex/rules/default.rulesはrtk git mergeを prompt に分類しています。Runtime Verification が必要
Required design
rtk git mergeの raw allow ではなく、例えばverified_ff_merge_exec.py --target-sha <sha>を canonical command とし、同executor内で precondition確認、git merge --ff-only <sha>、postcondition確認まで完了させてください。raw
git mergeと汎用rtk git mergeは引き続き deny/prompt とする必要があります。Issue #1589 に契約更新または実装PRが追加された時点で再レビューする監視も設定可能です。
squne121 commentedon Jul 18, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 18, 2026
Contract Review Result
実装: linked issue worktree の verified fast-forward を RTK guard で許可する (#…
fix: PR 1609 review fix_delta -- authorize before merge, fix Codex al…
squne121 commentedon Jul 18, 2026
Contract Review Result
実装: linked issue worktree の origin/main fast-forward 同期を trusted RTK …