---
task_id: task-2152
type: context
scope: task
created: 2026-04-24
updated: 2026-04-24
status: in-progress
---

# 맥락 노트: task-2152

**task**: task-2152

---

## 결정 근거

### Codex 리스크 6건 반영
- Codex 사전 검증에서 critical 2건, high 3건, medium 1건 발견
- 모두 설계에 반영하여 재설계 완료

### 1. set +e subshell 격리 (critical)
- **결정**: 각 게이트를 `set +e` 블록으로 감싸 exit code 캡처
- **대안**: subshell `()` 사용 → 변수가 상위 스코프로 전달 안 됨. 기각
- **Why**: finish-task.sh가 `set -euo pipefail`로 실행되므로, impact_scanner exit 1/2가 스크립트를 즉시 종료

### 2. task-timer.py gate_results 보존 (critical)
- **결정**: _write_event_file에서 기존 .done의 추가 필드(gate_results, status, completed_at) merge
- **대안**: .done 쓰기 순서를 task-timer 이후로 재배치 → finish-task.sh 흐름 변경이 크고 멱등성 깨질 위험. 기각
- **Why**: task-timer.py가 .done을 덮어쓰면 Step 3에서 추가한 gate_results가 유실

### 3. 변수 초기화 (high)
- **결정**: PROJ_DIR, COMMIT_COUNT를 Git 게이트 블록 바깥에서 초기화
- **Why**: non-code task로 Git 게이트가 skip되면 `set -u` 환경에서 미정의 변수 에러

### 4. Goal Assertions allowed_commands 검증 (high)
- **결정**: eval 전에 명령의 첫 단어를 gate-config.json의 allowed_commands에서 검증
- **Why**: 임의 쉘 명령 실행 방지

### 5. ci_preflight exit code 3단계 매핑 (high)
- **결정**: exit 0=PASS, 1=FAIL, 2=WARN으로 매핑
- **Why**: 실제 ci_preflight.sh는 timeout 시 exit 2 반환 (문서와 상이)

### 6. l1_smoketest 결과 수집 (medium)
- **결정**: .qc-result 파일의 checks_summary에서 l1_smoketest_check 결과 추출
- **Why**: l1_smoketest 수집 로직이 누락되면 gate_results 스키마 불완전

## 3 Step Why 자문

1st Why: "왜 이 설계가 필요한가?" → P1에서 완료된 5개 품질 게이트를 finish-task.sh에 통합해야 .done 생성 전 자동 검증이 수행됨
2nd Why: "왜 finish-task.sh 통합이 최선인가?" → finish-task.sh가 유일한 .done 생성 경로이므로 여기에 삽입하면 우회 불가능한 강제 게이트가 됨
3rd Why: "왜 Codex 리스크 반영 방식이 다른 대안보다 나은가?" → set +e subshell + allowed_commands 검증 + task-timer.py merge 방식은 기존 코드 최소 변경으로 안전성 확보

## 참조 자료

- task 파일: `/home/jay/workspace/memory/tasks/task-2152.md`
- gate-config.json: `/home/jay/workspace/config/gate-config.json`
- finish-task.sh: `/home/jay/workspace/scripts/finish-task.sh`
- task-timer.py: `/home/jay/workspace/memory/task-timer.py`
- gate_config_loader.py: `/home/jay/workspace/utils/gate_config_loader.py`
- impact_scanner.py: `/home/jay/workspace/scripts/impact_scanner.py`
- ci_preflight.sh: `/home/jay/workspace/scripts/ci_preflight.sh`

## 주의사항

- finish-task.sh의 `set -euo pipefail` 환경 필수 고려
- Step 2.6, 2.6.5는 Git 게이트(Step 2.5) 이후 위치이므로 PROJ_DIR/COMMIT_COUNT 의존
- Step 2.11, 2.12는 Codex 게이트(Step 2.10) 이후 위치
- task-timer.py 수정은 기존 qc_result 보존 로직과 호환 필수
