Skip to content

実装: branch-only cleanup fallback の認可 OID を compare-and-delete で束縛する #1625

Closed as duplicate

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "PR #1528 の branch-only fallback で認可済み branch tip と削除対象 ref を同一 OID に束縛し、TOCTOU と非 ancestry error で force delete へ進まない fail-closed executor にする"
change_kind: code
dedupe_key: "follow-up:squne121/loop-protocol:pr/1528:branch-only-fallback-oid-binding:v1"
origin_skill: impl-review-loop
source_pr: "#1528"

Parent Issue

なし(closed #1403 の PR #1528 review から抽出した単独 follow-up)

Parent Goal Ref

  • Goal: post-merge cleanup の branch-only fallback を、認可した ref だけに限定して安全に完了できるようにする。
  • Desired Destination: cleanup executor が shared mutation lock 内で expected OID を再検査し、compare-and-delete に成功した場合だけ branch-only fallback を完了する。

Current Validated Scope

  • scripts/agent-ops/cleanup_exec.py の branch-only fallback は、認可で得た local branch tip と実際に削除する ref を同一 OID に束縛していない。
  • git branch -d の任意の失敗を fallback 条件にせず、mergedness の構造的な再検査だけを force-delete への条件にする必要がある。
  • 既存 CLEANUP_EXEC_RESULT_V1 の外部キー集合・型は変更せず、normal と fallback の verified payload を同じ固定形に正規化して検証する必要がある。

Remaining Parent Gaps

Background

PR #1528 の OWNER review は、authorization 後に branch ref が更新されると未認可 OID を削除し得る TOCTOU と、git branch -d の non-zero を ancestry failure と混同して -D へ進む問題を示した。決定論的修正として expected OID を destructive call まで渡し、repository mutation lock 内で compare-and-delete を使う。prompt 注記、stderr 文字列だけの分類、または bare force delete は、ref identity と failure class を保証できないため採用しない。

Outcome

更新された cleanup executor と回帰テストにより、branch-only fallback は認可済み expected OID の compare-and-delete に成功した場合だけ branch を削除し、ref 変化・invalid object・非 ancestry failure では branch を残して fail-closed result を返す状態。

In Scope

  • branch-only authorization が返す expected local branch tip OID を destructive path まで保持し、shared repository mutation lock 内で ref / worktree 使用状態を再検査する。
  • git update-ref -d refs/heads/<branch> <expected-oid> 相当の compare-and-delete に成功した場合だけ branch-only fallback を完了する。
  • expected OID の commit object、comparison ref、mergedness を構造的に確認し、mergedness 不成立以外の Git / ref / I/O failure では force delete に進まない。
  • ref 更新 race、invalid object、non-ancestry error、same-invocation refusal を回帰テストで固定し、拒否時の partial actions と branch 残存を検証する。
  • normal cleanup と branch-only fallback の verified payload を固定 key / type に正規化し、既存 result schema の外部互換性を維持する。

Out of Scope

Acceptance Criteria

  • AC1: branch-only fallback は authorization 時の expected branch tip OID を destructive path まで渡し、shared mutation lock 内の compare-and-delete が expected OID と一致した場合だけ branch を削除する。ref が更新された race では branch_tip_changed を返し、更新後の branch を残す。
  • AC2: fallback は expected OID が commit object として有効で、comparison ref に対する mergedness 不成立が構造的に確認された場合だけを扱う。invalid object、ref lock、I/O error、comparison error、その他の non-ancestry failure では force delete を実行しない。
  • AC3: normal cleanup と branch-only fallback は既存 CLEANUP_EXEC_RESULT_V1 の外部キー集合・型を維持し、verified payload の key / type を固定して回帰テストで検証する。
  • AC4: same-invocation fallback の各拒否条件では、actions_taken は既に成功した worktree remove だけを保持し、branch は残り、force-delete subprocess は呼ばれず、既存 reason code を返す。

Runtime Verification Applicability

runtime_verification_applicability:
  decision: immediate
  applicable_acs: [AC1, AC2, AC3, AC4]
  execution_environment: "WSL2 Ubuntu 24.04、uv locked Python、fixture Git repository"
  skip_conditions: "uv、pytest、または git executable を利用できない場合は exit 77 として停止し、PASS を主張しない"
  fallback_policy: "bare git delete、stderr 文字列の推測、または ref identity を検証しない成功は PASS の代替にしない"
  artifact_requirements: "各 targeted pytest の command、exit code、current HEAD、refusal reason または compare-and-delete result を runtime evidence として記録する"

Verification Commands

# AC1
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_compare_and_delete_refuses_tip_change -q

# AC2
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_refuses_invalid_object_and_non_ancestry_errors -q

# AC3
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_preserves_verified_payload_schema -q

# AC4
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_same_invocation_fallback_refusals_preserve_partial_actions_and_branch -q

Allowed Paths

  • scripts/agent-ops/cleanup_exec.py
  • scripts/agent-ops/tests/test_cleanup_exec.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • shared repository mutation lock と expected OID compare-and-delete を同一 destructive boundary で実現できない場合
  • 実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523 と同じ cleanup executor path の並行変更を避ける直列化条件を確定できない場合

Required Skills

  • Python
  • Git ref safety
  • pytest

Required Design References

  • docs/dev/workflow.md
  • docs/dev/agent-skill-boundaries.md
  • docs/dev/github-ops.md
  • .claude/skills/post-merge-cleanup/SKILL.md
  • scripts/agent-ops/cleanup_exec.py

Scope Delta

  • source: PR feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 OWNER review https://github.com/squne121/loop-protocol/pull/1528#issuecomment-5013575386
  • validated_scope_delta: branch-only fallback の authorization OID と destructive delete が原子的に束縛されず、non-ancestry failure が force-delete へ誤って昇格し得る。
  • deterministic_fix: expected OID を shared lock 内の compare-and-delete まで渡し、failure class を構造的に fail-closed 判定する。
  • workaround_comparison: prompt 注記、stderr 文字列の分類、bare force delete は expected ref identity を保証できないため不採用。

Delivery Rule

  • 1 Issue = 1 PR とし、専用 worktree で実装して Draft PR を作成する。
  • 実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523 が scripts/agent-ops/cleanup_exec.py を変更する open scope であるため、実装開始前に対象 path の先行 PR / merge 状態を readback し、同一 path の並行編集をしない。
  • 最終 push 後の current HEAD に対して runtime verification と CI evidence を再生成し、PR 本文を current HEAD に再束縛してからレビューへ渡す。

Notes for Reviewer

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jul 19, 2026
  2. squne121 commented on Jul 19, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-19T01:01:35Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1625
      body_sha256: "sha256:312b5087040c44351fc25e8f896e1e53ac8c3601093eaf13a2db010539e8ab72"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        product_spec_check: {"schema":"product_spec_check/v1","applicability":"applicable","decision":"pass","triggers":{"docs_product_allowed_paths":false,"tasks_md_mentioned":false,"specify_artifact_mentioned":false,"generated_task_mentioned":false,"product_spec_context_present":false,"machine_readable_contract_present":true},"conditions":{"docs_product_requires_spec_evidence":{"status":"pass","evidence":[]},"tasks_md_not_direct_source":{"status":"pass","evidence":[]},"specify_not_canonical":{"status":"pass","evidence":[]},"diff_first_rationale_present":{"status":"pass","evidence":[]},"generated_task_trace_present":{"status":"pass","evidence":[]},"task_dependencies_materialized":{"status":"pass","evidence":[]}},"blocked_reasons":[],"body_sha256":"sha256:312b5087040c44351fc25e8f896e1e53ac8c3601093eaf13a2db010539e8ab72","source_provenance":{"source_type":"github_api","body_file":null}}
        vc_preflight:
          decision: pass
          classifications: [{"ac":"AC1","line":3,"raw_command":"uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_compare_and_delete_refuses_tip_change -q","command_hash":"sha256:497712f5e1cc20ff2bd917caf7c6940962d312956114042ae22b0fc1e36c4148","execution_key_hash":"sha256:6236085a2b278ff3454b01b56355597a06bad29f1aecad65bea612e40bdb331d","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-ops/tests/test_cleanup_exec.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":477,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":"fail","vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":2,"raw":"# baseline-expect: fail"},"strict":null,"repair":null},{"ac":"AC2","line":7,"raw_command":"uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_refuses_invalid_object_and_non_ancestry_errors -q","command_hash":"sha256:ea1f3be365dab8c39a9da32b7c1b0507c3e40b28a604bde809ef8d390b41e2a5","execution_key_hash":"sha256:d3ee3cc5ef9363cb687d7dd41ed57bb23c1e0da4cda03a25ee54c185979bf970","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-ops/tests/test_cleanup_exec.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":194,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":"fail","vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":6,"raw":"# baseline-expect: fail"},"strict":null,"repair":null},{"ac":"AC3","line":11,"raw_command":"uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_preserves_verified_payload_schema -q","command_hash":"sha256:855dfe6c50d95e9c5688126371eee0c8a1eeb5fd0762fe87eee2eb7fa5d106f1","execution_key_hash":"sha256:229f4dd4cf90a041eb7f7694ccefbdb1e0e59f15face811f328d23a6f57f7442","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-ops/tests/test_cleanup_exec.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":204,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":"fail","vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":10,"raw":"# baseline-expect: fail"},"strict":null,"repair":null},{"ac":"AC4","line":15,"raw_command":"uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_same_invocation_fallback_refusals_preserve_partial_actions_and_branch -q","command_hash":"sha256:e693c481c13f6cbecba0f4ff69ad21636cf7713022d0da318052e85b0c140c0b","execution_key_hash":"sha256:7dbf49b56328efd407af02f1faa962ac6f0e186bc3af898ffe5f2a7a6ed5f685","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-ops/tests/test_cleanup_exec.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":224,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":"fail","vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":14,"raw":"# baseline-expect: fail"},"strict":null,"repair":null}]
      source: ensure_contract_snapshot_auto
      expected_contract_fingerprint: {"issue_number":1625,"contract_source_kind":"issue_comment","contract_source_id":"5013606483","contract_body_sha256":"sha256:312b5087040c44351fc25e8f896e1e53ac8c3601093eaf13a2db010539e8ab72","allowed_paths_normalized_sha256":"939bcc234d0e120483a1041889c4746deab7bd632022cdab9d750fd490571500","base_ref":"main","base_sha_at_snapshot":"e6d9842c327491e9120ea9793fd1fcdfc3c32b2e"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions