# task-2553+9 — BRANCH_COLLISION_SAFE_ACTIVATION_REFINEMENT + task-2553+1 F1-solo 실 PR open 재수행 (회장 최종 GO)

> **Lv**: Lv.4 — 실 GitHub write/PR open. **Executor**: 적합 dev 1회 한정 (ANU 배치안·Codex lint·refine·re-lint 선행 후 dispatch). **TTL**: 2h.
> **상태**: 회장 spec 수신 완료(끝 마커 확인). task-2553+8 = isolated-worktree evidence COMPLETE/PASS + 첫 적용 DEFENSIVE_HOLD_PASS 인정. ANU-Codex loop 자동 수렴, HOLD 시만 회장 보고. md/memory 박제만 금지 — 실행코드+테스트+fixture 필수.
> **선행 의존**: task-2553+8 isolated_worktree_evidence_source.py + goal_activation_controller.py + pre_authorized_activation_runner.py. task-2553+5 deriver/binding + task-2553+4 gate(무수정 anchor). task-2553+1.md(F1-solo).
> **근본원인(정밀 식별)**: live 메인 워크스페이스가 branch `task/task-2553p1-f1-clean-replacement` @20456b5f 에 checkout 됨 + `pre_authorized_activation_runner.py:225` `_run(["git","checkout","-B", new_branch, base_sha], repo)` 가 그 **live-checked-out branch ref 를 reset** → +8 DEFENSIVE_HOLD. 본 task = 고유 신규 branch name allocate + live branch ref 절대 reset 0.

---

## 1. task-2553+8 결과 인정 (회장 verbatim)

1. isolated-worktree evidence source refinement = COMPLETE/PASS 2. task-2553+1 첫 적용 HOLD = DEFENSIVE_HOLD_PASS 3. controller 결함 아님 4. dev2 책임 아님 5. Critical 7 아님 6. live checkout branch ref reset 위험 감지·실 write 0 정지 = 올바른 fail-closed.

## 2. 목표 (회장 verbatim)

clean replacement PR open 용 branch 가 live workspace 에 checkout 된 branch ref 와 충돌하지 않도록, activation runner 가 **고유 신규 replacement branch name 을 할당**하고, 기존 live checkout branch 를 reset 하지 않도록 코드/파일 자동화를 구현한다.

## 3. 핵심 원칙 (회장 verbatim 6)

- live workspace 에 checkout 된 branch ref 는 **절대 reset 하지 않는다**.
- `git checkout -B <existing-live-checked-out-branch>` **금지**.
- clean replacement PR open 용 branch 는 isolated worktree 전용 fresh branch name 으로 생성한다.
- branch name collision / checked-out elsewhere / existing ref conflict 를 **preflight 에서 검사**한다.
- 충돌 시 기존 branch 를 강제 reset 하지 않고 **새 branch name 을 allocate** 한다.
- live workspace reset/clean/stash/rm/unlink/rmtree **금지**.

## 4. 구현 방향 (회장 verbatim 9)

1. branch_ref_allocator 구현
2. checked-out branch detection 구현
3. existing local/remote branch conflict detection 구현
4. fresh replacement branch naming 구현 (예: `task/task-2553p1-f1-clean-replacement-<runid>`)
5. activation runner 가 allocated branch 만 사용하도록 수정
6. branch ref reset primitive 제거 또는 fail-closed 처리
7. isolated worktree 에서만 branch 생성/commit/push 수행
8. live workspace branch/head 불변 검증
9. task-2553+1 F1-solo clean replacement PR open 재적용

## 5. 허용 범위 (회장 verbatim 10)

task-2553+9 코드/테스트/fixture 구현 / isolated worktree 전용 branch 생성 / commit / push / clean replacement PR open / result·report·evidence marker 생성 / normal+fallback callback 등록 / Codex post-result audit / ANU-Codex adjudication / task-2553+1 expected_files 6개 내 변경

## 6. task-2553+1 허용 effective diff (회장 verbatim 6 — 단일 권위)

1. `anu_v2/owner_trigger_pat.py`
2. `tests/regression/test_owner_trigger_2553_plus1_high_fix.py`
3. `memory/reports/task-2553+1.md`
4. `memory/events/task-2553+1.result.json`
5. `memory/events/task-2553+1.red-evidence.log`
6. `memory/events/task-2553+1.green-evidence.log`

