# task-2513 — critical_escalation_reporter: Critical 7종 전용 escalation 시스템

- 작업 유형: **자동화 코드 구현 + 회귀 테스트** (정책 문서 X)
- 작업 레벨: **Lv.3**
- 우선순위: **★★**
- Track: **critical_escalation_reporter / chair_report_only_critical_7 / 5 모듈 #5**
- parallel_policy: **limited_parallel** (회장 명시 — task-2512와 병렬 가능)
- 일시: 2026-05-09
- 회장 결정: 2026-05-09 직접 발행 (5 모듈 #5)

## ⚠️ 본 task의 본질 — 회장 명시

> Critical 7종만 회장 보고 대상으로 packet화하고,
> 나머지는 자동 처리 evidence/audit만 남긴다.
> 산출물 = 코드 + 회귀 테스트. 문서는 부속.

## dependency (모두 충족)

- ✅ task-2509+2.merged (PR #60, automation_contracts.py freeze — CriticalEscalationType/EscalationPacket 사용)
- ✅ task-2510.merged (PR #61, replacement_pr_runner — REPLACEMENT_PR_FAILED/AUTO_CREATION_FAILED packet 입력)
- ✅ task-2511.merged (PR #62, auto_gemini_triage — GEMINI_REAL_BUG_REQUIRES_SCOPE_EXPANSION/FORBIDDEN_PATH_INTRUSION packet 입력)

## 병렬 정책 (회장 명시)

- **task-2512와 병렬 가능** (limited_parallel)
- 두 task expected_files가 disjoint (utils/critical_escalation_reporter.py vs utils/post_merge_smoke_runner.py)
- 단, **task-2514 wiring은 두 task 모두 main 머지 완료 전까지 발사 금지**
- task-2514는 마지막 serial orchestration runtime wiring 단계

## Merge Topology Gate metadata

```yaml
expected_files:
  - "utils/critical_escalation_reporter.py"
  - "tests/regression/test_critical_escalation_reporter_2513.py"

risk_area: "critical_escalation_reporter / chair_report_only_critical_7 / audit_log"

dependency:
  - "task-2509+2.merged"
  - "task-2510.merged"
  - "task-2511.merged"

parallel_policy: "limited_parallel"

merge_queue_position: 10

stale_recheck_required: true

cherry_pick_allowed: false
```

## Critical 7종 (정확 매칭 — automation_contracts.py freeze)

```python
class CriticalEscalationType(str, Enum):
    FORBIDDEN_PATH_INTRUSION                              # #1
    REPLACEMENT_PR_AUTO_CREATION_FAILED_FOR_CONTAMINATED_DIFF  # #2
    GEMINI_REAL_BUG_REQUIRES_SCOPE_EXPANSION              # #3
    BLOCK_OVERRIDE_REQUIRED_OR_REASON_INSUFFICIENT        # #4
    DEPENDENCY_CYCLE_OR_SERIAL_ONLY_COLLISION             # #5
    REPLACEMENT_PR_FAILED                                  # #6
    POST_MERGE_SMOKE_FAILED                                # #7
```

## 자동 처리 7항목 (회장 보고 X — audit/evidence만 기록)

1. false-positive Gemini evidence dismiss
2. style-only Gemini dismiss
3. 허용 파일 내 minor fix
4. clean replacement PR 생성
5. dependency satisfied 자동 판정
6. queue 선두 PR의 CI/Gemini/CLEAN 확인 후 자동 머지
7. 머지 후 smoke 및 후행 stale 재검증

## 실전 replay fixture (회장 명시 — 반드시 replay)

### Critical escalation fixtures (회장 §9)
- forbidden path 침범 → Critical #1
- replacement failure → Critical #2 (REPLACEMENT_PR_AUTO_CREATION_FAILED_FOR_CONTAMINATED_DIFF)
- scope expansion → Critical #3
- dependency cycle → Critical #5
- smoke failure → Critical #7
- BLOCK override insufficient → Critical #4

### Auto-handled fixtures (회장 §10)
- style-only Gemini → suppression (회장 보고 X, audit만)
- false-positive Gemini → suppression
- outdated thread → suppression
- clean replacement PR 생성 → suppression
- dependency satisfied → suppression

## 필수 구현 10건 (회장 §1~10)

### 1. CriticalEscalationType 기반 routing
- 입력 event를 CriticalEscalationType enum으로 매칭
- 매칭 실패 시 non-critical 분류 (auto-handled로 routing)

### 2. escalation packet 생성
- `EscalationPacket` instance (automation_contracts freeze)
- escalation_type / merge_commit / task_id / evidence / severity / created_at

### 3. severity/risk classification
- `RiskLevel` enum (LOW / MEDIUM / HIGH / HIGH_CORE) 활용
- Critical 7종은 모두 HIGH 이상
- HIGH_CORE: merge_queue_executor / merge_topology_gate / dispatch.py 영향

### 4. duplicate escalation suppression
- 동일 (escalation_type, task_id, evidence_hash) 중복 제거
- audit log 기반 dedup window (예: 1시간)
- duplicate detected → audit만 기록, 회장 보고 X

### 5. audit log serialization
- `memory/orchestration-audit/critical-escalations.jsonl` (global append)
- `memory/events/{task_id}.escalation.json` (per-task)
- JSON Lines 포맷 (task-2509+1 audit 패턴 정합)

### 6. auto-handled event filtering
- 회장 §자동 처리 7항목에 해당 → suppression
- audit log에 "auto-handled" tag로 기록
- 회장 보고 packet 생성 X

### 7. human-reportable event filtering
- Critical 7종 정확 매칭 시에만 reportable
- 그 외는 모두 auto-handled

### 8. EscalationPacket formatter
- 회장 보고용 텍스트 포맷 (1~3 문장 요약 + evidence 링크)
- Telegram 발송 가능한 포맷 (4096자 이내)
- task ID / merge_commit / failure reason 명시

### 9. replay fixture (회장 §9)
- 6 critical escalation fixture 회귀 입력

### 10. auto-handled replay (회장 §10)
- 5 auto-handled fixture suppression 검증

## 필수 회귀 테스트 12건 (회장 §1~12)

`tests/regression/test_critical_escalation_reporter_2513.py`:

1. Critical 7종 exact match (7개 enum 모두 reportable)
2. non-critical suppression (Critical 7종 외 → audit only)
3. duplicate suppression (동일 escalation 중복 제거)
4. packet JSON serialization (round-trip 무결성)
5. severity mapping (Critical 7종 → HIGH/HIGH_CORE)
6. escalation formatting (회장 보고 텍스트 4096자 이내)
7. audit generation (jsonl append 정상)
8. **★ replay escalation fixtures**: 6 critical 사례 packet 생성
9. **★ replay auto-handled fixtures**: 5 auto-handled 사례 suppression
10. forbidden path → Critical #1 + HIGH_CORE
11. smoke failure → Critical #7 + audit append
12. style-only Gemini → suppression + audit "auto-handled" tag

## CLI entrypoint

`python3 utils/critical_escalation_reporter.py --event-file <path> --dry-run`
- 입력: event JSON (escalation_type 후보 + evidence)
- 출력: `EscalationPacket` JSON 또는 `SUPPRESSED` 결정
- `--apply` 옵션: 실제 audit log append + Telegram 발송 hook
- `--no-audit` 옵션 (테스트용)

## 금지 행위 (회장 명시 — 절대 준수)

- **merge_queue_executor wiring 금지** (import 가능성만 확인)
- **auto merge 실행 금지** (escalation/suppression 결정만)
- **dispatch.py 수정 금지**
- **task-2512 영역 침범 금지** (post_merge_smoke_runner 구현 X — Critical #7 입력만 받음)
- **replacement_pr_runner / auto_gemini_triage 수정 금지**
- **force push 금지**
- **rebase 금지**
- **admin override 금지** (`gh pr merge --admin`)
- **manual .done 금지**
- **required CI bypass 금지**
- **PR #52/#49/#50/#51 수정 금지**
- **expected_files 외 수정 금지**
- **자동 cherry-pick 구현 금지**
- **정책 md만 작성하고 종료 금지**
- **Critical 7종 외 회장 보고 금지**
- **amendment 무시 / mid-dispatch correction 무시 금지**

## allowed_resources

```yaml
allowed_resources:
  read_only_paths:
    - "memory/tasks/task-2509*"
    - "memory/tasks/task-2510*"
    - "memory/tasks/task-2511*"
    - "memory/tasks/task-2513*"
    - "memory/feedback/feedback_critical_escalation_only_260508.md"
    - "utils/automation_contracts.py"  # task-2509+2 freeze
    - "utils/merge_queue_executor.py"
    - "utils/replacement_pr_runner.py"
    - "utils/auto_gemini_triage.py"
    - "memory/orchestration-audit/merge-queue.jsonl"
    - "memory/task-timers.json"
    - ".env.keys"
  paths:
    - "memory/tasks/task-2513*"
    - "memory/reports/task-2513*"
    - "memory/events/task-2513*"
    - "memory/orchestration-audit/critical-escalations.jsonl"
    - "utils/critical_escalation_reporter.py"
    - "tests/regression/test_critical_escalation_reporter_2513.py"
  forbidden_actions:
    - "merge_queue_executor wiring"
    - "dispatch.py 수정"
    - "post_merge_smoke_runner 구현 (task-2512)"
    - "auto merge 실행"
    - "replacement_pr_runner 수정"
    - "auto_gemini_triage 수정"
    - "force push"
    - "rebase"
    - "admin override (gh pr merge --admin)"
    - "manual .done 생성"
    - "required CI bypass"
    - "PR #52/#49/#50/#51 수정"
    - "expected_files 외 수정"
    - "자동 cherry-pick 구현"
    - "정책 md만 작성하고 종료"
    - "Critical 7종 외 회장 보고"
    - "amendment 무시 / mid-dispatch correction 무시"
```

## 완료 조건 (회장 명시)

1. ✅ 실행 가능한 Python 코드 (`utils/critical_escalation_reporter.py`)
2. ✅ Critical 7종만 reportable (7 enum exact match 검증)
3. ✅ non-critical auto-handled (suppression 검증)
4. ✅ EscalationPacket serialization PASS (round-trip 무결성)
5. ✅ replay fixture PASS (6 critical + 5 auto-handled = 11 fixture)
6. ✅ Critical 7종 외 회장 보고 0건
7. ✅ Merge Topology Gate 자기참조 PASS (effective diff = 정확히 2 파일)
8. ✅ CI 11/11 SUCCESS
9. ✅ forbidden path 0
10. ✅ amendment 보호 의무 명시 + 적용 evidence

## 시스템 3문서 참조

- 정책 본체: `memory/feedback/feedback_critical_escalation_only_260508.md`
- 공통 계약: `utils/automation_contracts.py` (task-2509+2 freeze, EscalationPacket/CriticalEscalationType/RiskLevel 사용)
- 실전 fixture: PR #54 contamination / task-2506 base accumulation / task-2507 contamination / PR #61 capability gap

## 후행 task

본 task가 5 모듈 #5. **task-2512와 병렬**. 두 task 모두 main 머지 완료 후:
- task-2514 — 5 모듈 wiring (★ 마지막 serial orchestration runtime wiring)
  - merge_queue_executor → replacement_pr_runner → auto_gemini_triage → post_merge_smoke_runner → critical_escalation_reporter

## affected_files (auto-detected)
- utils/critical_escalation_reporter.py (NEW)
- tests/regression/test_critical_escalation_reporter_2513.py (NEW)

## goal_assertions (auto-generated)
- `python3 utils/critical_escalation_reporter.py --event-file <path> --dry-run`
- `pytest tests/regression/test_critical_escalation_reporter_2513.py -q` → 12/12 PASS