# task-2724+2 — terminal_state_callback robustness fix: DEFAULT_ANU_KEYS empty StopIteration 방어 (회장 B안 승인, 마지막 bounded round)

## 회장 인가 (2026-06-03, B안 — bounded robustness fix)
PR #170(head `b7ad94d4`) 잔여 Gemini HIGH: `_register_callback` 의 `owner_key = next(iter(DEFAULT_ANU_KEYS))` 가 `DEFAULT_ANU_KEYS` 공백 시 `StopIteration` → emit 중간 crash → terminal envelope/marker 미생성. **terminal_state_callback 은 실패/차단 통지 안전망 코드 → key set 비정상에서도 죽으면 안 됨.** 1줄 방어 가드로 종결.
★ **task-2724 의 마지막 bounded robustness fix.** 이후 새 HIGH/CRITICAL → 추가 patch loop 금지 → CHAIR_REQUIRED.

## worktree
- branch `task/task-2724-dev1` (head `b7ad94d4`, origin push 됨)에서 **이어서**. new head → non-force push. PR #170 갱신.

## 허용 파일 (회장 명시 — finish-task.sh 추가 수정 금지)
1. `scripts/harness/v36/terminal_state_callback.py` ← 주 수정 (방어 가드)
2. `tests/regression/test_terminal_state_callback_2724.py` ← 방어 회귀 추가
- ★ `scripts/finish-task.sh` **추가 수정 금지** (hook 이미 충분 — line 35 1줄 flag-guarded). diff 에 finish-task.sh 변경 0.

## 수정 방향 (회장 6)
1. `next(iter(DEFAULT_ANU_KEYS))` 가 **StopIteration 불가**하도록 default/fallback 방어. 예: `owner_key = next(iter(DEFAULT_ANU_KEYS), None)` (또는 `if DEFAULT_ANU_KEYS else None`).
2. `DEFAULT_ANU_KEYS` 공백(비정상) 시 emitter **crash 0** → fail-open 또는 **NOT_REGISTERED / NO_OWNER_KEY 계열 terminal result** 명확 기록. (owner_key None → launch_callback 미호출 또는 argv None 경로로 fail-closed marker, envelope 는 디스크에 남김).
3. 기존 self-key guard / owner 검증 / argv 존재 확인 / sendfile-only 금지 원칙 **유지**.
4. `TERMINAL_CALLBACK_ENABLED` default-off **유지**.
5. 테스트/스모크 실제 cron 등록 **0 유지**.
6. ANU key literal source 노출 **0 유지** (sealed import, test negative-assertion 제외).

## 필수 검증 (회장 10)
1. `DEFAULT_ANU_KEYS` 정상 1원소 상태 → 기존 registration flow 유지(회귀 무손상).
2. `DEFAULT_ANU_KEYS` empty mock 상태 → **StopIteration 0** (crash 없음).
3. empty key 상태 → 실제 cron 등록 **0**.
4. envelope/registration marker 가 fail-closed 또는 `NOT_REGISTERED`/`NO_OWNER_KEY` 상태 **명확 기록**.
5. 기존 19 regression 유지.
6. `git diff --name-only origin/main` = expected_files **3파일 내부** (terminal_state_callback.py + test + 보고/done; finish-task.sh 변경 0).
7. **finish-task hook 추가 변경 0**.
8. `TERMINAL_CALLBACK_ENABLED` default-off 유지.
9. test cron registration 0.
10. ANU key literal source 노출 0.
- smoke: `python3 -m pytest tests/regression/test_terminal_state_callback_2724.py -q` + `bash -n scripts/finish-task.sh`(무변경 확인).

## 금지 (회장 verbatim)
- merge / TERMINAL_CALLBACK_ENABLED 활성화 / pilot / actual terminal callback 운영 적용 / systemctl·activation·wake 금지.
- **finish-task.sh 추가 수정 금지** · expected_files 밖 수정 금지 · task-2725 혼입 금지 · PR #169 commit 금지 · force push·rebase·admin override 금지.

## doctrine
- same-PR post-Gemini push 금지(robustness fix = 새 commit→new head→non-force push). bot `/gemini review` 무효(인간 OWNER 1회). long polling 금지(watcher 위임).

## finalize (PR #170 갱신 → MERGE_READY_CANDIDATE — merge 금지)
1. fix → 10 검증 PASS → `git add` → commit → **non-force push**(PR #170 갱신).
2. `memory/reports/task-2724.md` 갱신(robustness + L1). 3. `memory/events/task-2724+2.done` 생성.
4. ANU normal callback cron 강제 등록 — collector_role=ANU, ANU_KEY=c119085addb0f8b7(sealed, literal 노출 금지). self-key 금지. cron 0+sendfile only=NOT_REGISTERED fail-closed.
5. ★ merge 금지 — ANU/watcher 가 새 head OWNER /gemini review → CI/Gemini watcher → CI GREEN + fresh unresolved 0 + diff 3파일 + forbidden 0 + ANU key 0 + flag default-off + test cron 0 시 MERGE_READY_CANDIDATE 보고.

## allowed_resources
```yaml
allowed_resources:
  paths:
    - "scripts/harness/v36/terminal_state_callback.py"
    - "tests/regression/test_terminal_state_callback_2724.py"
    - "memory/reports/task-2724.md"
    - "memory/events/task-2724+2.done"
  forbidden_paths:
    - "scripts/finish-task.sh"
    - "teams/shared/verifiers/critical_gap.py"
    - "dispatch/normal_fallback_callback_helper.py"
    - "deploy/systemd/**"
    - ".github/**"
  commands:
    - "pytest"
    - "python3 -m pytest"
    - "python3 -m py_compile"
    - "bash -n"
  merge_policy: "none"
  ttl_hours: 48
```

## goal_assertions (auto)
- `python3 -m pytest tests/regression/test_terminal_state_callback_2724.py -q`
- `python3 -c "import sys; s=open('scripts/harness/v36/terminal_state_callback.py').read(); sys.exit(1 if 'c119085addb0f8b7' in s else 0)"`
- `python3 -c "import sys; s=open('scripts/harness/v36/terminal_state_callback.py').read(); sys.exit(0 if 'next(iter(DEFAULT_ANU_KEYS), ' in s or ('if DEFAULT_ANU_KEYS' in s) else 1)"`

## 상태
CHAIR_APPROVED_B_ROBUSTNESS_FIX (task-2724 마지막 bounded round) — dev1 재위임. 이후 새 HIGH/CRITICAL → CHAIR_REQUIRED(patch loop 금지). flag on/activation/pilot = merge 이후 별도 승인.