> 파일명 권위: task-2553+6/+8 §5 동일 — #2 = `high_fix`(회장 spec 단일 권위, 기존 f1.py = 미머지 evidence-only HOLD 아티팩트, 상이 lifecycle).

## 7. 금지 (회장 verbatim)

merge / PR #102 원본 변경 / same-branch push / F2 수정 / token transport 변경 / phase3 test 수정 / merge_queue_executor 수정 / 기존 preserved tests assertion 수정 / expected_files 6개 밖 변경 / credential·OWNER PAT 조작 / clean replacement PR open 범위 초과 actual API 호출 / real write·limited real write 일반 진입 / dev status 자동 변경 / 자동 closeout 확정 / **live workspace cleanup·reset·stash·rm·unlink·rmtree**

## 8. 필수 regression (회장 verbatim 16)

1. target branch checked out in live workspace → allocator chooses new branch, no reset
2. target branch exists local but not checked out → safe allocation or new branch according to policy
3. target branch exists remote → collision-safe suffix allocation
4. no collision → deterministic branch name
5. branch allocation provenance recorded
6. live workspace HEAD unchanged
7. live workspace branch ref unchanged
8. same-branch push impossible
9. PR #102 preserved
10. expected_files 6 exact diff
11. F2 unchanged
12. phase3/mqe unchanged
13. merge path unreachable
14. credential/API beyond PR-open unreachable
15. callback registered
16. Codex audit/adjudication loop completes

## 9. HOLD_FOR_CHAIR 조건 (회장 verbatim 13)

live branch ref reset 필요 / clean unique branch allocation 실패 / isolated worktree 생성 실패 / expected_files 6개 밖 diff / PR #102 원본 변경 필요 / same-branch push 필요 / merge 필요 / F2·token transport 변경 필요 / phase3·mqe 변경 필요 / credential·API·real write 필요 / Codex unresolved HIGH·CRITICAL / ANU-Codex 반복 충돌 / 목표 달성 불가

## 10. 완료 후 최종 packet (회장 verbatim 12 — 중간 보고 금지, 최종 1개)

allocated branch name / clean replacement PR 번호 / live workspace HEAD·branch·ref 불변 증거 / effective diff 6파일 일치 / PR #102 보존 / F2 byte-identical / phase3·mqe 무변경 / regression 결과 / Codex audit·adjudication 결과 / callback collector 결과 / HOLD 여부 / merge 가능 여부 판단

## 11. ANU 배치안 / expected_files (task-2553+9 자체 — 코드/테스트/fixture 필수, 문서만 금지)

1. `anu_v3/branch_ref_allocator.py` — collision-safe branch name allocator. checked-out detection(`git worktree list --porcelain` 전 worktree HEAD ref 파싱) + local ref(`git show-ref --verify refs/heads/<name>`) + remote ref(`git ls-remote --heads origin <name>` 또는 isolated wt 내 `git branch -r`) conflict detection. 충돌 시 deterministic fresh suffix(`-<runid>`, runid=uuid4 hex 12) allocate, 미충돌 시 base name. **절대 강제 reset 0** — 충돌은 회피(새 name)로만 해소.
2. `anu_v3/pre_authorized_activation_runner.py` — **surgical edit (회장 §4-5/6 명시 "runner ... 수정")**: `:225` `_run(["git","checkout","-B", new_branch, base_sha], repo)` 를 (a) branch_ref_allocator 로 받은 **allocated unique branch name 사용** + (b) 작업을 **isolated worktree 내부에서만**(`git -C <isolated_wt>`) 수행 + (c) live repo 대상 `checkout -B`/branch ref reset primitive **제거·fail-closed**(live-checked-out branch 와 동일 name 이면 즉시 HOLD, reset 0). 그 외 runner 로직(deriver/gate/binding preflight 체인·merge 부재·dry-run) 무변경.
3. `anu_v3/goal_activation_controller.py` — branch allocation 결과를 activation flow 에 배선하는 최소 seam (결정 로직·6조건·call API 무변경, 기존 controller regression 무회귀).
4. `scripts/run_branch_ref_allocator.py` — CLI (repo/isolated_wt 경로 + base name → allocated name + provenance JSON).
5. `schemas/branch_allocation_provenance.schema.json` — **9-R.6 과 1:1 필드**: `allocated_branch_name` / `base_sha` / `collision_detected` / `sources_checked`(worktree/local/remote) / `runid` / `live_checkout_branch` / `chosen_strategy`(base|suffixed). (base_name 미사용 — base_sha 단일 권위로 통일.)
6. `memory/fixtures/branch_alloc_live_checkedout_collision.json` — target = live-checked-out → 새 name·no reset
7. `memory/fixtures/branch_alloc_local_not_checkedout.json` — local 존재·미checkout → 정책 allocation
8. `memory/fixtures/branch_alloc_remote_conflict.json` — remote 존재 → suffix allocation
9. `memory/fixtures/branch_alloc_no_collision.json` — 미충돌 → deterministic name
10. `tests/regression/test_branch_ref_allocator_2553plus9.py` — §8 16 regression + 4 fixture 시나리오
11. `memory/events/task-2553+9.activation-decision.json`
12. `memory/events/task-2553+9.hold-for-chair.json` (조건부)
13. `memory/reports/task-2553+9.md`
14. `memory/events/task-2553+9.result.json` — 최종 packet 12

