Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Refs-bound PR の post-merge Task Context binding を、通常経路だけでなく復旧経路(recover)と local-only 経路でも同一の non_closing_authority 検証で成立させ、手動介入を不要にする"
change_kind: workflowParent Issue
none
Parent Goal Ref
- Goal: closing relation を持たない(意図的に Issue を OPEN に保つ)Refs-bound PR でも、post-merge cleanup の復旧経路・local-only 経路が 実装: PR Closes/Refs 選択と post-merge OPEN close gate を整合する #2878 と同じ authority 検証で停止せず進めること。
- Desired Destination: 単独改善(親 Issue なし)。実装: PR Closes/Refs 選択と post-merge OPEN close gate を整合する #2878(merged / completed phase の non-closing binding)の phase 適用範囲を recover / local-only へ広げる follow-up。
Current Validated Scope
.claude/skills/post-merge-cleanup/scripts/task_context_workflow_signal.pyの_fresh_merged_evidence(recover / local-only 共有)から_merged_evidence(..., allow_non_closing=True)を呼ぶ配線tests/task-context/test_post_merge_workflow_signal_adapter.pyの回帰テスト(既存の「recover / local-only は拒否」固定テストを新契約へ更新).claude/skills/post-merge-cleanup/SKILL.md、docs/dev/task-context.md、docs/dev/workflow.mdの「recover / local-only は non-closing binding を受理せず従来どおり停止」記述の更新と、それを固定するtests/test_post_merge_cleanup_boundary.pyの文言 assertion の更新
Remaining Parent Gaps
cleanup_exec.py::_verify_linked_issueの closing relation 非依存認可と orchestrator→worker→executor→CLI の入力経路は 実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 が所有する(本 Issue では扱わない)。- discard lane は別 Outcome。
Background
- main
fc34b8d6be5f6f110aaa7552bd2127fb590054dc時点で、_merged_evidence(..., allow_non_closing=...)は 実装: PR Closes/Refs 選択と post-merge OPEN close gate を整合する #2878 により--phase merged/--phase completedでのみnon_closing_authority(7 key:decision/level/reason_code/repo/issue_number/pr_number/pr_body_sha256)による non-closing binding を許す。 --phase recover/--phase local-onlyは共有ヘルパ_fresh_merged_evidenceを通りallow_non_closingを渡さないため、closing node が空の Refs-bound PR は常にRELATION_ISSUE_MISMATCHで拒否される。通常経路が途中失敗して復旧経路(実装: マージ済み PR に Task Context の claim を遡及付与する復旧経路を追加する #2817)が必要になった Refs-bound PR では、claim の遡及付与も local-only cleanup 許可も得られず手動介入になる。- 再現: closing node が空で本文が
Refs #Nの merged PR の fresh snapshot に有効な top-levelnon_closing_authorityを添えて--phase recover(または--phase local-only)を実行すると拒否される。同じ snapshot は--phase mergedなら bind される。 - 現状の固定:
.claude/skills/post-merge-cleanup/SKILL.mdとtests/task-context/test_post_merge_workflow_signal_adapter.py::test_given_recover_or_local_only_phase_when_non_closing_authority_then_still_rejected、tests/test_post_merge_cleanup_boundary.py::test_given_close_gate_matrix_when_compared_then_workflow_and_post_merge_skill_matchが「recover / local-only は受理しない」を固定している。 - 近接 Issue との差分(dedupe_key:
task-context:recover-local-only:non-closing-authority:v1、2026-10-04 に OPEN / CLOSED 両方を検索し同一 Outcome の owner なしを確認): 実装: PR Closes/Refs 選択と post-merge OPEN close gate を整合する #2878(CLOSED)は merged / completed phase のみ、実装: マージ済み PR に Task Context の claim を遡及付与する復旧経路を追加する #2817(CLOSED)は recover / local-only 経路の新設、実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891(OPEN)はcleanup_exec.pyとscripts/agent-opsの入力経路・認可で Allowed Paths と検証面が別。 - 採用方針: 運用回避(手動で claim 付与)ではなく、adapter の phase 別 binding を決定論的に修正する。7 key の検証ロジックは 実装: PR Closes/Refs 選択と post-merge OPEN close gate を整合する #2878 の
_non_closing_authority_bindsをそのまま再利用し、新しい検証を書かない。
Outcome
task_context_workflow_signal.py の --phase recover / --phase local-only が、#2878 と同一の 7 key authority 検証(decision == nonclosing_required、level が A1 または A2、repo / issue_number / pr_number 一致、pr_body_sha256 一致。live issue_state は再判定しない)を満たす Refs-bound PR を bind し、それ以外は従来の reason code で拒否して書き込み 0 とする状態が、実 CLI subprocess テストの PASS と post-merge-cleanup/SKILL.md / docs/dev/task-context.md / docs/dev/workflow.md の記述更新で確認できる。
Runtime Verification Applicability
decision: immediate
reason: Allowed Paths の .claude/skills/post-merge-cleanup/SKILL.md は docs/dev/extension-surface-runtime-policy.yaml の skill-invocation-procedure-or-contract-change(skill-invocation-runtime-smoke)の hard selector に該当し、default_decision: immediate である。免除条件(runtime 非読込・実行意味不変)は満たさない。経路選択(normal / local-only / stop)の意味は変えないため、#2817 AC11 の既存 read-only smoke fixture を再利用し、変更後の SKILL が実 runtime で引き続き宣言どおりに読まれ経路選択が退行しないことだけを確認する。新しい harness・runner・fixture は追加しない。
applicable_acs: [AC7]
execution_environment: linked worktree 内で claude 実行ファイルと uv が利用可能な現在の Claude Code session から scripts/agent-ops/run_worktree_agent_runtime_smoke.py を --runtime claude --mode structured で起動する。canonical root からは実行しない。output directory は run ごとに未使用の worktree 配下 path とする。smoke は read-only で、Task Context DB・cleanup_exec・adapter・gh・git 変更系を起動しない。
skip_conditions: claude または uv が利用不能、または structured smoke を起動できない環境では exit 77 + stdout 先頭 SKIP: で停止し、AC7 を PASS 扱いしない(docs/dev/runtime-verification-policy.md の SKIP 規約)。
fallback_policy: AC1〜AC6 の unit / subprocess test の PASS は AC7 の代替にしない。runtime を起動できない場合に static な文言確認だけで AC7 を PASS としない。
artifact_requirements: Claude Code version、起動条件、exit code、順序 marker の観測結果を PR 本文に記録する。raw transcript・credential・secret は記録しない。
runtime_assertion_bindings:
- profile: skill-invocation-runtime-smoke
assertion: procedure_steps_executed_in_declared_order
ac: AC7 - profile: skill-invocation-runtime-smoke
assertion: output_contract_schema_fields_present
ac: AC7
In Scope
_fresh_merged_evidenceが_merged_evidence(snapshot, issue_number, pr_number, allow_non_closing=True)を呼ぶよう配線する(recover / local-only の双方)。fresh snapshot(mtime 300 秒以内)と--merge-identityの 40 hex 照合・--explicit-recovery必須・local-only の outcome 許可集合など recover / local-only 固有の規則は順序・結果とも変えない。tests/task-context/test_post_merge_workflow_signal_adapter.pyに回帰テストを追加し、既存の「recover / local-only は拒否」テストを新契約(bind される)へ置き換える。.claude/skills/post-merge-cleanup/SKILL.md、docs/dev/task-context.md、docs/dev/workflow.mdの「recover / local-only は未対応」記述を「merged / completed / recover / local-only で受理」へ更新し、tests/test_post_merge_cleanup_boundary.pyの該当文言 assertion を追従させる。
Out of Scope
- 7 key の再定義・追加・改名、新 reason code、新 schema、signal_kind 集合や既存
disposition/reason_code値の変更 scripts/agent-ops/cleanup_exec.pyと orchestrator→worker→executor→CLI の入力経路(実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891)- Issue の自動 close、close gate の変更、discard lane
- closing node が 1 件以上ある PR の従来規則の変更(別 Issue の node があれば拒否し fall through しない挙動を維持)
Acceptance Criteria
- AC1: closing node が空で有効な
non_closing_authority(decisionnonclosing_required、level A1 / A2 の双方)を持つ merged Refs-bound PR の fresh snapshot で、--phase recover --explicit-recoveryがRELATION_ISSUE_MISMATCHで拒否されず、--phase mergedと同じ証拠で claim の遡及付与(signal_recover)に進む。close authority は付与されない。 - AC2: 同じ snapshot で
--phase local-onlyが(許可 outcome の場合)local_only/LOCAL_ONLY_PERMITTEDを返し、Task Context への書き込みは 0、authorityのcleanup_completed/parent_issue_close/superseded_pr_closeは全て false のままである。 - AC3: 無効な
non_closing_authority(欠落、decision 不一致、level が A1 / A2 以外、repo / issue_number / pr_number 不一致、pr_body_sha256不一致、pullRequest.body欠落・非 string、key 集合の不正)では recover / local-only の双方が従来の reason code(RELATION_ISSUE_MISMATCH等)で拒否し、DB 書き込み 0 である。 - AC4: recover / local-only 固有の規則が不変である。有効な authority があっても、snapshot が 300 秒より古ければ
SNAPSHOT_STALE、--merge-identity不一致ならMERGE_IDENTITY_MISMATCH、--explicit-recovery欠落ならEXPLICIT_RECOVERY_REQUIREDで拒否され、書き込み 0 である。 - AC5: closing node が 1 件以上ある PR の recover / local-only の挙動が従来どおりである(別 Issue の node があれば non-closing 判定へ fall through せず拒否)。
- AC6:
.claude/skills/post-merge-cleanup/SKILL.md、docs/dev/task-context.md、docs/dev/workflow.mdが recover / local-only でも non_closing_authority binding が受理されると記述し、旧記述(recover / local-only は non-closing binding を受理せず従来どおり停止)が残っておらず、tests/test_post_merge_cleanup_boundary.pyの assertion が新記述と一致して PASS する。 - AC7: extension-surface policy が要求する最小の runtime 確認として、既存 read-only smoke(実装: マージ済み PR に Task Context の claim を遡及付与する復旧経路を追加する #2817 AC11 の fixture)が変更後の SKILL で実 Claude Code runtime 上に PASS し、順序 marker が宣言順に観測される(Runtime Verification Applicability 参照)。
- AC8: 既存の品質ゲートが通る。
Verification Commands
# AC1
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_post_merge_workflow_signal_adapter.py::test_given_non_closing_authority_when_recover_phase_then_claims_without_close_authority
# AC2
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_post_merge_workflow_signal_adapter.py::test_given_non_closing_authority_when_local_only_phase_then_permit_with_zero_writes
# AC3
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_post_merge_workflow_signal_adapter.py::test_given_invalid_non_closing_authority_when_recover_or_local_only_then_rejected_with_zero_writes
# AC4
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_post_merge_workflow_signal_adapter.py::test_given_valid_non_closing_authority_when_recover_local_only_rules_violated_then_unchanged_rejection
# AC5
# baseline-expect: fail
$ uv run --locked pytest tests/task-context/test_post_merge_workflow_signal_adapter.py::test_given_closing_node_when_recover_or_local_only_then_legacy_behavior_unchanged
# AC6
# baseline-expect: fail
$ uv run --locked pytest tests/test_post_merge_cleanup_boundary.py::test_given_close_gate_matrix_when_compared_then_workflow_and_post_merge_skill_match
# AC6
$ uv run --locked pytest tests/task-context/test_post_merge_workflow_signal_adapter.py
# AC7
# preflight-scope: runtime_only
$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --runtime claude --mode structured --worktree . --prompt-file tests/task-context/fixtures/post_merge_local_only_runtime_prompt.md --output-dir .claude/artifacts/worktree-agent-runtime-smoke/issue-recover-local-only-non-closing-ac7-run1 --timeout-seconds 600 --max-turns 12 --require-subagent-causal-evidence --require-min-subagents 1 --expect-ordered-marker POST_MERGE_ROUTE_A=normal_dispatch --expect-ordered-marker POST_MERGE_ROUTE_B=local_only --expect-ordered-marker POST_MERGE_ROUTE_C=stop_human_review --expect-marker POST_MERGE_ROUTE_A=normal_dispatch --expect-marker POST_MERGE_ROUTE_B=local_only --expect-marker POST_MERGE_ROUTE_C=stop_human_review
# AC8
$ pnpm typecheck
# AC8
$ pnpm lint
# AC8
$ pnpm test
# AC8
$ pnpm build
# AC8
$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.pyAllowed Paths
- .claude/skills/post-merge-cleanup/scripts/task_context_workflow_signal.py
- .claude/skills/post-merge-cleanup/SKILL.md
- tests/task-context/test_post_merge_workflow_signal_adapter.py
- tests/test_post_merge_cleanup_boundary.py
- docs/dev/task-context.md
- docs/dev/workflow.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 7 key の再定義、新 reason code・新 schema、
cleanup_exec.pyの変更(実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891)、Issue の自動 close、close gate の変更が必要と判明した場合 - 動作検証 AC の VC が SKIP(exit 77)を返した場合(実行環境不可のためエスカレーション)
- fallback 経由でのみ「成功」する場合(FAIL として扱い、実行環境を確認)
Required Skills
なし
Required Design References
- docs/dev/task-context.md
- docs/dev/workflow.md
- docs/dev/runtime-verification-policy.md
- docs/dev/extension-surface-runtime-policy.yaml
- .claude/skills/post-merge-cleanup/SKILL.md
Delivery Rule
1 Issue = 1 PR、専用 worktree、Draft PR 既定。- 実装: PR Closes/Refs 選択と post-merge OPEN close gate を整合する #2878 は完了済みで前提は満たしている。実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 とは Outcome が独立でブロックしない。ただし Allowed Paths は
.claude/skills/post-merge-cleanup/SKILL.md/docs/dev/workflow.md/tests/test_post_merge_cleanup_boundary.pyで重なる(preflight:overlap_requires_comment, C1)。編集箇所(本 Issue は recover / local-only の記述、実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 は cleanup_exec 認可)は異なるが、着手時に fresh な overlap 確認を行い、同一ファイルは直列化して後発側が rebase する。 - 本 PR は Issue の close 判断を変えない。
Activity
feat: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closi…