# task-1243.1 완료 보고서: 봇 충돌 방지 강화 — composite 진행 중 dev팀 위임 차단 v2

## SCQA

**S**: dispatch.py의 봇 충돌 방지 코드(task-1223.1에서 구현)가 배포되어 있으며, 단위 테스트 126건이 통과 중이다.

**C**: 그러나 composite task-1241.1이 bot-c를 점유 중임에도 task-1242.1이 dev2-team(bot-c)에 배정되었다. `_get_busy_bots_info()`가 task-timers.json을 읽을 때 **새 태스크의 timer entry가 composite entry를 dict에서 덮어쓰면서** 충돌 검사가 자기 자신을 감지하여 통과하는 버그가 원인이다.

**Q**: 봇 충돌 검사가 모든 경로에서 확실하게 작동하도록 보장할 수 있는가?

**A**: `_get_busy_bots_info()`에 `exclude_task_id` 파라미터를 추가하여 현재 태스크의 timer entry를 검사 대상에서 제외. 133건 테스트 전체 통과(기존 126건 + 신규 7건), 핵심 회귀 시나리오(composite bot-c + dev2-team timer entry 공존) 커버 완료.

## 원인 분석

dispatch() 실행 순서:
1. timer start (line 924) → task-timers.json에 `{task_id: {team_id: "dev2-team", status: "running"}}` 기록
2. bot conflict check (line 1046) → `_get_busy_bots_info()` 호출
3. `_get_busy_bots_info()` 내부에서:
   - composite task-1241.1: bot="bot-c" → `busy["bot-c"] = {task-1241.1}`
   - 새 task-1242.1: dev2-team → TEAM_TO_BOT_ID → bot-c → `busy["bot-c"] = {task-1242.1}` (덮어쓰기)
4. conflict check: `conflict_task_id == task_id` → 자기 자신 → 충돌 미감지

## 수정 내용

### dispatch.py

1. `_get_busy_bots_info(exclude_task_id)` 파라미터 추가 (line 184)
   - `exclude_task_id`와 일치하는 task entry는 결과에서 제외
   - 기본값 None으로 기존 호출(`_find_available_bot` 등) 호환
2. 봇 충돌 검사에서 `exclude_task_id=task_id` 전달 (line 1046)
3. 충돌 검사 시작/통과 로깅 추가 (line 1047-1050, 1070-1071)

### tests/test_dispatch.py

- `TestGetBusyBotsInfoExclude` 클래스 (4개 테스트): exclude_task_id 동작 검증
- `TestBotConflictWithTimerEntry` 클래스 (3개 테스트): timer entry 존재 시 충돌 감지 회귀 테스트

### memory/specs/bot-team-mapping.md

- v2.1: 봇 충돌 방지 규칙 섹션 추가

## 산출물

- `/home/jay/workspace/dispatch.py`
- `/home/jay/workspace/tests/test_dispatch.py`
- `/home/jay/workspace/memory/specs/bot-team-mapping.md`

## 테스트 결과

- pytest: 133건 전체 통과 (0.86초)
- 기존 126건: 회귀 없음
- 신규 7건: 모두 통과
  - test_exclude_removes_own_entry
  - test_exclude_keeps_other_entries
  - test_exclude_none_returns_all
  - test_exclude_prevents_overwrite_of_composite_entry
  - test_composite_conflict_detected_despite_own_timer_entry
  - test_dynamic_bot_on_dev_team_bot_blocks
  - test_force_bypasses_conflict_with_timer_entry

## 발견 이슈 및 해결

### 자체 해결 (3건)
1. **timer start가 conflict check보다 먼저 실행되어 자기 자신의 entry가 composite entry를 덮어쓰는 버그** — `exclude_task_id` 파라미터로 자기 자신 제외
2. **봇 충돌 검사 로깅 부재로 디버깅 어려움** — `[봇 충돌 검사]` 접두사 INFO 로그 추가
3. **bot-team-mapping.md에 충돌 방지 규칙 미문서화** — v2.1로 규칙 섹션 추가

### 범위 외 미해결 (0건)
없음.
