# P2 — finish-task callback-before-failfast routing contract DRAFT (260529)

★ **DRAFT ONLY** — 회장 verbatim "P2 설계 초안" 인가 영역 한정. 본 문서 = read-only spec draft. 코드 수정 0 / finish-task.sh 수정 0 / dispatch.py 수정 0 / dispatch 발사 0 / PR / branch push / merge 0.

- **chair_authorization_id_anchor**: 회장 verbatim 2026-05-29 P2 설계 초안 작성 인가 (★ '단 코드 수정 금지 · finish-task.sh 수정 금지 · dispatch 금지 · PR/branch push/merge 금지')
- **doctrine_anchor**: "evidence 만 따른다" + "ANU 자체 분류 결정 0"
- **lineage_category**: ROUTING_LAYER_DESIGN_SPEC_DRAFT (★ 회장 verbatim 4 enum 매핑 외 별도 spec layer)
- **out_of_scope_explicit**: implementation / dispatch / code edit / cron registration / .done generation / task-2708 자동 발의

---

## 1. 문제 정의 (★ 회장 verbatim)

### 1.1 핵심 문제 1 줄

> **callback registration gate가 fail-fast 이후에 위치한다.**

### 1.2 구체화 4 condition

- **C1**: `scripts/finish-task.sh L377` (QC FAIL exit 1) 가 `L1550` (callback registration helper launch) 보다 1155 라인 위에 있다.
- **C2**: QC FAIL / scope-guard FAIL / tdd_check FAIL / taskctl fail-closed 경로에서 callback gate 미도달.
- **C3**: 결과 회수 실패 시 ANU 가 직접 수동 read-only 검증으로 회수해야 한다 (★ ANU session 의존).
- **C4**: FORMALIZATION_COMMIT_ONLY / lineage cleanup / read-only verification 등 'feature 추가 = 0' task type 에서 동일 cascade 재발 가능.

### 1.3 production 영향 evidence — task-2707

- acceptance 7/7 PASS · forbidden 11/11 OK · regression 3/3 PASS · commit success → implementation **8 evidence PASS**
- callback-launch.json 부재 · .done 부재 · ANU cron-list 빈 schedules · .escalate 14:01 박힘 → routing **5 evidence FAIL**
- 회장 verbatim 4 enum 판정: **IMPLEMENTATION_PASS_ROUTING_FAIL** (★ 고정)

---

## 2. source evidence (★ verbatim · read-only 인용)

### 2.1 finish-task.sh fail-fast / callback gate 위치

| 위치 | 코드 의미 |
|---|---|
| L355-377 | QC 결과 확인 → `if QC_STATUS = "FAIL": .failed marker 작성 + exit 1` |
| L448-451 | `SCOPE-GUARD FAIL — 머지 차단 + .escalate 생성 + exit 1` |
| L470 | `exit 1` (taskctl 관련 fail-fast) |
| L483 | `exit 1` (taskctl fail-closed) |
| L492 | `exit 1` |
| L505 | `exit 1` |
| L1532-1558 | `# 5.5. [task-2626 + task-2661 Phase 2b] callback runtime enforcement gate` |
| L1546-1548 | `callback_kind=normal / owner_key=$T2626_ANU_KEY (c119085addb0f8b7)` |
| L1550 | `python3 -m dispatch.normal_fallback_callback_helper launch ...` |
| L1556 | `> "$WORKSPACE/memory/events/${TASK_ID}.callback-launch.json"` |
| L1557 | `&& echo "[task-2626] callback runtime gate: ANU-owned launcher PASS"` |

### 2.2 exit points before callback gate count

- 17+개 (★ grep evidence: L67/L80/L117/L132/L161/L192/L203/L208/L211/L222/L282/L321/L359/L367/L377/L448/L451/L470/L483/L492/L505 등)
- 모든 17+ path 가 L1550 callback registration 우회

### 2.3 3 case production evidence 비교 (★ STEP 1 박제 정합 인용)

