Repository navigation
Open
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
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: codeParent 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 でないか)
- 実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196(CLOSED): branch-only resume lane の追加であり、通常 lane の
_perform()後例外の actions 保持は対象外。 - 実装: post-merge-cleanup の dedicated branch force delete lane を許可する #1403(CLOSED): dedicated branch force delete lane の認可追加であり、例外時の actions 保持は対象外。
- 実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891(OPEN, PR 2911 で対応中, non_closing_authority): 認可経路の拡張であり、Outcome を分離する。実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 AC4(authority/hash 再認可拒否時の途中成功保持)は authority 拒否の failure class で、本 Issue の subprocess / guard 例外とは別。
- dedupe evidence: 検索語
cleanup_exec actions_taken/TimeoutExpired/OSError/GuardDeadlineExceeded/worktree_removepartial /cleanup-exec:partial-successに対し exact owner となる OPEN / CLOSED Issue は無いことを確認済み。dedupe_key の live 検索も 0 件だった。
Source
- dedupe_key:
cleanup-exec:partial-success:post-worktree-remove-exception-actions:v1 - 起点: PR 2911(linked Issue 実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891)の OWNER comment feat: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる (#2891) #2911 (comment)
- OWNER 承認: exact owner が無い場合の再発防止用の新規 Issue 起票は、人間(OWNER)が明示的に承認済み。
In Scope
scripts/agent-ops/cleanup_exec.pyの_perform()呼び出し周りで、worktree remove 成功後のTimeoutExpired/OSError/GuardDeadlineExceeded時に、成功済みworktree_removeをactions_takenに残してstatus: errorを返す。既存 result schemaCLEANUP_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
- rollback framework、新 result schema、新 approval layer、新 reason code の追加
- force-delete 認可条件の緩和(緩めない)
- 実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 の non_closing_authority 認可ロジックの変更
- branch-only lane / discard lane の挙動変更
- PR 2911 / 実装: cleanup_exec の linked Issue 認可を closing relation 非依存の non_closing_authority に対応させる #2891 への変更・コメント
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 lintAllowed Paths
scripts/agent-ops/cleanup_exec.pyscripts/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 を既定とする。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity