<!-- task=m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct plan=3 tag=REVIEW_API milestone-task=route-selector,direct-flow -->

# Code Review Reference - REVIEW_API

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> The task is NOT complete until every implementation-owned section below is filled in.
> Complete the `Implementation Checklist`; the final checklist item is mandatory before saving.
> Fill implementation-owned sections, then stop with active files in place and report ready for official review.
> If implementation is blocked, record the exact blocker, attempted commands/output, and resume condition only in implementation-owned evidence fields.
> Do not ask the user directly, present choices, call user-input tools, create control-plane stop files, or classify the next state.
> Finalization (`Code Review Result`, log rename, `complete.log`, archive moves, `Review-Only Checklist`) is review-agent-only, even after compaction/resume.
> Follow the ownership table at the bottom of this file for which sections you own.

## Overview

date=2026-08-03
task=m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct, plan=3, tag=REVIEW_API

## Archive Evidence Snapshot

- Prior plan: `agent-task/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/plan_cloud_G08_2.log`.
- Prior review: `agent-task/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/code_review_cloud_G08_2.log`.
- Verdict: FAIL with 3 Required, 0 Suggested, and 0 Nit findings.
- Required closure: document the authorized virtual-preset Hot Path exception while preserving ordinary raw relay; update the Chat virtual-preset fixture with complete pinned gate evidence; add the missing Messages SSE no-provider-ID regression.
- Affected files: OpenAI/Anthropic API contracts, the living input-surface spec, and the Anthropic native, principal route, and direct Hot Path regressions.
- Verification evidence: the focused selector/direct suite passed, but the targeted legacy contract suite, common race suite, and full Edge suite failed because virtual-preset tests still expected provider-native raw bytes, pre-start BODY/END acceptance, or used an incomplete selector candidate.
- Roadmap carryover: `route-selector,direct-flow`; SDD S03 requires structural hard-gate evidence and S07 requires endpoint-native direct completion without internal artifact or transport metadata exposure.

## For the Review Agent

> **[REVIEW AGENT ONLY]** The finalization steps below are review-agent only. Implementing agents must not execute this section.

Compare implementation of each item against source files and verify that output in `Verification Results` matches code.
Review completion means the following steps are finished:

1. Append verdict and `review_rework_count` / `evidence_integrity_failure` routing signals.
2. Archive `CODE_REVIEW-cloud-G08.md` → `code_review_cloud_G08_3.log` and `PLAN-cloud-G08.md` → `plan_cloud_G08_3.log`.
3. If PASS, write `complete.log` and move active task directory to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/`. If WARN/FAIL, fully write the next filesystem state required by the code-review skill.
4. If PASS, preserve the first-line `milestone-task=route-selector,direct-flow` metadata in `complete.log` and report it for the runtime aggregation event. Roadmap state evaluation belongs to `sync-milestone-workstate`.
5. Check applicable `Review-Only Checklist` items at the final `.log` location before reporting.

---

## Implementation Item Completion

| Item | Status |
|------|---------|
| REVIEW_API-1 Align public Hot Path semantics | [x] |
| REVIEW_API-2 Migrate integrated regressions | [x] |

## Implementation Checklist

- [x] Define the authorized virtual-preset Hot Path exception in both API contracts and the living input-surface spec while preserving ordinary-route raw relay.
- [x] Migrate virtual-preset handler regressions to complete pinned gate evidence, caller-requested stream shape, provider identity, fail-closed pre-start frames, and direct terminal assertions; add the missing Messages SSE no-ID case.
- [x] Run fresh focused, common-race, full Edge, vet, formatting, deterministic contract-reference, and diff verification with every required command exiting zero.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** This checklist is used only by the review agent.
> Implementing agents must not modify or check this section.

- [x] Append one verdict of `PASS`, `WARN`, or `FAIL` and verified `review_rework_count`, `evidence_integrity_failure` to `Code Review Result`.
- [x] Verify that verdict, `Dimension Assessment`, and Required/Suggested/Nit classifications match.
- [x] Archive active `CODE_REVIEW-*-G??.md` to `code_review_cloud_G08_3.log`.
- [x] Archive active `PLAN-*-G??.md` to `plan_cloud_G08_3.log`.
- [x] Verify that the Agent-Ops managed block in `.gitignore` unignores `agent-task/**/*.md` and `agent-task/**/*.log` and ignores `agent-roadmap/current.md`.
- [ ] If PASS, write `complete.log` based on `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md` files.
- [ ] If PASS, move active task directory `agent-task/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/` to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/07+02,04,06_route_selector_direct/` and update this checklist at the final archive path.
- [ ] If PASS and task group is `m-<milestone-slug>`, preserve and report `milestone-task` metadata for runtime aggregation, without modifying roadmap or directly calling `update-roadmap`.
- [ ] If PASS for split work, remove empty active parent `agent-task/m-iop-hot-path-one-shot-execution/` or verify it was kept due to remaining siblings/files.
- [x] If WARN/FAIL, write the next filesystem state matching code-review verdict and do not write `complete.log`.

