# task-2645 — DISPATCH_SPAWN_VERIFICATION_AND_PROMPT_LIMIT_GATE

- Level: Lv.4 (시스템 dispatch reliability + prompt-size gate + spawn verification · 3 모듈)
- 담당: 회장 결정 후 dispatch · 별도 worktree task-2645-{bot}
- base: origin/main 최신
- 단일소스 spec: 본 task md (회장 verbatim 전체)
- 사고 박제 단일소스: `memory/feedback_dispatch_false_ok_and_prompt_limit_misclassification_260524.md`
- 회장 결정 (2026-05-24 verbatim): task-2644 dispatch 사고 후속. dispatch.py false success 차단 + prompt-size gate verbatim 코드화 + silent drop spawn verification.

## 결함명 (회장 verbatim)
`DISPATCH_FALSE_OK_AND_PROMPT_LIMIT_MISCLASSIFICATION`

## 목적 (회장 verbatim)
- dispatch.py가 false success를 보고하지 못하게 한다
- prompt size 정책을 verbatim 기준으로 코드화한다
- silent drop을 spawn verification으로 즉시 감지한다

## 정책 verbatim (회장 4 구간)
1. **≤3200 bytes** = `OK_TARGET`
2. **3201~3499 bytes** = `OK_ABOVE_TARGET`
3. **3500~3900 bytes** = `WARNING_BUT_ALLOWED`
4. **>3900 bytes** = `HARD_BLOCK`
5. **4096 bytes** = cokacdir channel absolute limit (명시)
6. >3900 자동 path-only compact prompt mode 전환
7. dispatch.py cron_response=ok 단독 final success 처리 금지
8. `DISPATCH_SUBMITTED_UNVERIFIED` 상태 추가
9. spawn verification gate 추가

## 17 필수 구현 (회장 verbatim 1:1)
1. cron prompt UTF-8 byte classifier (4 구간 + absolute)
2. ≤3200 → `OK_TARGET`
3. 3201~3499 → `OK_ABOVE_TARGET`
4. 3500~3900 → `WARNING_BUT_ALLOWED`
5. >3900 → `HARD_BLOCK`
6. 4096 absolute channel limit 명시 (상수/주석)
7. prompt >3900 시 자동 path-only compact prompt mode (task md 경로 + sha256 만)
8. dispatch.py cron_response=ok 단독 final success 보지 않음 (gate downstream)
9. `DISPATCH_SUBMITTED_UNVERIFIED` 상태 enum 추가
10. spawn verification gate 추가
11. spawn verification 4 항목:
    - workspace dir exists (필수)
    - executor process or first activity signal
    - schedule visibility or schedule accepted marker
    - schedule_history absence는 작업 중/종료 후/미발사 분리 판정
12. spawn 확인 실패 시 `DISPATCH_SILENT_DROP_HOLD` 상태
13. 직접 cron workaround와 dispatch.py 결과 비교 fixture
14. 3270 bytes prompt **must be allowed** regression
15. 3901 bytes prompt **must be blocked** regression
16. 4096+ prompt silent drop fixture (실측: 673AA5A6 박제)
17. false dispatched report fails regression

## 4 spawn verification 항목 상세
| 항목 | 신호 | 의미 |
|---|---|---|
| workspace dir | `/home/jay/.cokacdir/workspace/<cron_id>/` 존재 | cokacdir 채널 등록은 됐음 |
| executor process | `ps -ef \| grep claude` neighbor process | 봇 spawn 실측 |
| schedule visibility | `cron-list` OR pending marker | 1회성 자동삭제 분리 판정 |
| schedule_history | `.log` 부재 = 3 상태 분리 (in-progress / 종료 / silent drop) | 단독 "log 미존재" 단정 금지 |

## 4신호 silent drop 확정 (모두 hit 시 `DISPATCH_SILENT_DROP_HOLD`)
1. workspace dir 빈 채
2. schedule_history log 부재
3. 봇 process 없음
4. cron-list 0개

## 자동 진행 허용
- byte classifier / spawn verification / fixture / regression 구현
- ANU-Codex loop 자동수렴
- 4 Track 병렬 fan-out 가능

## 자동 진행 금지 (회장 verbatim 6)
- task-2644 ↔ task-2645 혼합 금지
- live settings.json 수정 금지
- live cokacdir 수정 금지
- ANU 직접 CI/Gemini polling 금지
- BOT App token / chair_authorization / real auto-merge / PR #141 pilot 금지
- merge execution 금지

