# task-2550+1 plan — .worktrees auto-cleanup policy + worktree_cleanup.py clean replacement

**status**: in-progress
**level**: Lv.4 (control-plane, security/correctness)
**team**: dev5 (마르둑)
**replacement_of**: task-2550 / PR #100 (IMPLEMENTATION_SPEC_INCOMPLETE)
**original_head**: 4067d8c43833155f5ea626255645549602a23bbb

## 목표

PR #100 Gemini fresh review (head 4067d8c4) 6 unresolved findings (HIGH 1 + medium 4 unique + duplicate 1) 의 corrected clean replacement.

- HIGH: `task_id in headRefName` substring 오탐 차단 (task-25 vs task-2550 boundary 본질 결함)
- medium #1: `hash()` 비결정론 → `hashlib.sha256` 결정론
- medium #2: `pgrep -f` argv-only → `lsof +D` AND 게이트 보완
- medium #3: `r.all_safe` dry-run 가시성 상실 → `is_safe_ignoring_apply` helper
- medium #4 (duplicate dedupe): MED-3 와 통합

본 task 는 같은-PR push doctrine 위반 회피 위해 fresh PR 으로 진행. PR #100 보존 (failed original evidence).

## 범위 (expected_files 11)

### code (2)
1. `anu_v2/worktree_cleanup.py` — NEW (PR #100 baseline + HIGH/medium fix 반영)
2. `anu_v2/post_merge_smoke_runner.py` — MODIFIED (cleanup 통합 + MED-3 cleanup_candidates 산정 fix)

### tests (2)
3. `anu_v2/tests/test_worktree_cleanup_2550plus1.py` — NEW (boundary + concurrency + 4 fix 회귀)
4. `anu_v2/tests/test_post_merge_smoke_worktree_2550plus1.py` — NEW (cleanup_candidates dry-run 가시성 + smoke 통합)

### events (3)
5. `memory/events/task-2550+1.dispatch-decision.json` — NEW (authoritative source)
6. `memory/events/task-2550+1.replacement-lineage.json` — NEW (PR #100 lineage + unresolved-to-resolved mapping)
7. `memory/events/task-2550+1.gemini_triage_decision.json` — NEW (6 findings 1:1 triage)

### plans (3)
8-10. `memory/plans/tasks/task-2550+1/{plan,context-notes,checklist}.md`

### report (1)
11. `memory/reports/task-2550+1.md`

## forbidden_paths (회장 §명시 18)

- PR #98~#109 branch 변경 0
- `scripts/ci.sh` / `dashboard/` / `dispatch/__init__.py` / `team_prompts.py` / `.github/workflows/` / `.env*` 변경 0
- 다른 task markers (task-2545~2557 외) 변경 0
- POC 영역 (memory/poc/, tools/poc/, tests/poc/) 변경 0
- main 직접 push 0
- `.worktrees/` 실제 삭제 0 (dry-run only)
- 다른 anu_v2 modules (owner_trigger_*, merge_queue_executor, replacement_pr_runner, auto_gemini_triage, critical_escalation_reporter, gemini_stale_prevention_runner, pr_open_gemini_trigger_prevention, executor_scheduler, idle_pr_diagnoser, polling_policy) 변경 0
- long polling 0 (polling_policy 상수 강제: 5min~15min cooldown × 30min first timeout × 1회 recheck × 종료)
- bot /gemini review 0 / owner PAT live 0 / GH_TOKEN fallback 0

## 18단계 실행 흐름

**Phase A — Bootstrap (3단계)**:
1. cokacdir 시작 + dev5 worktree 환경 확인
2. `.worktrees/task-2550plus1-dev5` 생성 (origin/main bf59e7d2 기준)
3. PR #100 head 4067d8c4 baseline 4 file 추출 (worktree_cleanup, post_merge_smoke_runner + 2 tests)

**Phase B — Implementation (4단계)**:
4. Gemini 6 unresolved triage → `gemini_triage_decision.json`
5. HIGH `_matches_task_id_strict` 두 단 게이트 (regex 경계 + extracted 동등)
6. medium 4 fix (sha256 hash / lsof CWD / cleanup_candidates ignoring apply)
7. boundary test (task-25/2500/250/2550/2550+1) + concurrency test (PYTHONHASHSEED 결정론)

**Phase C — Verification (5단계)**:
8. pytest 전체 회귀 (anu_v2 432 + 신규 31) PASS
9. pyright 0 errors
10. effective diff == 11 expected_files
11. forbidden path 0
12. PR 생성 (BOT identity, base=main)

**Phase D — Finalize (6단계)**:
13. Gemini fresh review (capability runner 자동 호출 — FIRST_MISSING/STALE 시 OWNER_GEMINI_TRIGGER_TOKEN)
14. unresolved 0 어셀션
15. CI 11/11 SUCCESS
16. mergeStateStatus CLEAN
17. BOT squash merge (admin override 0)
18. smoke/reconcile evidence + lifecycle markers (done.acked/merge-done) + 보고서 + **PR #100 original head 4067d8c4 unchanged 어셀션**

## 완료 기준 12건

1. task-2550+1 PR merged
2. mergedBy = `app/jeon-jonghyuk-taskctl-bot`
3. HIGH task_id 부분 일치 제거 (strict 일치 + boundary test PASS)
4. medium 4 반영 (hash 결정론 / pgrep+lsof / cleanup_candidates 산정 / dedupe)
5. effective diff == corrected expected_files (11)
6. forbidden path 0
7. CI all SUCCESS
8. Gemini unresolved 0
9. smoke/reconcile evidence 존재
10. PR #100 original head unchanged (4067d8c4)
11. operational defect STATE_FILE_MISSING 별도 follow-up 분리 명시 (본 task 처리 X)
12. 신규 Critical 7 없음