## Deviations from Plan

None.

## Key Design Decisions

- Ordinary provider routes retain raw status/header/body/SSE relay. The exception is scoped to an admitted virtual execution preset after immutable selector, provider, health, capability, and credential-binding evidence succeeds.
- The virtual-preset path collects and validates selected output before HTTP commitment, then re-encodes the caller-requested endpoint-native JSON or SSE shape. It requires the provider response ID and keeps run IDs, frame timestamps, and other transport correlation internal.
- The migrated Anthropic regression uses `stream:true` for direct SSE, validates public virtual model/provider identity, rejects `BODY`/`END` before `RESPONSE_START`, and verifies exactly-once terminalization. The Chat fixture now carries a real protocol profile driver/capability snapshot, and the missing Messages SSE identity case asserts a sanitized `api_error` with no transport leak.

## Reviewer Checkpoints

- Ordinary provider routes still preserve raw upstream status, headers, body bytes, and SSE framing.
- Authorized virtual presets collect and structurally classify selector output before commitment, then encode the stream or non-stream shape requested by the caller.
- Missing provider identity and BODY/END before `RESPONSE_START` fail with endpoint-standard sanitized errors, and run/frame correlation never appears as public provider metadata.
- Integrated Chat and Messages tests prove virtual public identity, provider response identity, and exactly-once terminal coordinator state.
- Every focused, common-race, full Edge, vet, formatting, reference, and diff command exits zero with uncached evidence.

## Verification Results

### REVIEW_API-1 Contract and living-spec reference scan

```bash
rg --sort path -n 'virtual preset|execution preset|Hot Path|raw tunnel|provider response ID|msg_iop' agent-contract/outer/openai-compatible-api.md agent-contract/outer/anthropic-compatible-api.md agent-spec/input/openai-compatible-surface.md
```

Expected: the ordinary raw-relay guarantee and authorized virtual-preset exception are explicit, and no unconditional `msg_iop` fallback applies to the virtual direct path.

_Actual stdout/stderr:_

```text
agent-contract/outer/openai-compatible-api.md:415:### Authorized virtual-preset Hot Path
agent-contract/outer/openai-compatible-api.md:417:Ordinary provider routes retain raw tunnel semantics: Edge relays the selected
agent-contract/outer/openai-compatible-api.md:423:For that virtual-preset Hot Path, Edge collects and structurally classifies the selected
agent-contract/outer/anthropic-compatible-api.md:290:### Authorized virtual-preset Hot Path
agent-contract/outer/anthropic-compatible-api.md:298:For that virtual-preset Hot Path, Edge collects and structurally classifies selected
agent-contract/outer/anthropic-compatible-api.md:303:into public provider metadata, and it does not apply the ordinary `msg_iop` fallback.
agent-spec/input/openai-compatible-surface.md:146:| virtual-preset Hot Path | An admitted virtual execution preset first collects and structurally classifies selector output. It then encodes the caller-requested endpoint-native JSON or SSE shape, preserves the virtual public model and provider response identity, and fails closed before commitment when selector evidence, provider identity, or pre-start tunnel framing is invalid. |
agent-spec/input/openai-compatible-surface.md:221:- An admitted virtual preset is the only provider-path exception to raw relay: it retains provider response identity but emits caller-requested direct JSON/SSE after collection. `BODY` or `END` before `RESPONSE_START`, a missing provider identity, or failed immutable selector evidence returns a sanitized endpoint error before public commitment; run IDs and frame timestamps stay internal.
```

### REVIEW_API-2 Integrated regression suite

```bash
go test -count=1 ./apps/edge/internal/openai -run 'Test(AnthropicNativeVirtualPresetPreservesPublicModelIdentity|VirtualPresetModelHandlersPreservePublicIdentity|HotPathPresetHandlersDirect)'
```

Expected: integrated Chat/Messages virtual presets use the production direct path and all missing-identity/pre-start cases fail before public response commitment.

_Actual stdout/stderr:_

```text
ok  \tiop/apps/edge/internal/openai\t0.096s
```

### Final dependency and contract verification

```bash
test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/02+01_preset_generation/complete.log
test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization/complete.log
test -f agent-task/archive/2026/08/m-iop-hot-path-one-shot-execution/06+04,05_request_identity_ingress/complete.log
rg --sort path -n 'virtual preset|execution preset|Hot Path|raw tunnel|provider response ID|msg_iop' agent-contract/outer/openai-compatible-api.md agent-contract/outer/anthropic-compatible-api.md agent-spec/input/openai-compatible-surface.md
```

Expected: all dependencies exist and the public contract references retain both ordinary raw relay and the narrow virtual-preset direct exception.

