Skip to content

実装: cleanup_exec の worktree remove 成功後の例外で成功済み actions_taken を保持する #2913

Open

Description

@squne121

Parent Issue

なし(単独改善)

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "cleanup_exec が worktree remove 成功後の subprocess / guard 例外でも、成功済み worktree_remove を actions_taken に保持し fail-closed にする"
change_kind: code

Parent Goal Ref

親 Issue なし。単独改善の目的は上記 goal_ref のとおり。

Current Validated Scope

scripts/agent-ops/cleanup_exec.py の通常 lane(run() が _perform() を呼ぶ経路)と、同一 invocation 再認可経路のうち例外が actions_taken を失う箇所のみ。branch-only lane と discard lane は対象外。

Remaining Parent Gaps

なし。

Outcome

scripts/agent-ops/cleanup_exec.py を修正し、worktree remove 成功後の branch -d 実行中に subprocess.TimeoutExpired / OSError / GuardDeadlineExceeded が送出されても、status: error と actions_taken == ["worktree_remove"] を返す。branch 側の結果は不明のまま扱い、ancestry failure と誤分類せず force delete も実行しない。この挙動を scripts/agent-ops/tests/test_cleanup_exec.py の regression test で固定し、VC の全 pass をもって完了とする。

Runtime Verification Applicability

  • decision: not_applicable
  • reason: fake git fixture を使う pytest で完結し、実 worktree や実 remote の操作を伴わないため

Context

観測された failure class

  • 対象は scripts/agent-ops/cleanup_exec.py。production path は run() の通常 lane である。
  • _perform() は git worktree remove 成功後に actions.append(OP_WORKTREE_REMOVE)(値は worktree_remove)し、続けて git branch -d を _git() 経由で実行する。_git() は subprocess.run(..., timeout=deadline.subprocess_timeout(...)) であり、branch -d 実行中に subprocess.TimeoutExpired / OSError / GuardDeadlineExceeded が送出されても _perform() 内では捕捉されない。
  • 例外は run() の except (GuardDeadlineExceeded, OSError, subprocess.TimeoutExpired) as e: return _result("error", str(e)[:160], verified, [])(PR 2911 の head dbeb05c では 1662-1667 行付近、origin/main の f1104df では 1598-1602 行付近)へ到達し、worktree が削除済みでも actions_taken: [] を返す。これは _perform() の docstring(Blocker 6: 破壊操作後に空の actions を報告してはならない)の意図に反する。
  • 同様に、same-invocation 再認可経路(perform_error が branch_delete_failed のとき)では _default_branch(root, deadline) が try の外にある。また再認可前の verify_branch_only_cleanup_authorization の呼び出しは GuardDeadlineExceeded しか捕捉しておらず、OSError / TimeoutExpired は outer の run() 側ハンドラへ抜け得る。実装時に実コードで確認し、scope を最小に確定すること。
  • 再現 evidence: OWNER が PR 2911 のレビュー中に限定的な故障注入で再現した(feat: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる (#2891) #2911 (comment) の P2 指摘)。origin/main にも同一コードが存在するため、PR 2911 が導入した regression ではない。

既存 Issue との関係(なぜ exact owner でないか)

Source

In Scope

  • scripts/agent-ops/cleanup_exec.py の _perform() 呼び出し周りで、worktree remove 成功後の TimeoutExpired / OSError / GuardDeadlineExceeded 時に、成功済み worktree_remove を actions_taken に残して status: error を返す。既存 result schema CLEANUP_EXEC_RESULT_V1 は維持する。
  • branch 側の結果は不明のまま扱い、branch 操作が成功したと推測しない。
  • 例外を ancestry failure(BRANCH_ONLY_NON_ANCESTRY_FAILURE / SAME_INVOCATION_ANCESTRY_NOT_CONFIRMED)と誤分類して force delete に昇格させない。
  • same-invocation 再認可経路で、再認可前の verify_branch_only_cleanup_authorization / _default_branch が OSError / TimeoutExpired を送出した場合も actions_taken を保持する(実コード確認の上で最小範囲に限る)。
  • 実 failure class を固定する regression test を既存 scripts/agent-ops/tests/test_cleanup_exec.py に追加する(既存の fake git fixture の流儀を踏襲し、TimeoutExpired / OSError / GuardDeadlineExceeded を対象にする)。

Out of Scope

Acceptance Criteria

  • AC1: 通常 lane で worktree remove 成功後の branch -d が TimeoutExpired / OSError / GuardDeadlineExceeded のそれぞれで失敗した場合、status: error かつ actions_taken == ["worktree_remove"] となり、branch は削除済みと推測されず、force delete subprocess が実行されない。
  • AC2: 上記例外が ancestry failure の reason code(BRANCH_ONLY_NON_ANCESTRY_FAILURE / SAME_INVOCATION_ANCESTRY_NOT_CONFIRMED)に誤分類されない。
  • AC3: 再認可経路で OSError / TimeoutExpired が送出された場合も actions_taken == ["worktree_remove"] が保持され、force delete が実行されない。
  • AC4: 既存の成功経路 / refused 経路 / branch_delete_failed 経路(実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 AC4 を含む)の結果が変わらず、既存 test が全件 pass する。
  • AC5: 新 reason code と新 schema key が追加されていない。

Verification Commands

# AC1
$ uv run --locked pytest -q scripts/agent-ops/tests/test_cleanup_exec.py -k post_worktree_remove_exception_keeps_actions
# AC2
$ uv run --locked pytest -q scripts/agent-ops/tests/test_cleanup_exec.py -k post_worktree_remove_exception_not_ancestry_failure
# AC3
$ uv run --locked pytest -q scripts/agent-ops/tests/test_cleanup_exec.py -k reauthorization_exception_keeps_actions
# AC4
$ uv run --locked pytest -q scripts/agent-ops/tests/test_cleanup_exec.py
# AC4
$ uv run --locked pytest -q scripts/agent-ops/tests/test_cleanup_exec_issue_2628_e2e.py
# AC4
$ uv run --locked pytest -q tests/codex/test_cleanup_exec_branch_only.py
# AC5
$ rg -c "^SAME_INVOCATION_ANCESTRY_NOT_CONFIRMED = " scripts/agent-ops/cleanup_exec.py
# AC5
$ pnpm typecheck
# AC5
$ pnpm lint

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 が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 新 reason code・新 schema key の追加が必要と判明した場合

Required Skills

なし

Required Design References

  • docs/dev/agent-skill-boundaries.md
  • docs/dev/workflow.md

Scope Delta(任意)

N/A

Delivery Rule

1 Issue = 1 PR。専用 worktree で作業し、Draft PR を既定とする。

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Oct 4, 2026
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