# task-1551.1 완료 보고서: 팀장 봇 기본 모델 Sonnet 전환 + Critical 시 Opus 자동 승격

**팀**: dev5-team (마르둑)
**작업일**: 2026-04-08
**검증 레벨**: normal

---

## SCQA

**S**: 팀장 봇 8개 전원이 claude-opus-4-6으로 설정되어 있어 Opus 토큰 사용이 주간 79%에 달하며, Sonnet 한도는 6%만 사용 중이다.

**C**: 팀장이 수행하는 작업(지시서 실행, subagent 호출, 보고서 작성)은 Sonnet으로 충분함에도 Opus 토큰이 편중 소모되어 복잡한 작업(Lv.3 한정승인 등)에서 Opus 한도 부족 위험이 있다.

**Q**: 팀장 봇의 기본 모델을 Sonnet으로 전환하고, critical/security 레벨에서만 Opus를 자동 사용하는 메커니즘을 구현할 수 있는가?

**A**: bot_settings.json에서 8개 팀장 봇의 모델을 claude-sonnet-4-6으로 변경하고, dispatch.py에 critical/security 레벨 시 임시 Opus 승격 + 자동 복원 로직을 구현하였다. pytest 167건 전체 통과, 회귀 없음. 예상 Opus 사용량 약 50~60% 감소.

---

## 변경 내역

### 변경 1: bot_settings.json 모델 변경
- **파일**: `/home/jay/.cokacdir/bot_settings.json`
- **변경**: 8개 팀장 봇의 models 값 `claude-opus-4-6` → `claude-sonnet-4-6`
- **대상 봇**: dev1_hermes, dev2_odin, dev3_dagda, dev4_vishnu, dev5_marduk, dev6_perun, dev7_itzamna, dev8_ra
- **제외**: 아누(ai_dev_server_bot) — Opus 유지
- **동기화**: `bot_settings_sync.json` 및 `config/constants.json` 자동 동기화 완료

### 변경 2: dispatch.py Opus 자동 승격 로직
- **파일**: `/home/jay/workspace/dispatch.py`
- **신규 함수**:
  - `_set_bot_model(key_hash, model, chat_id)` (line 466~499): bot_settings.json에서 특정 봇의 모델을 변경하고 이전 모델 반환
  - `_schedule_model_restore(key_hash, model, delay)` (line 502~520): delay초 후 모델을 복원하는 백그라운드 프로세스 포크
- **dispatch() 함수 수정** (3곳):
  - cokacdir 호출 전 (line 1951~1962): `level in ("critical", "security")`일 때 Opus로 승격
  - 성공 시 (line 1991~1993): 30초 후 Sonnet으로 복원 예약
  - 실패 시 (line 2083~2086): 즉시 Sonnet으로 복원

### 변경 3: organization-structure.json 동기화
- **파일**: `/home/jay/workspace/memory/organization-structure.json`
- **변경**: 8개 dev 팀장의 lead.model 값 `claude-opus-4-6` → `claude-sonnet-4-6`
- **라인**: 391, 473, 555, 616, 677, 738, 799, 860

---

## 생성/수정 파일 목록

- `/home/jay/.cokacdir/bot_settings.json` — 8개 봇 모델 변경
- `/home/jay/workspace/dispatch.py` — _set_bot_model, _schedule_model_restore 추가 + dispatch() 승격 로직
- `/home/jay/workspace/memory/organization-structure.json` — 8개 팀장 model 필드 변경
- `/home/jay/workspace/memory/bot_settings_sync.json` — 자동 동기화
- `/home/jay/workspace/config/constants.json` — 자동 동기화

---

## 테스트 결과

- **기존 테스트**: pytest tests/test_dispatch.py → 167 passed (회귀 없음)
- **_set_bot_model round-trip 테스트**: sonnet → opus → sonnet 변환 및 복원 정상
- **_read_bot_models 검증**: 8개 봇 sonnet, 아누 opus 확인
- **JSON 유효성**: bot_settings.json, organization-structure.json 모두 정상 파싱
- **구문 검증**: dispatch.py ast.parse() 통과

---

## 발견 이슈 및 해결

### 자체 해결 (3건)
1. **bot_settings_sync.json 동기화 순서** — bot_settings.json 변경 후 sync 함수 수동 실행하여 즉시 동기화 완료
2. **_schedule_model_restore에서 CHAT_ID 참조** — 모듈 레벨 상수를 f-string으로 직접 임베딩하여 백그라운드 프로세스에서 import 없이 동작하도록 구현
3. **디스패치 실패 시 모델 복원** — else 블록에 즉시 복원 로직 추가하여 orphan Opus 설정 방지

---

## 셀프 QC

- [x] 1. 영향 파일: bot_settings.json, dispatch.py, organization-structure.json, bot_settings_sync.json, constants.json
- [x] 2. 엣지 케이스: 이미 Opus인 봇에 critical dispatch (변경 스킵), bot_settings.json 없는 경우 (None 반환), 디스패치 실패 시 (즉시 복원)
- [x] 3. 작업 지시와 정확히 일치: 8개 봇 Sonnet 전환 + critical/security Opus 승격 + 조직도 동기화
- [x] 4. 에러 처리: _set_bot_model에 try/except, None 반환 시 승격 스킵
- [x] 5. 테스트 커버리지: 기존 167건 회귀 없음 + round-trip 수동 테스트
- [x] 6. 발견 이슈 3건 모두 직접 해결
- [x] 7. SOLID/DRY: 모델 변경 로직을 _set_bot_model로 분리, 복원 로직을 _schedule_model_restore로 분리
- [x] 8. 인터페이스 변경: dispatch() 시그니처 변경 없음. 신규 내부 함수 2개 추가

---

## 모델 사용 기록

- 엔키(백엔드) / dispatch.py 수정 / sonnet
- 엔키(백엔드) / bot_settings.json 변경 / sonnet
- 엔키(백엔드) / organization-structure.json 변경 / sonnet