| axis | task-2626 | task-2661 | task-2707 |
|---|---|---|---|
| callback reg location | L1550 | L1356-1380 (★ 본 task 자체 fix) | L1532-1558 |
| 미등록 사유 | N/A | N/A | **★ L377 exit cascade** |
| finish-task 종료 | normal exit 0 | normal exit 0 | **★ L377 fail-fast exit 1** |
| .done present | YES (14:33) | YES (16:08) | **★ NO** |
| helper invoked | YES | YES | **★ NO** |
| cron registered (ANU key) | YES `task-2626::normal` | YES (absolute 30s) | **★ NO (빈 schedules)** |
| 결과 회수 | SUCCESS | SUCCESS | **★ FAIL (수동)** |

### 2.4 linked source markers

- `memory/events/anu_p2_finish_task_routing_callback_registration_after_failfast_evidence_260529.json` (★ STEP 1~4 evidence 박제)
- `memory/events/task-2626.callback-launch.json` (★ baseline 등록 성공)
- `memory/events/task-2661.callback-normal-fire-delay-remediation-p2b-result-260525.json` (★ L1369 fix 본 task)
- `memory/events/task-2707.formalization-commit-260529.json` (★ acceptance 7/7 PASS)
- `memory/events/task-2707.escalate` (★ system-auto-escalate)
- `memory/events/p1b_finish_task_profile_contract_accepted_with_known_caveats_260529.json` (★ C2 caveat lineage)

---

## 3. candidate contract rules (★ 회장 verbatim 5 rule · ANU 자체 신설 0)

| ID | 규칙 문장 |
|---|---|
| R1 | callback registration 은 fail-fast 보다 먼저 보장되어야 한다 |
| R2 | fail-fast 직전이라도 envelope 이 있으면 ANU callback cron 등록은 1회 보장되어야 한다 |
| R3 | 모든 종료 path 에서 callback registration 단계를 결정성 1회 통과해야 한다 |
| R4 | callback registration 은 idempotent 해야 한다 |
| R5 | callback registration 실패는 별도 marker 로 남겨야 한다 |

★ 본 5 rule = 회장 verbatim 인용 · ANU 자체 신설 0 · 우선순위 결정 회장 영역.

---

## 4. task_type 별 정책 (★ 회장 verbatim 7 task_type)

| task_type | callback 의무 | normal completion path | fail-fast 시 callback | 비고 |
|---|---|---|---|---|
| `code` | YES | QC PASS → done → callback | R3 정합 — fail-fast 이전 register 보장 | 일반 코드 task (PR/merge 가능) |
| `system_hook` | YES | QC PASS → done → callback | R3 정합 | finish-task.sh / dispatch.py 등 system hook 수정 task |
| `local_runtime` | YES | local commit → callback (PR 없음) | R3 정합 | local-only commit task (task-2569+1 lineage) |
| `formalization_commit_only` | YES | commit only → callback | **★ R3 + R4 필수** | **task-2707 lineage** · tdd_check 면제 영역 · body byte 0 변경 정합 |
| `read_only` | YES | verification artifacts → callback | R3 정합 + R5 별도 marker | task-2705+4 / task-2706+1 lineage · QC SKIP 정합 |
| `callback_only` | YES (★ self) | envelope 작성 → callback | R3 직접 정합 | 본 task type 자체가 callback 등록 layer |
| `closeout_marker_only` | YES | marker 작성 → callback | R3 정합 | P1-A / P1-B closeout marker 작성 task 영역 |

★ task_type 분류 = P1-B matrix `v36_p1b_task_mode_pass_warn_fail_escalate_matrix_260529.md` 와 정합 / lineage rewrite 0.

---

## 5. callback kind (★ 회장 verbatim 6 kind)

