# task-2514 — 5 모듈 orchestration runtime wiring (★ 마지막 serial task)

- 작업 유형: **runtime wiring + end-to-end 회귀 테스트** (새 기능 개발 X, 새 abstraction X)
- 작업 레벨: **Lv.3+** (시스템 orchestration runtime)
- 우선순위: **★★★ blocking** (5 모듈 자동화 완성의 마지막 관문)
- Track: **orchestration_runtime / merge_queue_chain / 5 모듈 wiring (★ 단일 serial)**
- parallel_policy: **serial_only**
- 일시: 2026-05-09
- 회장 결정: 2026-05-09 직접 발행 (5 모듈 모두 main 머지 완료 후)

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

> 본 task는 새 기능 개발이 아니라, 이미 main에 존재하는 5 모듈을 **실제 runtime flow로 연결**하는 것이다.
>
> ```
> merge_queue_executor
>   → replacement_pr_runner
>   → auto_gemini_triage
>   → post_merge_smoke_runner
>   → critical_escalation_reporter
> ```
>
> 를 실제 실행 파이프라인으로 wiring한다.
>
> **이번 task에서는 구현보다 orchestration determinism이 우선이다.**
>
> 성공 기준: **"사람이 중간 개입하지 않아도 queue가 스스로 흐르는 것"**

## 5 모듈 main 머지 완료 (모두 dependency 충족)

