<!-- task=m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle plan=0 tag=API milestone-task=route-observability -->

# Raw-free Hot Path lifecycle wiring

## For the Implementing Agent

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

## Background

Child 18의 closed schema를 admission, stage attempts/transitions, terminal, cleanup, orphan responsibility에 연결해 one logical request lifecycle을 만들고 raw-free cardinality guarantees를 실제 경로에서 검증한다.

## 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_light.go`
- `apps/edge/internal/openai/hot_path_cleanup.go`
- `apps/edge/internal/openai/hot_path_cleanup_test.go`
- `agent-test/local/rules.md`

### SDD Criteria

- 승인 SDD, `milestone-task=route-observability`, S15.
- request/preset/mode/stage/attempt, route reason, timing, terminal, cleanup/orphan lifecycle correlation과 actual-path raw/secret absence가 oracle이다.

### Verification Context

- in-memory zap observer and Prometheus collector provide deterministic evidence; no backend is required.

### Test Coverage Gaps

- schema projection tests alone do not prove every lifecycle boundary, join order, exactly-once counter, or failure isolation.

### Symbol References

- no rename/remove; use predecessor typed schema only.

### Split Judgment

- stable contract: Hot Path lifecycle boundaries → child 18 observation schema.
- schema construction is predecessor 18; dashboard/backend/smoke are excluded.

### Scope Rationale

- no durable store, new observation sink contract, raw payload hashing, dashboard, or alert.

### Final Routing

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

## Implementation Checklist

- [ ] [API-1] Wire the predecessor observation schema across admission, stage attempts/transitions, terminal, cleanup, and orphan responsibility while isolating observation failure from request behavior.
- [ ] [API-2] Add lifecycle joins, ordering, cardinality, exactly-once, and seeded raw/secret absence regressions and run the child verification commands.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [API-1] Lifecycle emission wiring

**Problem:** generic dispatch logs do not join one Hot Path request across route, stage, terminal, and cleanup boundaries.

**Solution:** Emit the predecessor typed event at admission, dispatch start/end, transition, terminal, cleanup result, and TTL/orphan handoff. Normalize timing/outcome/reason, keep high-cardinality ids log-only, and isolate log/metric failures from request semantics.

**Modified Files and Checklist:**

- [ ] Modify `apps/edge/internal/openai/hot_path_dispatch.go` at admission/dispatch/transition boundaries.
- [ ] Modify `apps/edge/internal/openai/hot_path_light.go` at review/repair attempt transitions.
- [ ] Modify `apps/edge/internal/openai/hot_path_cleanup.go` at terminal/cleanup/orphan boundaries.

**Test Strategy:** API-2 exercises direct success, light pass/repair, provider error, cancel, cleanup failure, and orphan responsibility.

**Verification:** `go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPath(ObservationLifecycle|ObservationRejectsRawValues|Metric)'` exits 0.

### [API-2] Lifecycle and raw-free evidence

**Problem:** S15 needs actual-path positive lifecycle evidence and negative sentinel evidence.

**Solution:** Capture all emitted records/metrics for the scenario rows. Assert attempt ordering, request-stage joins, bounded timing bucket, terminal/cleanup responsibility, exactly-once counters, failure isolation, and absence of seeded prompt/output/tool/header/credential/error values.

**Modified Files and Checklist:**

- [ ] Extend `apps/edge/internal/openai/hot_path_observation_test.go` with `TestHotPathObservationLifecycle` and actual-path redaction/cardinality rows.
- [ ] Fill `agent-task/m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle/CODE_REVIEW-cloud-G09.md`.

**Test Strategy:** compare ordered event classes and exact projected keys/labels; use no external backend.

**Verification:** run Final Verification; all lifecycle rows pass.

## Dependencies and Execution Order

1. `17+14,15,16_endpoint_error_matrix` must produce its active `complete.log`.
2. `18+17_observation_schema` must produce its active `complete.log`.
3. 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_light.go` | API-1 |
| `apps/edge/internal/openai/hot_path_cleanup.go` | API-1 |
| `apps/edge/internal/openai/hot_path_observation_test.go` | API-2 |
| `agent-task/m-iop-hot-path-one-shot-execution/19+17,18_observation_lifecycle/CODE_REVIEW-cloud-G09.md` | API-2 |

## Final Verification

```bash
go test -race -count=1 ./apps/edge/internal/openai -run 'TestHotPathObservation|TestHotPathMetric|TestHotPath(EndpointTerminalMatrix|CancelCompleteRace|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, joined raw-free lifecycle, bounded metrics, no sentinel/credential value, empty diff check. Cached output is not acceptable.

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