> branch/commit/push 는 **isolated worktree(`git worktree add <path> <base_sha>`) 내부 전용**. live repo 대상 git write 0. allocator 는 read-only detection 만(show-ref/ls-remote/worktree list — write 0). live workspace HEAD·branch·ref 불변을 실행 전후 sha 비교로 검증.

## 12. forbidden_write_targets (수정 0 — task-2553+9 자체)

**무수정 frozen (byte-identical):** anu_v3/pre_authorized_action_gate.py(f34e2445…) / pre_authorized_contract_deriver.py / pre_authorized_executor_binding.py / pre_authorized_evidence_bundle_builder.py / anu_v3/isolated_worktree_evidence_source.py / **`utils/anu_delegation_completion_callback.py`(callback orchestrator 본체 — 명시 frozen, import/결합 0)** / schemas/pre_authorized_*.schema.json / schemas/goal_execution_*.schema.json / utils/completion_callback_fallback_cancel.py(+9a 산출, 무관) / tests/regression/test_pre_authorized_* / test_goal_activation_controller_2553plus7 / test_isolated_worktree_evidence_2553plus8 / test_anu_delegation_completion_callback_2595 / test_completion_callback_dup_ignored_realworld_2553plus1 / 9B3BEB11 fixture / dispatch.py / scripts/finish-task.sh / task-timer.py / post-tool-use.sh / test_owner_trigger_2553_plus1_f1.py(미머지 evidence-only, 무관) / task-2553+1~+8·+9a md.

**surgical edit 허용 (회장 §4 명시):** anu_v3/pre_authorized_activation_runner.py(:225 branch primitive + allocator 통합·fail-closed만) / anu_v3/goal_activation_controller.py(branch alloc seam만, 기존 regression 무회귀) / scripts/run_*.py(allocator 배선) / schemas append only.

**특히:** live workspace(tracked/untracked)·타 worktree 대상 git reset/clean/stash + rm/unlink/rmtree + `checkout -B`/branch-ref-reset on live-checked-out branch 호출 정적·런타임 **부재 강제**. isolated worktree 정리 = `git worktree remove` 만.

## 13. ANU-Codex loop (자동 수렴)

batch plan(본 §11) → Codex lint → ANU refine → Codex re-lint → dispatch(적합 dev 1회, TTL 2h, callback (a)) → 구현 → regression → dry-run → micro-fix → post-result audit → ANU·Codex adjudication → 최종 packet 12. 회장 중간 라우팅 0, HOLD 조건 적중 시만 회장 보고.

## 9-R. Codex lint 반영 정밀 보강 (NEEDS_REFINEMENT → 자동 수렴, agent ab65357361d472b14)

### 9-R.1 (HIGH #3 해소) runner 4개 write primitive **전부** isolated worktree 재타겟