- ✅ task-2509.merged (PR #58, merge_queue_executor 본체 + CLI)
- ✅ task-2509+1.merged (PR #59, review_gate_passed + Gemini 7 enum + fallback_review_passed)
- ✅ task-2509+2.merged (PR #60, automation_contracts.py 12 타입 freeze)
- ✅ task-2510.merged (PR #61, replacement_pr_runner)
- ✅ task-2511.merged (PR #62, auto_gemini_triage + resolveReviewThread mutation)
- ✅ task-2512.merged (PR #64, post_merge_smoke_runner + envelope 패턴)
- ✅ task-2513.merged (PR #63, critical_escalation_reporter + LEGACY_CRITICAL_MAP)

## Merge Topology Gate metadata

```yaml
expected_files:
  - "utils/merge_queue_executor.py"  # ★ wiring (5 모듈 import + execution chain)
  - "tests/regression/test_orchestration_runtime_2514.py"  # NEW: end-to-end runtime 회귀

risk_area: "orchestration_runtime / merge_queue_chain / 5_module_wiring / runtime_determinism"

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

parallel_policy: "serial_only"

merge_queue_position: 11

stale_recheck_required: true

cherry_pick_allowed: false
```

## 회장 §금지 (절대 준수)

1. **새 abstraction 생성 금지** (helper module / wrapper class / 신규 dataclass 추가 X)
2. **enum redesign 금지** (CriticalEscalationType / RiskLevel / GeminiStatus / TriageVerdict / SmokeStatus 모두 freeze 유지)
3. **contract schema 변경 금지** (`utils/automation_contracts.py` 수정 0)
4. **policy md 보강 금지** (회장 보고용 정책 문서 작성 X — 본 task는 코드 wiring만)
5. **dispatch.py 대규모 리팩토링 금지** (꼭 필요한 hook 1~2 line 외 dispatch.py 변경 0)
6. **merge topology rule 재설계 금지** (`utils/merge_topology_gate.py` 수정 0)
7. **runtime 범위 밖 "개선 작업" 금지** (TODO 정리 / 코드 정돈 / pyright cleanup 등 본 task 외 모두 보류)

## 회장 §허용 (8건)

1. **import wiring** — merge_queue_executor에서 `from utils.replacement_pr_runner import ...` 등
2. **execution chain 연결** — pipeline 내 5 모듈 호출 순서 wiring
3. **runtime state propagation** — `ReviewGateStatus` / `ReplacementResult` / `PostMergeSmokeRun` / `EscalationPacket` 인스턴스 전파
4. **escalation routing 연결** — Critical 7종 발생 시 `critical_escalation_reporter`로 routing
5. **review thread auto-resolve hook 연결** — `auto_gemini_triage.triage_pr` 호출
6. **stale revalidation 연결** — 후행 PR stale 재검증 hook
7. **smoke continuation 연결** — `PostMergeSmokeRun.allow_continuation` 신호로 다음 queue 처리
8. **audit/evidence propagation 연결** — 단계별 evidence를 audit JSON으로 전파

## Runtime Pipeline 명세 (회장 명시 흐름)

queue 선두 PR이 발견되면 다음 chain으로 처리:

```
[1] merge_queue_executor: queue_head 확인 + base sync + CI/HEAD SHA lock 검증
       │
       ├─[2] effective diff 검증
       │     └─ 오염 검출 → replacement_pr_runner 호출
       │           └─ replacement 실패 → critical_escalation_reporter (#2 또는 #6)
       │           └─ replacement 성공 → 새 PR을 queue 선두로 다시 검증
       │
       ├─[3] forbidden path 검증
       │     └─ 1건 이상 → critical_escalation_reporter (#1 FORBIDDEN_PATH_INTRUSION)
       │
       ├─[4] CI all SUCCESS 검증
       │
       ├─[5] Gemini review thread 처리
       │     └─ auto_gemini_triage.triage_pr 호출
       │           └─ blocking_thread_count > 0 → critical_escalation_reporter (#3 또는 #1)
       │           └─ auto_resolved + review_gate_passed → 다음 단계
       │
       ├─[6] mergeStateStatus CLEAN 검증 (HEAD SHA lock 재확인)
       │
       ├─[7] squash merge 실행 (admin/force/rebase 절대 금지)
       │
       ├─[8] post_merge_smoke_runner 호출
       │     └─ smoke FAIL → critical_escalation_reporter (#7 POST_MERGE_SMOKE_FAILED)
       │     └─ smoke PASS + allow_continuation → 다음 단계
       │
       └─[9] 후행 PR stale 재검증
             └─ Critical 7종 발생 시 → critical_escalation_reporter
             └─ 정상 → 다음 queue 처리
```

자동 처리 7항목 모두 chain 안에서 처리 (회장 §자동 처리 항목과 정합):
- false-positive dismiss / style-only dismiss / allowed minor fix → [5] auto_gemini_triage
- clean replacement → [2] replacement_pr_runner
- dependency satisfied → [1] merge_topology_gate (이미 main)
- queue-head auto merge → [7] squash merge
- smoke + stale revalidation → [8] + [9]

회장 보고는 Critical 7종 발생 시에만 — 모두 critical_escalation_reporter로 routing.

## 필수 wiring 7건 (회장 §허용에서 도출)

### W1. merge_queue_executor에 5 모듈 import wiring
```python
from utils.replacement_pr_runner import ReplacementPRRunner, transplant_expected_files
from utils.auto_gemini_triage import triage_pr, to_legacy_gemini_state
from utils.post_merge_smoke_runner import run_post_merge_smoke, PostMergeSmokeRun
from utils.critical_escalation_reporter import report_critical, route_event
```

### W2. effective diff 오염 → replacement_pr_runner 호출
- `merge_queue_executor`의 effective diff 검증 단계에서 contaminated 판정 시 `ReplacementPRRunner.execute()` 호출
- 실패 시 critical_escalation_reporter로 routing (#2 또는 #6)

### W3. Gemini review thread → auto_gemini_triage 호출
- 기존 `gemini_state` 인터페이스를 `to_legacy_gemini_state(triage_pr(...))`로 교체
- review_gate_passed = (Gemini COMPLETED + unresolved 0) OR (UNAVAILABLE + fallback_review_passed) OR (auto_gemini_triage가 blocking 0 보고)

### W4. squash merge 직후 → post_merge_smoke_runner 호출
- merge commit SHA를 `run_post_merge_smoke()`에 전달
- `PostMergeSmokeRun.envelope`로 결과 받아 `allow_continuation=True` 시 다음 queue 처리
- smoke FAIL 시 critical_escalation_reporter로 routing (#7)

### W5. Critical 7종 routing → critical_escalation_reporter
- 단계별 critical 후보 발생 시 `report_critical(EscalationPacket)` 호출
- duplicate suppression / audit log append는 모듈이 자동 처리
- 회장 보고용 packet은 모듈이 자동 생성 (4096자 이내)

### W6. 후행 PR stale 재검증 hook
- `recheck_following_prs` 단계에서 BEHIND/conflict/diff 오염/forbidden/Gemini stale 모두 평가
- Critical 7종 해당 시 → critical_escalation_reporter
- 정상 → 다음 queue 처리

### W7. audit/evidence propagation
- `memory/orchestration-audit/merge-queue.jsonl` (global append) — 단계별 decision/sha/checks/diff/smoke 기록
- `memory/events/{task_id}.merge-queue.json` (per-task)
- 모든 wiring 단계에서 evidence를 동일 audit schema로 흘림 (task-2509+1 audit 패턴 정합)

## 필수 회귀 테스트 14건 (end-to-end runtime)

`tests/regression/test_orchestration_runtime_2514.py`:

### 정상 흐름 (4건)
1. **clean PR + 자동 머지 10조건 충족** → 5 모듈 chain 통과 → AUTO_MERGE_SUCCESS + smoke PASS + 후행 stale 재검증 OK
2. **Gemini outdated thread × 5** → auto_gemini_triage가 모두 resolve → review_gate_passed → squash merge → smoke PASS
3. **Gemini quota** → fallback_review_passed → review_gate_passed → squash merge → smoke PASS
4. **clean replacement (오염 PR)** → replacement_pr_runner가 새 PR 생성 + 원 PR 보존 → 새 PR 자동 머지

### Critical 7종 escalation (7건)
5. **Critical #1 forbidden path** → critical_escalation_reporter packet 생성
6. **Critical #2 replacement_pr_auto_creation_failed** → packet 생성
7. **Critical #3 gemini_real_bug_requires_scope_expansion** → packet 생성
8. **Critical #4 block_override_required** → packet 생성
9. **Critical #5 dependency_cycle_or_serial_only_collision** → packet 생성
10. **Critical #6 replacement_pr_failed** → packet 생성
11. **Critical #7 post_merge_smoke_failed** → packet 생성

### 자동 처리 7항목 (3건)
12. **false-positive Gemini suppression** → auto_gemini_triage가 dismiss + audit "auto-handled" tag → 회장 보고 0건
13. **style-only Gemini suppression** → 동일
14. **dependency satisfied 자동 판정** → merge_topology_gate ALLOW → 자동 진행

## CLI entrypoint (기존 인터페이스 유지)

`python3 utils/merge_queue_executor.py --pr <N> --dry-run --task-file <path>`
- 출력: `AUTO_MERGE_ALLOWED` / `BLOCKED_WITH_REASON: <code>` / `CRITICAL_ESCALATION: <enum>` JSON
- 회장 §"task-2509 본체 인터페이스 breaking change 금지" — 모든 신규 필드는 추가만, 기존 필드 변경 X
- 출력 JSON에 신규 필드 포함:
  - `pipeline_step` (현재 chain 단계)
  - `replacement_used` (bool)
  - `triage_summary` (auto_resolved / blocking_thread_count)
  - `smoke_envelope` (PostMergeSmokeRun JSON)
  - `escalations` (EscalationPacket 리스트)

## 금지 행위 정리 (회장 §금지 + 공통 7개 동일)

- 새 abstraction 생성 금지 (helper module / wrapper class / 신규 dataclass 0)
- enum redesign 금지
- contract schema 변경 금지 (`utils/automation_contracts.py` 수정 0)
- policy md 보강 금지
- dispatch.py 대규모 리팩토링 금지
- merge topology rule 재설계 금지 (`utils/merge_topology_gate.py` 수정 0)
- runtime 범위 밖 "개선 작업" 금지
- force push / rebase / admin override / manual .done 금지
- required CI bypass 금지
- PR #52/#49/#50/#51 수정 금지
- expected_files 외 수정 금지 (정확히 2 파일)
- 자동 cherry-pick 구현 금지
- 정책 md만 작성하고 종료 금지
- Critical 7종 외 회장 보고 금지
- amendment 무시 / mid-dispatch correction 무시 금지
- task-2509 본체 인터페이스 breaking change 금지

## allowed_resources

```yaml
allowed_resources:
  read_only_paths:
    - "memory/tasks/task-2509*"
    - "memory/tasks/task-2510*"
    - "memory/tasks/task-2511*"
    - "memory/tasks/task-2512*"
    - "memory/tasks/task-2513*"
    - "memory/tasks/task-2514*"
    - "memory/feedback/feedback_critical_escalation_only_260508.md"
    - "utils/automation_contracts.py"  # task-2509+2 freeze (READ ONLY)
    - "utils/replacement_pr_runner.py"  # task-2510 (READ ONLY)
    - "utils/auto_gemini_triage.py"     # task-2511 (READ ONLY)
    - "utils/post_merge_smoke_runner.py"  # task-2512 (READ ONLY)
    - "utils/critical_escalation_reporter.py"  # task-2513 (READ ONLY)
    - "utils/merge_topology_gate.py"    # READ ONLY
    - "memory/orchestration-audit/merge-queue.jsonl"
    - "memory/orchestration-audit/critical-escalations.jsonl"
    - "memory/task-timers.json"
    - ".env.keys"
  paths:
    - "memory/tasks/task-2514*"
    - "memory/reports/task-2514*"
    - "memory/events/task-2514*"
    - "utils/merge_queue_executor.py"  # ★ wiring 대상 (modify)
    - "tests/regression/test_orchestration_runtime_2514.py"  # NEW
  forbidden_actions:
    - "새 abstraction 생성 (helper module / wrapper class / 신규 dataclass)"
    - "enum redesign"
    - "contract schema 변경 (utils/automation_contracts.py 수정)"
    - "policy md 보강"
    - "dispatch.py 대규모 리팩토링"
    - "merge topology rule 재설계 (utils/merge_topology_gate.py 수정)"
    - "runtime 범위 밖 개선 작업"
    - "5 모듈 본체 수정 (replacement_pr_runner / auto_gemini_triage / post_merge_smoke_runner / critical_escalation_reporter)"
    - "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 무시"
    - "task-2509 본체 인터페이스 breaking change"
```

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

1. ✅ runtime wiring 7건 (W1~W7) 모두 구현
2. ✅ end-to-end 회귀 14/14 PASS
3. ✅ 자동 처리 7항목 모두 runtime에서 자동 처리 (회장 보고 0건)
4. ✅ Critical 7종 발생 시에만 critical_escalation_reporter routing
5. ✅ Merge Topology Gate 자기참조 PASS (effective diff = 정확히 2 파일)
6. ✅ CI 11/11 SUCCESS
7. ✅ task-2509 CLI 인터페이스 breaking change 0건
8. ✅ amendment 보호 의무 명시 + 적용 evidence
9. ✅ **"사람 개입 없이 queue가 스스로 흐르는" runtime determinism 검증** (★ 회장 명시 성공 기준)

## 시스템 3문서 참조

- 정책 본체: `memory/feedback/feedback_critical_escalation_only_260508.md`
- 공통 계약: `utils/automation_contracts.py` (task-2509+2 freeze, READ ONLY)
- 5 모듈:
  - `utils/merge_queue_executor.py` (wiring 대상)
  - `utils/replacement_pr_runner.py` (READ ONLY)
  - `utils/auto_gemini_triage.py` (READ ONLY)
  - `utils/post_merge_smoke_runner.py` (READ ONLY)
  - `utils/critical_escalation_reporter.py` (READ ONLY)
- 실전 fixture: PR #54~#62 + #63/#64 (task-2503+1/2506/2507/2509/2509+1/2509+2/2510/2511/2512/2513) 전체 회귀

## 후행 task

본 task가 5 모듈 자동화의 **마지막 wiring**. 머지 후:
- 5 모듈 자동화 시스템 완성
- "회장 승인 없이 자동 처리 가능한 시스템" 실제 runtime 도달
- 후속은 운영 모니터링 + Critical 7종 발생 시 회장 보고만

## affected_files (auto-detected)
- utils/merge_queue_executor.py (modify, wiring)
- tests/regression/test_orchestration_runtime_2514.py (NEW)

## goal_assertions (auto-generated)
- `python3 utils/merge_queue_executor.py --pr <N> --dry-run --task-file <path>`
- `pytest tests/regression/test_orchestration_runtime_2514.py -q` → 14/14 PASS
- `pytest tests/regression/test_merge_queue_executor_2509.py -q` (회귀 보존)
- `pytest tests/regression/test_merge_queue_executor_review_gate_2509p1.py -q` (회귀 보존)