| kind | trigger | owner_key | cron schedule | marker path 예시 |
|---|---|---|---|---|
| `normal` | QC PASS → done | ANU key `c119085addb0f8b7` | absolute 30s (★ task-2661 fix) | `{task_id}.callback-launch.json` (★ status=ANU_OWNED_READY) |
| `fail_fast` | L377 / L451 / L483 exit 1 | ANU key | absolute 30s | `{task_id}.callback-fail-fast-launch.json` (★ 신규 marker 분류) |
| `escalate` | .escalate / .qc-result FAIL × N | ANU key | absolute 30s | `{task_id}.callback-escalate-launch.json` |
| `hold_for_chair` | doctrine conflict / OWNER PAT 부재 등 | ANU key | absolute 30s | `{task_id}.callback-hold-for-chair-launch.json` (★ task-2661 lineage) |
| `verifier_result` | Maat / Odin verifier task 완료 | ANU key | absolute 30s | `{task_id}.callback-verifier-launch.json` (★ task-2706+1 lineage) |
| `fallback` | normal 30s 내 등록 실패 시 safety-net | ANU key | `10m` (★ task-2661 DEFAULT_AT_FALLBACK 유지) | `{task_id}.callback-fallback-launch.json` |

★ 모든 kind = ANU key 단일 강제 (★ self-collector forbidden doctrine 정합).
★ normal vs fail_fast 분리 박제 (★ R3 정합 evidence 박제 가능성).

---

## 6. safety model (★ 회장 verbatim 6 항목)

| safety | 적용 방식 |
|---|---|
| **duplicate callback 방지** | idempotency key = `(task_id, callback_kind, executor_attempt_n)` |
| **idempotency key** | `task_id::callback_kind` (★ task-2626 cron_id 패턴 정합) |
| **callback marker** | 등록 시 `{task_id}.callback-launch.json` 작성 · 실패 시 `{task_id}.callback-not-registered.json` (★ R5) |
| **no GitHub write** | callback 등록 자체는 cokacdir cron 호출만 · GitHub API 0 |
| **no task mutation** | task md / task-timers.json / lineage marker 수정 0 |
| **safe-fail** | callback helper 자체 예외 시 .escalate / silent skip · finish-task.sh 자체는 진행 가능 (★ R5 marker 박제) |

★ safety model = task-2626 / task-2661 lineage 정합 + task-2707 차단 사례 보완.

---

## 7. 적용 범위 (★ 회장 verbatim 3 항목)

- ✅ 이번 단계는 **설계 초안만**
- ❌ finish-task.sh 수정 없음
- ❌ helper 수정 없음
- ❌ dispatch.py 수정 없음
- ❌ 코드 수정 없음 / dispatch 발사 없음 / PR 생성 없음 / branch push 없음 / merge 없음
- ❌ task md / task-timers.json mutation 없음
- ❌ ANU 자체 추가 task 발의 없음

★ 본 spec = 회장 결정 spec read-only 박제 · 향후 구현은 회장 별도 인가 후 task ID 신규 발급.

---

## 8. 향후 구현 task 후보 (★ 회장 verbatim 4 candidate · ANU 자체 발의 0)

| candidate ID | 목적 | 우선순위 | 의존성 |
|---|---|---|---|
| **P2-A**: callback-before-failfast pre-registration layer | finish-task.sh 진입 직후 callback registration 1회 결정성 통과 | 1st (★ R1/R3 핵심) | 회장 별도 인가 / 회장 task ID 발급 |
| **P2-B**: all-exit-path callback finalizer | 모든 17+ exit point 에서 callback gate 통과 보장 | 2nd | P2-A 의존 / 회장 별도 인가 |
| **P2-C**: callback idempotency marker | `{task_id}.callback-launch.json` + duplicate 방지 enforcement | 3rd | P2-A · P2-B 의존 / 회장 별도 인가 |
| **P2-D**: task_type aware fail-fast routing | tdd_check 등 verifier 가 task_type 인식 (★ FORMALIZATION_COMMIT_ONLY 면제 등) | 4th | P1-C completion 후 (★ actor attribution 정합) / 회장 별도 인가 |

★ 4 candidate 모두 **회장 verbatim 별도 인가 대기** · ANU 자체 발사 0.
★ P2-A ↔ P2-B 분리 이유: pre-registration 은 finish-task 진입 직후 / finalizer 는 종료 path coverage · 분리 박제 + 회장 우선순위 결정 영역.

---

## 9. task-2707 처리 제안 (★ 회장 verbatim 3 항목)