§11-2 정정 — line 225 단독 아님. activation runner 의 **4개 실 write primitive 전부** 가 live `repo` 가 아닌 isolated worktree 대상:
- ① `git checkout -B <allocated_unique_name> <base_sha>` → `git -C <iso_wt>` (allocated name, live-checked-out 와 절대 불일치)
- ② `git ... commit` (6 effective-diff 파일) → `git -C <iso_wt>`
- ③ `git push` (신규 allocated branch only) → `git -C <iso_wt>`
- ④ `gh pr create` → **반드시 isolated worktree 컨텍스트에서 실행**(`cwd=<iso_wt>` 또는 `git -C <iso_wt>` 동등 — gh 가 isolated worktree 의 git 컨텍스트에서 repo 해석) + `--repo <owner/repo>` 명시 + `--head <allocated_branch>` + `--base main`. live repo working dir 대상 read/write **0**.
live `repo`(메인 워크스페이스) 대상 git-write·gh-write **0** (4 primitive 전부 정적·런타임 부재 강제 — isolated wt 외 git/gh write 경로 코드상 부재). 그 외 runner 로직(deriver/gate/binding preflight·merge 부재·dry-run) 무변경.

### 9-R.2 (HIGH #1/#8 해소) isolated worktree lifecycle 소유·seam 명시

**activation runner 가 isolated worktree lifecycle 단독 소유**(controller 인자 결합 0): runner 가 activation 시작 시 `git worktree add <iso_path=.worktrees/task-2553p1-act-<runid>> <base_sha>` 생성 → 4 primitive 전부 거기서 수행 → 종료 시(성공·실패·예외 무관, `finally`) `git worktree remove --force <iso_path>` 만(파괴적 op 아님, live 무영향). controller seam = `run_activation(allocated_branch, base_sha)` 호출만(isolated_wt 인자 미전달, runner 내부 self-manage). 기존 controller regression 무회귀.

### 9-R.3 (MED #2 해소) allocator loop-until-clean (확률 방어 금지)

branch_ref_allocator 는 단발 uuid 아님 — **loop**: candidate = base name → 충돌 시 `<base>-<runid(uuid4 hex12)>` → (worktree list checked-out ∪ local refs `show-ref` ∪ remote refs `ls-remote --heads origin`) 3-source 전부 absent 확인. 하나라도 present → 새 runid 재생성·재검사. **모든 source 에서 absent 될 때까지 반복**(bounded max 8회, 초과 시 HOLD "clean unique branch allocation 실패"). 강제 reset 0. allocator read-only(show-ref/ls-remote/worktree list — git-write 0).

### 9-R.4 (HIGH #4 해소) fail-closed: live-checked-out 일치 시 git-write 전 HOLD

모든 git write **이전** preflight: allocated name 이 `git worktree list --porcelain` 의 어떤 checked-out branch 와라도 일치 → **즉시 HOLD_FOR_CHAIR(git write 0)**. 9-R.3 loop 와 belt-and-suspenders 이중 차단. live branch ref reset primitive 코드상 부재(제거).

### 9-R.5 (HIGH #7 해소) 누락 regression 6 추가 (§8 16 + )

17. live-repo `checkout -B`/reset/clean/stash/rm/unlink/rmtree 정적 부재(AST/grep, isolated wt 외)
18. allocator suffix loop-until-clean: 1차 충돌 → 재생성 → 전 source absent 확인
19. pre/post live workspace HEAD sha `assertEqual`(불변 직접 증명)
20. isolated worktree 실패·예외 시에도 `finally` 로 제거(live 무영향)
21. runid uniqueness/idempotency(동일 입력 재실행 시 중복 PR open 0)
22. allocator read-only 증명(git-write 부작용 0, detection만)

### 9-R.6 (#6 해소) branch allocation audit trail 필수

decision/result/activation-decision artifact 에 `base_sha` + `allocated_branch_name` + `collision_detected` + `sources_checked`(worktree/local/remote) + `runid` + `chosen_strategy`(base|suffixed) + `live_checkout_branch` 기록 필수(§11-5 schema 와 1:1). 미기록 → HOLD.

→ 9-R.1~9-R.6 으로 Codex HIGH 4 + MED 1 + #6 전건 해소. CRITICAL 0 유지. 회장 라우팅 0. Codex re-lint GO_READY 시 dispatch.

## 14. task-2553 계열 (혼선 방지)

+1=F1 / +2·+3=초안 / +4=gate / +5=deriver+binding / +6=activation runner / +7=goal controller v0 / +8=isolated-worktree evidence(COMPLETE, 첫 적용 DEFENSIVE_HOLD: branch collision) / +9a=callback fallback cancel(별개 트랙, 진행중) / **+9(본건)=branch collision-safe activation refinement + task-2553+1 F1-solo 실 clean replacement PR open 재수행**.