_Actual stdout/stderr:_

```text
Dependency existence checks: PASS (no stdout).
Contract reference scan: PASS; output matches REVIEW_API-1 above.
```

### Final focused and common-race verification

```bash
go test -count=1 ./apps/edge/internal/openai -run 'Test(AnthropicNativeVirtualPresetPreservesPublicModelIdentity|VirtualPresetModelHandlersPreservePublicIdentity|HotPathPresetHandlersDirect)'
go test -count=1 ./apps/edge/internal/openai -run 'TestHotPath(SelectorDecisionMatrix|PresetHandlersDirect|Direct)'
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
```

Expected: all commands exit 0 with uncached focused and common-race evidence.

_Actual stdout/stderr:_

```text
ok  \tiop/apps/edge/internal/openai\t0.096s
ok  \tiop/apps/edge/internal/openai\t0.106s
ok  \tiop/packages/go/streamgate\t3.646s
ok  \tiop/packages/go/config\t1.981s
ok  \tiop/apps/edge/internal/openai\t9.671s
ok  \tiop/apps/edge/internal/service\t7.646s
```

### Final Edge, vet, formatting, and diff verification

```bash
route_selector_contract_tmp_dir="$(mktemp -d /config/.tmp-iop-route-selector-contract.XXXXXX)"
TMPDIR="$route_selector_contract_tmp_dir" go test -count=1 ./apps/edge/...
rmdir "$route_selector_contract_tmp_dir"
go vet ./apps/edge/...
gofmt -d apps/edge/internal/openai/anthropic_native_test.go apps/edge/internal/openai/principal_routes_test.go apps/edge/internal/openai/hot_path_direct_test.go
git diff --check
```

Expected: all commands exit 0; provider identity stays provider-owned, transport metadata stays internal, direct requests terminalize exactly once, and the changed files are formatted with no whitespace errors.

_Actual stdout/stderr:_

```text
ok  \tiop/apps/edge/cmd/edge\t0.991s
ok  \tiop/apps/edge/internal/authprojection\t0.178s
go vet ./apps/edge/...: PASS (no stdout)
gofmt -d ...: PASS (no stdout)
git diff --check: PASS (no stdout)
```

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?**
> If anything is blank, go back and fill it in before saving this file.
> Leave review-agent-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Header comment, Overview, Review Agent Instructions | Fixed at stub creation | Implementing agent must not modify or execute these (archive, complete.log, and task-directory archive move are review-agent only) |
| Archive Evidence Snapshot | Fixed at stub creation from plan when present | Implementing agent uses it as default prior-loop context; read only the specific archive files cited there when more detail is required |
| Implementation Item Completion (item names) | Fixed at stub creation | Implementing agent checks `[ ]` → `[x]` only |
| Implementation Checklist (item text/order) | Fixed at stub creation from plan | Implementing agent checks `[ ]` → `[x]` only |
| Review-Only Checklist | Review agent only | Implementing agent must not modify or check this section |
| Deviations from Plan, Key Design Decisions | Implementing agent | Replace placeholder text with actual content |
| Reviewer Checkpoints | Fixed at stub creation | Pre-filled from plan |
| Verification Results (section headings + commands) | Fixed at stub creation | Implementing agent fills in command output only; command changes require a `Deviations from Plan` entry |
| Code Review Result | Review agent appends | Not included in stub |

## Code Review Result

- Overall Verdict: FAIL
- Dimension Assessment:
  - Correctness: Pass
  - Completeness: Fail
  - Test coverage: Fail
  - API contract: Pass
  - Code quality: Pass
  - Implementation deviation: Fail
  - Verification trust: Fail
  - Spec conformance: Fail
- Findings:
  - Required — `apps/edge/internal/openai/principal_routes_test.go:1237`, `apps/edge/internal/openai/principal_routes_test.go:1265`, `apps/edge/internal/openai/anthropic_native_test.go:250`, and `apps/edge/internal/openai/hot_path_direct_test.go:171`: the active plan requires integrated assertions for provider response identity and absence of run/frame transport correlation, but the Chat JSON, Anthropic bridge, and native non-stream cases never assert their fixture response IDs, while the missing-ID matrix rejects the run ID only and does not reject its frame timestamp. The review evidence therefore claims identity and correlation coverage that these tests do not provide; a regression that substitutes a different non-empty provider ID or exposes the frame timestamp can pass. Decode and assert the exact fixture IDs (`chatcmpl-public` and `msg-public`) in all three success cases, reject both the run-ID and frame-timestamp sentinels in the missing-provider-metadata response, and rerun the focused, race, and full Edge verification.
- Routing Signals:
  - review_rework_count=4
  - evidence_integrity_failure=true
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with this raw finding, rerun isolated task routing, archive this pair, and materialize the routed follow-up pair. Do not write `complete.log`.