- **implementation PASS 로 보존**: commit `b5f652440f76f4b3...` + 5 expected_files + acceptance 7/7 + forbidden 11/11 + regression 3/3 PASS evidence 박제 유지 · revert 0
- **routing fail 로 별도 caveat**: P1-B closeout C1 → C1+1 으로 추가 분류 가능 (★ 회장 결정 영역) · routing FAIL = task-2707 자체가 P2 trigger evidence 1호
- **C1 formalization closeout 은 P2 설계 후 별도 결정**: 본 spec → 회장 결정 → P2-A 구현 → task-2707 verifier 재실행 또는 ANU 독립 verifier 대체 → C1 closeout marker 작성

★ 본 처리 제안 = 회장 verbatim 정합 매핑 · ANU 자체 결정 0 · 회장 결정 대기.

---

## 10. 금지 범위 (★ 회장 verbatim 5 강제)

- ❌ 코드 수정 금지
- ❌ finish-task.sh 수정 금지
- ❌ `.done` 생성 금지
- ❌ callback cron 수동 생성 금지
- ❌ task-2708 자동 발의 금지

★ 본 spec draft 작성 = mutating action 1건 (★ 본 md 파일 신규 작성만) · 회장 verbatim P2 설계 초안 인가 영역 정합.

---

## 11. ANU doctrine compliance (★ 본 spec draft 작성)

- ★ "evidence 만 따른다" doctrine 정합 (★ source evidence §2 verbatim 인용만)
- ★ ANU 자체 분류 결정 0 (★ task_type 7 · kind 6 · safety 6 · candidate 4 모두 회장 verbatim · 신규 신설 0)
- ★ ANU 자체 FULL_ACCEPT 판정 0 (★ task-2707 IMPLEMENTATION_PASS_ROUTING_FAIL = 회장 verbatim 4 enum 매핑)
- ★ ANU 자체 dispatch 0 (★ P2-A/B/C/D 4 candidate 모두 회장 발사 인가 대기)
- ★ ANU 자체 task md 작성 0 (★ P2-A/B/C/D task md 미작성 · 회장 인가 후만)
- ★ ANU 자체 코드 수정 0
- ★ self-collector callback 금지 doctrine 정합 (★ kind 6 모두 ANU key 단일 강제)

---

## 12. lineage preservation (★ 회장 verbatim)

- task-2626 — callback runtime enforcement gate 도입 (★ L1550 origin · 보존)
- task-2661 — callback fire delay 30s remediation Phase 2b (★ L1369 fix · 보존)
- task-2707 — IMPLEMENTATION_PASS_ROUTING_FAIL trigger evidence 1호 (★ 회장 verbatim 고정 · 보존)
- P1-B closeout C2 caveat — "scope-guard 35 violations · finish-task.sh git diff main..HEAD" (★ P2 동기 lineage · 보존)
- P1-C IMPLEMENT_LATER — actor attribution contract (★ task_type aware fail-fast routing P2-D 의존 가능성 · 보존)
- **본 spec — P2 routing contract draft (★ 본 문서)**
- lineage_rewrite_count: 0

---

## 13. Chair decision pending (★ 본 spec → 회장 결정 6 영역)

1. ★ 본 spec draft 승인 여부 (★ P2 설계 초안 범위 정합 확인)
2. ★ candidate contract rules 5 우선순위 결정 (R1/R2/R3/R4/R5)
3. ★ P2-A / P2-B / P2-C / P2-D 구현 순서 결정 (★ ANU 자체 발의 0)
4. ★ task-2707 처리 (implementation PASS 보존 vs routing fail caveat 별도 분류)
5. ★ C1 closeout 시점 (★ P2-A 구현 후 vs ANU 독립 verifier 대체 vs HOLD_FOR_CHAIR)
6. ★ task_type aware fail-fast routing (P2-D) 의 P1-C 의존성 결정

---

## 14. Sentinel

★ 본 spec = P2 finish-task routing contract DRAFT only. 회장 결정 전 P2-A/B/C/D 구현 0 · finish-task.sh 수정 0 · dispatch 0 · code 수정 0. 끝
