Repository navigation
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1395"
goal_ref: "agent の branch publish 操作が hook / approval 境界または remote head drift で止まったとき、手動 remote 更新へ暗黙フォールバックせず deterministic な publish lane 判定または safety stop へ誘導する"
implementation_mode: docs_and_policy_only
change_kind: workflow
preflight_scope: implementation
runtime_verification:
required: true
mode: immediate
evidence_type: hook-policy-testsParent Issue
Parent Goal Ref
- PR fix: preflight repair hint と hook docs を整合させる (#1395) #1399 の実装中、agent の branch publish 操作が hook / approval 境界で完了できず、ユーザーが手動で remote 更新した。
- 手動 remote 更新後に PR head が進み、実装: issue-refinement-loop canonical runtime の hook allowlist を整備する #1395 の verified head と PR branch provenance / Allowed Paths の再同期が必要になった。
- 関連 blocker comment: fix: preflight repair hint と hook docs を整合させる (#1395) #1399 (comment)
Current Validated Scope
- branch publish 失敗時の boundary_layer、reason_code、repair hint、publish lane 判定、safety stop report を扱う。
impl-review-loop/open-pr/ hook docs から、手動 remote 更新へ暗黙フォールバックしない運用を明文化する。- remote head drift、local head mismatch、reviewed head mismatch、mixed head contamination を検出した場合は、自動 force update せず safety stop に倒す。
docs_and_policy_onlyとして reason_code alignment、repair hint alignment、hook policy regression、safety stop report schema を実装する。
Remaining Parent Gaps
- 実装: issue-refinement-loop canonical runtime の hook allowlist を整備する #1395 / PR fix: preflight repair hint と hook docs を整合させる (#1395) #1399 の hook allowlist 実装そのものは既存 PR の範囲で扱う。
- GitHub 権限モデル全体や credential 管理全体は本 Issue では扱わない。
- automatic worker dispatch 実装は 実装: implementation-worker に IMPLEMENTATION_WORKER_REQUEST_V2 mode を追加し PR repair executor として機能させる(#626 child-4) #631 完了後の別スコープとし、本 Issue では追加しない。
Outcome
agent が branch publish で止まった場合、CI pass/fail だけで安全扱いせず、expected_remote_head / current_remote_head / local_head / verified_head / allowed_paths_gate_status を比較して PUBLISH_LANE_DECISION_V1 を出す。条件が揃う場合だけ bounded publish lane を案内し、remote head に unrelated commit が混入した場合や head provenance が不明な場合は PUBLISH_SAFETY_STOP_REPORT_V1 を残して停止する。
In Scope
- publish failure reason を boundary_layer と reason_code に分離し、docs / tests / hook stderr の machine-readable block で一致させる。
impl-review-loopの publish 失敗後手順に、fetch/readback、expected/current/local head comparison、allowed publish lane decision、post-publish readback、safety stop report の順序を明記する。open-prの正本に、PR 作成失敗時の branch publish preflight / failure report の参照先を明記する。- hook policy tests で、raw remote write、unsafe wrapper route、wrong remote、wrong branch、force route、stale remote head、mixed head contamination が block されることを固定する。
- allowed publish lane は remote / branch / expected head / local head / reviewed head が一致する場合にだけ案内する。
- publish 用 repair hint は
push_refspec_requires_active_branchをそのまま流用せず、remote head 照合を要求する reason_code / safe_action / stop_condition を持つ。 - human intervention が必要な場合の監査メモ形式に redacted_command、boundary_layer、reason_code、expected_remote_head、current_remote_head、local_head、required_decision を含める。
Out of Scope
- GitHub credential / OAuth / organization policy の全面変更
- branch force update の自動実行
- PR fix: preflight repair hint と hook docs を整合させる (#1395) #1399 の差分修正
- 実装: agent delegation 実行の監査ログを専用 schema (delegation_audit_v1) で導入する #1381 の delegation audit 実装内容
- 新しい subagent role の追加
- hook policy 全体の大規模リファクタ
Acceptance Criteria
- AC1: publish failure reason は
boundary_layerとreason_codeを分離し、docs / tests / hook stderr の machine-readable block で一致している。 - AC2:
impl-review-loopは publish failure 後に fetch/readback、expected/current/local head comparison、allowed publish lane decision、post-publish readback、safety stop report の順序を明記している。 - AC3: raw remote write、force route、unsafe wrapper、wrong remote、wrong branch は Claude/Codex parity hook tests で block される。
- AC4: allowed publish lane は
remote == origin、active_branch == target_branch、expected_remote_head == current_remote_head、local_head == declared_publish_head、local_head == reviewed_headの全条件が満たされた場合だけallowed_commandを出す。 - AC5: current remote head に unrelated commit が混入した場合は force update も reset も実行せず、
PUBLISH_SAFETY_STOP_REPORT_V1を出す。 - AC6: human intervention audit memo は redacted_command、boundary_layer、reason_code、expected_remote_head、current_remote_head、local_head、verified_head、required_decision を含む。
- AC7:
open-pr側の記述は実在するSKILL.md/open_pr.py正本に揃い、存在しない step file を前提にしない。
Publish Lane Decision Schema
PUBLISH_LANE_DECISION_V1:
status: allow_retry | safety_stop
publish_failure_reason:
boundary_layer:
- claude_pretooluse_exit2
- codex_pretooluse_deny
- codex_permission_request_no_decision
- worktree_scope_guard_denied
- git_remote_rejected
reason_code:
- remote_write_requires_approval
- hook_policy_denied
- permission_request_no_decision
- branch_mismatch
- stale_remote_head
- local_head_mismatch
- mixed_head_contamination
- unsafe_wrapper_route
issue_number: 1402
pr_number: "<number>"
branch: "<branch>"
remote: origin
expected_remote_head: "<sha>"
current_remote_head: "<sha>"
local_head: "<sha>"
verified_head: "<sha>"
declared_publish_head: "<sha>"
allowed_paths_gate_status: ok | fail_closed | indeterminate
allowed_command: null | "rtk git push origin HEAD:refs/heads/<branch>"
postcondition: "remote branch head == local_head"
required_human_decision: []Safety Stop Report Schema
PUBLISH_SAFETY_STOP_REPORT_V1:
status: safety_stop
issue_number: 1402
pr_number: "<number>"
redacted_command: "<command>"
boundary_layer: "<layer>"
reason_code: "<reason>"
expected_remote_head: "<sha>"
current_remote_head: "<sha>"
local_head: "<sha>"
verified_head: "<sha>"
allowed_paths_gate_status: ok | fail_closed | indeterminate
required_decision:
- "PR branch を linked issue 専用 head へ戻す"
- "混入 commit を別 PR / 別 branch へ退避する"Runtime Verification Applicability
runtime_verification_applicability:
decision: immediate
reason: "hook policy / skill workflow の allow/block/reason_code/repair hint はローカルテストと docs grep で即時検証できる"
applicable_acs:
- AC1
- AC2
- AC3
- AC4
- AC5
- AC6
- AC7
execution_environment: "local WSL2 Ubuntu 24.04 / repo hook tests"
skip_conditions:
- "ローカル依存関係が欠落し、hook test harness 自体が起動できない場合"
- "Stop Conditions に該当する GitHub credential policy 変更が必要と判明した場合"
fallback_policy: "publish lane の自動化が権限境界変更または dispatch 実装を要求する場合は停止し、別 Issue に分離する"
artifact_requirements:
- "hook policy test output"
- "skill docs grep output"
- "repair hint assertion"
- "publish lane decision fixture"Verification Commands
# AC1
$ rg -n "publish_failure_reason" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/agent-skill-boundaries.md scripts/agent-guards/hook_repair_hints.py
$ rg -n "boundary_layer" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/agent-skill-boundaries.md scripts/agent-guards/hook_repair_hints.py
$ rg -n "worktree_scope_guard_denied" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md .claude/hooks/worktree_scope_guard.py docs/dev/hook-boundaries.md scripts/agent-guards/hook_repair_hints.py
# AC2
$ rg -n "expected_remote_head" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/workflow.md
$ rg -n "PUBLISH_LANE_DECISION_V1" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/workflow.md
# AC3
$ rg -n "unsafe_wrapper_route" .claude/hooks/worktree_scope_guard.py .claude/hooks/tests/test_worktree_scope_guard.py tests/codex/test_local_main_branch_guard.py scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
$ rg -n "stale_remote_head" .claude/hooks/worktree_scope_guard.py .claude/hooks/tests/test_worktree_scope_guard.py tests/codex/test_local_main_branch_guard.py scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
$ rg -n "mixed_head_contamination" .claude/hooks/worktree_scope_guard.py .claude/hooks/tests/test_worktree_scope_guard.py tests/codex/test_local_main_branch_guard.py scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
# AC4
$ rg -n "declared_publish_head" .claude/hooks/worktree_scope_guard.py .claude/hooks/tests/test_worktree_scope_guard.py tests/codex/test_local_main_branch_guard.py scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
$ rg -n "allowed_command" .claude/hooks/worktree_scope_guard.py .claude/hooks/tests/test_worktree_scope_guard.py tests/codex/test_local_main_branch_guard.py scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
# AC5
$ rg -n "PUBLISH_SAFETY_STOP_REPORT_V1" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/agent-skill-boundaries.md scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
$ rg -n "mixed_head_contamination" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/agent-skill-boundaries.md scripts/agent-guards/git_mutation_command_policy.py scripts/agent-guards/tests/test_git_mutation_command_policy.py
# AC6
$ rg -n "redacted_command" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/agent-skill-boundaries.md scripts/agent-guards/hook_repair_hints.py
$ rg -n "required_decision" .claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md docs/dev/hook-boundaries.md docs/dev/agent-skill-boundaries.md scripts/agent-guards/hook_repair_hints.py
# AC7
# baseline-expect: pass
$ rg -n "open_pr.py" .claude/skills/open-pr/SKILL.md .claude/skills/open-pr/scripts/open_pr.py
# baseline-expect: pass
$ rg -n "E_GH_FAILURE" .claude/skills/open-pr/SKILL.md .claude/skills/open-pr/scripts/open_pr.pyAllowed Paths
.claude/skills/impl-review-loop/SKILL.md.claude/skills/impl-review-loop/steps/preparation.md.claude/skills/impl-review-loop/steps/step-5-feedback-and-termination.md.claude/skills/open-pr/SKILL.md.claude/skills/open-pr/scripts/open_pr.py.claude/hooks/worktree_scope_guard.py.claude/hooks/tests/test_worktree_scope_guard.py.claude/hooks/tests/test_local_main_branch_guard.pytests/codex/test_local_main_branch_guard.pyscripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/git_mutation_command_policy.pyscripts/agent-guards/tests/test_git_mutation_command_policy.pyscripts/agent-guards/hook_repair_hints.pydocs/dev/hook-boundaries.mddocs/dev/agent-skill-boundaries.mddocs/dev/workflow.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- GitHub credential / OAuth / organization policy の変更が必要と判明した場合
- branch force update の自動実行が必要と判明した場合
- actual worker dispatch implementation の追加が必要と判明した場合
rtk本体や外部 executor の仕様変更が必要と判明した場合- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Hook policy
- Agent workflow
Required Design References
.claude/skills/impl-review-loop/SKILL.md.claude/skills/open-pr/SKILL.md.claude/hooks/worktree_scope_guard.pydocs/dev/hook-boundaries.mddocs/dev/agent-skill-boundaries.mdscripts/agent-guards/git_mutation_command_policy.pyscripts/agent-guards/hook_repair_hints.py
Scope Delta
- Derived from PR fix: preflight repair hint と hook docs を整合させる (#1395) #1399 continuation where agent branch publish could not complete without user manual remote update.
- Incorporates Issue 実装: agent publish lane の手動介入依存を解消する #1402 owner review comment: 実装: agent publish lane の手動介入依存を解消する #1402 (comment)
- Narrows outcome from automatic dispatch to
docs_and_policy_onlywhile keeping hook policy regression and deterministic safety stop evidence immediate. - Related blocker comment: fix: preflight repair hint と hook docs を整合させる (#1395) #1399 (comment)
Delivery Rule
- 1 Issue = 1 PR
- 作業前に issue-contract-review で fresh
CONTRACT_REVIEW_RESULT_V1 status: goを取得する。 - human intervention を完全に隠すのではなく、必要時は deterministic な安全停止と監査メモを残す。
Sub-issues
Collapse Sub-issuesSub-issues
Loading 1 sub-issues
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jul 8, 2026
敵対的レビュー結果: REQUEST_CHANGES
GitHub には投稿していません。#1402 自体にはコメントがなく、実質的な根拠は親 Issue #1395、PR #1399、特に PR #1399 の remote head drift コメントにあります。#1402 は「publish が hook / approval 境界で止まった場合に、手動 remote 更新へ流れず、deterministic retry または safety stop に誘導する」Issueですが、現状の契約のままだと false-green になる可能性が高いです。
Blocker 1: Allowed Paths が enforcement 点とずれている
#1402 の AC4 は「許可された publish lane は、対象 branch / remote / expected head が一致する場合にだけ案内される」です。しかし実際の
rtk git push認可はscripts/agent-guards/git_mutation_command_policy.pyが担っており、このファイルは #1402 の Allowed Paths に含まれていません。現行 policy は意図的に狭い exact shape parser で、rtk git add/commit/pushだけを認識し、それ以外を fail-closed にする設計です。現在の push 判定は、禁止 flag、
origin、HEAD:refs/heads/<branch>、branch 名 regex、必要時の current branch 一致だけを見て、最後にrtk_git_push_allowedを返します。remote head readback、expected head、post-push verification、unrelated commit contamination は見ていません。さらに
worktree_scope_guard.pyはclassify_rtk_git_mutation(... require_active_branch_push=True)の結果が allow で、issue worktree 解決と cwd containment が通れば_allow()します。つまり、現時点の実 enforcement は「local branch / refspec lane」までであり、「remote expected-head lane」ではありません。要求修正: #1402 はこのままでは AC4 を実装できません。
scripts/agent-guards/git_mutation_command_policy.pyとscripts/agent-guards/tests/test_git_mutation_command_policy.pyを Allowed Paths に追加するか、#1402 を docs/tests/hints-only Issue に縮退し、remote-head enforcement は follow-up Issue に分割してください。現状の Allowed Paths のまま「expected head が一致する場合にだけ案内」と書くと、実装が伴わない claim になります。Blocker 2: #1399 の事故原因を “permission boundary” に矮小化している
#1402 の parent gap は、単なる
remote_write_requires_approvalではありません。PR #1399 では、intended verified head548a586...に対して current remote head がa8e7e3...に進み、#1395 Allowed Paths 外の #1381 delegation-audit 変更が混入した、というremote_head_scope_contaminationが記録されています。required human decision も「PR branch を #1395 専用 head へ戻す」または「#1381 混入を別 PR / 別 branch へ退避する」でした。その後、current head
a8e7e3...で verification / CI は PASS になっていますが、これは「テストが通った」だけで、「linked issue の Allowed Paths と PR branch provenance が正しい」ことを意味しません。PR #1399 の最終 PR body も current heada8e7e3...で 9/9 PASS とし、changed files は #1395 の 5 files としていますが、前段の contamination report と緊張関係があります。要求修正: safety stop の判定は「CI pass/fail」ではなく、少なくとも次の比較を正本にすべきです。
Remote head readback は
git ls-remoteで remote refs と commit IDs を読むか、GitHub branch API のcommit.shaを読む方式に寄せられます。(Git)Blocker 3: repair hint が危険に単純すぎる
hook_repair_hints.pyはpush_refspec_requires_active_branchの場合、safe action を「active branch と一致する refspec だけを使う」とし、suggested command をrtk git push origin HEAD:refs/heads/<active-branch>、verification command をgit branch --show-currentにしています。これは #1402 の要求より弱いです。branch 名が合っていても、remote branch が別 commit に進んでいる、remote head に unrelated commit が混入している、local head が reviewed head と違う、というケースを防げません。#1402 の事故はまさにこの種の問題です。
要求修正:
push_refspec_requires_active_branchをそのまま publish retry hint に使わないでください。publish 用には別 reason code を切るべきです。Git の通常 push は fast-forward であれば履歴を失いませんが、remote ref の破壊的な上書きには
--forceまたは+refspec が関わります。--force-with-lease=<refname>:<expect>は expected value を使って remote ref を保護できますが、#1402 は branch force update の自動実行を out-of-scope にしているため、自動実行ではなく human decision route としてだけ文書化するのが妥当です。([Git]2)Blocker 4: テスト対象が
local_main_branch_guardに寄りすぎている#1402 は hook policy tests で raw publish route と unsafe wrapper route を block するとしていますが、実 publish lane は local main root ではなく issue worktree 内の
worktree_scope_guard.py経由で allow されます。local_main_branch_guard.py側だけに negative tests を足しても、publish lane の positive/negative 判定は保証できません。Claude Code hooks の公式仕様上、
PreToolUseは exit code 2 で tool call を block し、それ以外の多くの非ゼロは non-blocking error です。したがって unit-level 関数テストだけではなく、hook stdin JSON → stderr / exit behavior まで含む regression が必要です。([Claude Platform Docs]3)要求修正: 少なくとも以下を追加してください。
git merge-base --is-ancestorは ancestry check に使えますし、git rev-list A..Bは B から到達可能で A から到達不能な commit set を列挙できます。mixed commit contamination の検出には、remote head と verified head の ancestry と、rev-listで出る追加 commit の path scope を組み合わせるのが堅いです。([Git]4)Blocker 5:
remote_write_requires_approvalの意味が Codex と Claude で混ざるCodex adapter には
git pushをremote_write_requires_approvalと分類する処理があります。 ただし現行の adapter は remote write をevaluateGuard()内でaction: no_decisionとして返し、PreToolUse では deny、PermissionRequest ではremote_write_requires_approvalだけ no-decision として何も emit しない設計です。つまり #1402 の reason code に
remote_write_requires_approvalだけを置くと、「PreToolUse hook denial」「PermissionRequest no_decision」「Claude hook exit 2 denial」「worktree policy denial」が混同されます。要求修正: reason code は層を分けるべきです。
Blocker 6:
open-prの正本と #1402 Allowed Paths が噛み合っていない#1402 の Allowed Paths には
.claude/skills/open-pr/steps/publish-and-open.mdが入っていますが、この確認では該当ファイルを取得できませんでした。一方、取得できたopen-pr正本はSKILL.mdで、PR 作成はopen_pr.pywrapper に集約されています。open-prはgh pr create --head <branch> --base mainを呼ぶだけで、branch publish 自体の deterministic retry lane は記述していません。失敗時のE_GH_FAILUREも「権限 / ブランチ存在 / remote push 済みを確認」に留まります。要求修正:
open-pr側に publish preflight / failure report を入れるなら、実在するSKILL.mdに入れるべきです。存在しない step file を Allowed Paths に残すと、実装者が無効な path を編集しようとして Stop Conditions に落ちます。Blocker 7:
impl-review-loopは現時点で dispatch 実装を足せない制約を持つimpl-review-loopの Step 5 はrequired_auto_actionsを worker に委譲する routing を書いていますが、child-4 / #631 が open の間は dispatch 実行コードを追加せず docs-only mode に留める、と明記されています。したがって #1402 が「deterministic retry」を本当に自動化するなら、#631 との依存関係を解決するか、今回の outcome を「retry 手順と safety stop report の deterministic documentation + hook test」に限定する必要があります。
要求修正: #1402 の Outcome を次のどちらかに明確化してください。
または:
現状のまま「手動介入依存を解消」と書くと、docs-only 制約と衝突します。
Web 検索に基づく実装品質化提案
安全な publish lane は「read → compare → bounded write → readback」の 4 段にしてください。
Python wrapper を実装する場合は、shell string ではなく argv list +
shell=Falseを使うべきです。Python 公式 docs は、subprocessは暗黙に system shell を呼ばないため shell metacharacters を安全に child process へ渡せるが、shell=Trueを明示した場合は shell injection を避ける quoting 責任がアプリ側に来る、と説明しています。([Python documentation]5)shlexは tokenization / shell quoting の補助には使えますが、Unix shell 向けであり、非 POSIX shell や Windows shell では injection risk が残るため、実行はsubprocess.run([...], shell=False)へ寄せるべきです。([Python documentation]6)gh api -f/-Fは request payload parameter を追加し、通常 POST に切り替わるため、rawgh api -f body=...を read-only と扱ってはいけません。これは #1399 で直した分類 drift と同じ種類の regression surface です。([GitHub CLI]7)具体的な修正案
#1402 の AC をこの形に寄せるのがよいです。
結論
この Issue は方向性は正しいですが、現行のまま実装に入ると「repair hint と grep は増えたが、実 publish lane は expected head を見ていない」という状態になり得ます。最優先の修正は、Allowed Paths を enforcement 点へ広げること、
remote_write_requires_approvalを境界層別に分解すること、そして #1399 の実事故であるremote_head_scope_contaminationを primary test case にすることです。squne121 commentedon Jul 8, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 9, 2026
Contract Review Result
squne121 commentedon Jul 10, 2026
impl-review-loop: 完了 (2026-07-10T12:14:21Z)
4ae91f5388d8d3f4885058c8b79c10241d112d5cfix: agent publish lane safety stop (#1402) (#1410)
squne121 commentedon Jul 10, 2026
post-merge-cleanup: 完了 (2026-07-10T12:21:29Z)
/home/squne/projects/LOOP_PROTOCOL/.claude/worktrees/issue-1402-agent-publish-laneworktree-issue-1402-agent-publish-lanemain/ clean