<!-- task=m-iop-hot-path-one-shot-execution/13+12_outer_turn_integration plan=0 tag=API milestone-task=terminal-control -->

# Hot Path outer-turn direct/light integration

## For the Implementing Agent

구현 후 `CODE_REVIEW-cloud-G09.md`의 구현 담당 섹션에 실제 변경·검증 출력을 채우고 active 파일을 유지한다. 차단 시 정확한 blocker/명령/출력/재개 조건만 기록하고 사용자 질문, archive, `complete.log` 작성은 하지 않는다.

## Background

Child 12가 만드는 protocol-neutral outer-turn core를 selector/direct/light stage lifecycle에 연결하고 compatibility codec으로 기존 완료 응답을 보존해야 endpoint child가 live codec을 안전하게 연결할 수 있다.

## Archive Evidence Snapshot

- Archived predecessor 10/11은 child 12의 선행 evidence다.
- 이 child는 active predecessor `12+10,11_outer_turn_core/complete.log`가 생성된 뒤 시작한다.

## Analysis

### Files Read

- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-hot-path-one-shot-execution/SDD.md`
- `apps/edge/internal/openai/hot_path_dispatch.go`
- `apps/edge/internal/openai/hot_path_direct.go`
- `apps/edge/internal/openai/hot_path_light.go`
- `apps/edge/internal/openai/hot_path_cleanup.go`
- `apps/edge/internal/openai/hot_path_direct_test.go`
- `apps/edge/internal/openai/hot_path_light_test.go`
- `apps/edge/internal/openai/hot_path_cleanup_test.go`
- `agent-test/local/rules.md`

### SDD Criteria

- 승인 SDD, `milestone-task=terminal-control`, S10.
- 이 child는 one outer turn across direct/light stage transitions, compatibility response equivalence, terminal stop, and no nested response-start evidence에 기여한다.

### Verification Context

- fresh `-race -count=1` unit/integration results are required; external runtime is not required.

### Test Coverage Gaps

- core와 기존 direct/light/cleanup 경로가 같은 turn을 공유하고 pre-endpoint bytes/state가 동등한지 검증하는 fixture가 없다.

### Symbol References

- existing public symbols are not renamed or removed.

### Split Judgment

- stable contract: outer-turn core → selector/direct/light lifecycle through compatibility codec.
- Core construction/race is child 12, Anthropic/Chat wire is child 14/15.

### Scope Rationale

- endpoint encoding, endpoint error matrix, observability, actual smoke are excluded.

### Final Routing

- evaluation_mode=isolated-reassessment, finalizer=`finalize-task-policy.sh pair`.
- build closures 모두 true, scores=2/2/1/1/2, G08, risks=`temporal_state,concurrent_consistency,boundary_contract,variant_product`(4), risk-boundary → `PLAN-cloud-G08.md`.
- review closures 모두 true, scores=2/2/1/2/2, G09, official-review → `CODE_REVIEW-cloud-G09.md`.
- `large_indivisible_context=false`, recovery=0/false, capability gap 없음.

## Implementation Checklist

- [ ] [API-1] Feed selector/direct/light stages through one predecessor outer turn and preserve completed-response behavior through the compatibility codec.
- [ ] [API-2] Add direct/light transition, compatibility, stop-after-terminal, and cleanup regression evidence and run the child verification commands.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [API-1] Direct/light lifecycle integration

**Problem:** selector, direct, and light collection currently complete independently and do not share the outer turn.

**Solution:** Adapt selector and subsequent stage collection to feed the predecessor decoder/codec pair. Keep structural route/tool classification internal, retain one turn across local→review/repair transitions, convert Core terminal results into transition decisions, and stop after cancel/terminal. Use the compatibility codec until endpoint children replace it.

**Modified Files and Checklist:**

- [ ] Modify `apps/edge/internal/openai/hot_path_dispatch.go` to feed selector/subsequent stages into one outer turn.
- [ ] Modify `apps/edge/internal/openai/hot_path_direct.go` to use the shared turn through the compatibility codec.
- [ ] Modify `apps/edge/internal/openai/hot_path_light.go` to retain the turn across local/review/repair and stop after terminal.

**Test Strategy:** API-2 extends existing direct/light/cleanup regressions.

**Verification:** `go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(OuterTurnCompatibility|Direct|Light|Cleanup)'` exits 0.

### [API-2] Compatibility and transition evidence

**Problem:** no test proves shared-turn compatibility across direct/light stage transitions.

**Solution:** Add compatibility-equivalence and multi-stage transition rows proving one response-start, stable state/bytes before endpoint integration, ordered continuation, and no stage work after terminal/cancel.

**Modified Files and Checklist:**

- [ ] Extend `apps/edge/internal/openai/hot_path_terminal_control_test.go` with `TestHotPathOuterTurnCompatibility` and direct/light transition fixtures.
- [ ] Record output in `agent-task/m-iop-hot-path-one-shot-execution/13+12_outer_turn_integration/CODE_REVIEW-cloud-G09.md`.

**Test Strategy:** preserve existing direct/light/cleanup behavior and assert exact transition order.

**Verification:** run Final Verification; all commands exit 0 without race.

## Dependencies and Execution Order

1. `12+10,11_outer_turn_core` must produce `agent-task/m-iop-hot-path-one-shot-execution/12+10,11_outer_turn_core/complete.log`.
2. Implement API-1, then API-2.

## Modified Files Summary

| File | Item |
|---|---|
| `apps/edge/internal/openai/hot_path_dispatch.go` | API-1 |
| `apps/edge/internal/openai/hot_path_direct.go` | API-1 |
| `apps/edge/internal/openai/hot_path_light.go` | API-1 |
| `apps/edge/internal/openai/hot_path_terminal_control_test.go` | API-2 |
| `agent-task/m-iop-hot-path-one-shot-execution/13+12_outer_turn_integration/CODE_REVIEW-cloud-G09.md` | API-2 |

## Final Verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(OuterTurnCompatibility|Direct|Light|Cleanup)'
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
git diff --check
```

Expected: exit 0, compatible direct/light behavior, one outer response lifecycle, no race/post-terminal work, empty diff check. Cached output is not acceptable.

After completing all code changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