## expected_files (task-2645 범위 · ~25 file 추정)
- utils 3 (prompt_byte_classifier.py + spawn_verifier.py + dispatch_status_enum.py)
- dispatch.py 수정 (status 전이 / spawn gate 호출)
- schemas 2 (dispatch_status_v1.json + spawn_verification_result_v1.json)
- fixtures 6 (3270 allow / 3901 block / 4096+ silent drop / spawn 성공 / spawn 실패 silent drop / dispatch.py false-ok 재현)
- regression 7 (각 fixture × classifier + spawn_verifier + dispatch gate 통합)
- task md / report / done event / INDEX

## finalize 프로토콜 (★ BOT App token 부재 — 로컬 한정)
1. base = origin/main 최신 clean
2. 신규 helper + schema + fixture + regression PASS · 기존 baseline 유지
3. **로컬 commit 만** (push/PR/merge 금지)
4. `/home/jay/workspace/memory/events/task-2645.done` 생성
5. `/home/jay/workspace/memory/reports/task-2645.md` 보고서 작성
6. ANU normal callback cron 강제 등록:
   - collector key: c119085addb0f8b7 (ANU · executor self-key 금지)
   - envelope UTF-8 ≤3900 bytes (wc -c)
   - canonical_root=/home/jay/workspace
   - REGISTERED + schedule_id non-null + DELIVERED + UNCONFIRMED
   - result.json 9 필드 (callback_prompt_utf8_bytes 등)
7. validate_spawn_callback_contract self-check
8. executor 시작/종료 ts + 로컬 commit SHA 명기

## 회장 보고 형식 (10 필드 1:1)
- branch:
- commit:
- changed files count:
- classifier implementation:
- spawn verification 4-item:
- regression 17 item coverage:
- DISPATCH_SUBMITTED_UNVERIFIED state:
- DISPATCH_SILENT_DROP_HOLD state:
- live infra modified: (★ 0 보장)
- forbidden action count: (★ 0 보장)

## frozen anchor (회장 verbatim)
- ANCHOR-1: "dispatch.py cron_response=ok ≠ spawn 성공 — DISPATCH_SUBMITTED_UNVERIFIED 거쳐야 함"
- ANCHOR-2: "prompt byte 4 구간 + 4096 absolute · 측정 wc -c · ≤3900 hard limit"
- ANCHOR-3: "spawn verification 4 항목 + silent drop 4신호 모두 hit"
- ANCHOR-4: "3270 bytes allowed regression · 3901 bytes blocked regression · 4096+ silent drop fixture"
- ANCHOR-5: "task-2644 ↔ task-2645 혼합 0 · live infra 수정 0"

## allowed_resources (본 task의 capability)

```yaml
allowed_resources:
  paths:
    - "utils/prompt_byte_classifier.py"
    - "utils/dispatch_spawn_verifier.py"
    - "utils/dispatch_status_enum.py"
    - "dispatch.py"
    - "schemas/dispatch_status_v1.json"
    - "schemas/spawn_verification_result_v1.json"
    - "tests/fixtures/dispatch_gate/**"
    - "tests/regression/dispatch_gate/**"
    - "tests/test_prompt_byte_classifier*.py"
    - "tests/test_dispatch_spawn_verifier*.py"
    - "tests/test_dispatch_status_enum*.py"
    - "tests/test_dispatch_gate_integration*.py"
    - "memory/tasks/task-2645.md"
    - "memory/reports/task-2645.md"
    - "memory/events/task-2645.done"
    - "INDEX.md"
  forbidden_paths:
    - "/home/jay/.claude/settings.json"
    - "/home/jay/.claude/settings.local.json"
    - "/usr/local/bin/cokacdir"
    - ".github/**"
    - "memory/events/*.cron-*"
    - "memory/tasks/task-2644*"
    - "memory/tasks/task-2643*"
    - "memory/tasks/task-2641*"
    - "memory/tasks/task-2642*"
    - "memory/specs/system_anu_callback_collector_control_plane_spec_260524.md"
    - "memory/specs/system_real_merge_executor_wiring_spec_260523.md"
    - "scripts/finish-task.sh"
    - "utils/replacement_pr_runner.py"
    - "hooks/**"
    - "**/.env*"
    - "**/credentials*"
  commands:
    - "pytest"
    - "python3 -m py_compile"
    - "python3 -m json.tool"
    - "git status"
    - "git diff"
    - "git add"
    - "git commit"
    - "git log"
    - "git checkout"
    - "git branch"
    - "git worktree"
    - "sha256sum"
    - "wc"
    - "printf"
    - "ls"
    - "grep"
    - "find"
  merge_policy: "local_only"
  ttl_hours: 72
```

끝
