<!-- task=m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization plan=0 tag=API milestone-task=preset-model -->

# Code Review Reference - 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`, fill actual notes/output, then stop with active files in place and report ready for review. If blocked, record only the exact blocker, attempts/output, and resume condition. Do not ask the user, call user-input tools, create stop files, classify state, archive, or write `complete.log`; finalization is review-agent-only.

## Overview

date=2026-08-02
task=m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization, plan=0, tag=API

## For the Review Agent

> **[REVIEW AGENT ONLY]** Implementers must not execute this section.

Compare each item against source and Verification Results. Append verdict/signals, archive the active pair, and on PASS write `complete.log`, preserve milestone metadata, archive the task directory, and update the final `.log` checklist. WARN/FAIL must create the code-review skill's exact next state.

## Implementation Item Completion

| Item | Status |
|------|---------|
| API-2 Resolve virtual model authorization and public identity | [x] |

## Implementation Checklist

- [x] Resolve and authorize selector plus every allowed preset stage uniquely for the principal.
- [x] Filter listing/admission failures and preserve the public virtual model identity without synthetic credentials.
- [x] Run dependency, focused, race, vet, and diff verification exactly as written.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual notes and output.

## Review-Only Checklist

> **[REVIEW AGENT ONLY]** Implementers must not modify or check this section.

- [x] Append one PASS/WARN/FAIL verdict with verified `review_rework_count` and `evidence_integrity_failure`.
- [x] Verify verdict, Dimension Assessment, and Required/Suggested/Nit classifications match.
- [x] Archive the active review to `code_review_cloud_G07_0.log`.
- [x] Archive the active plan to `plan_local_G07_0.log`.
- [x] Verify the Agent-Ops `.gitignore` block.
- [ ] On PASS write `complete.log` from `agent-ops/skills/common/code-review/templates/complete-log-template.md` and leave no active `.md`.
- [ ] On PASS archive to `agent-task/archive/YYYY/MM/m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization/` and update this checklist there.
- [ ] On PASS preserve/report `milestone-task=preset-model` without direct roadmap mutation.
- [ ] On PASS remove the active parent only if no siblings/files remain.
- [x] On WARN/FAIL write the mandated next state without `complete.log`.

## Deviations from Plan

None

## Key Design Decisions

- Extended `ExecutionPreset` with `CanonicalModelReferences()` in `packages/go/config` to gather unique canonical model IDs referenced by the selector and all route stages across allowed modes.
- Implemented `resolveVirtualPresetModelForPrincipal` in `apps/edge/internal/openai/principal_routes.go` to require exactly one active projected route for the selector and every stage model reference, resolving each against the model catalog.
- Preserved the external virtual model ID as public identity (`ExternalModelID` and `RouteID`) in dispatch and model listing without creating synthetic credential projections.
- Added legacy virtual model resolution in `route_resolution.go` and `routes.go` (`advertisedModels`), ensuring that all canonical references resolve to valid catalog entries or explicit routes when model catalog is active.

## Reviewer Checkpoints

- Managed listing/admission requires unique selector and every-stage authorization.
- No synthetic projection or credential route is created.
- Public model echo remains the requested virtual id.

## Verification Results

### API-2 item verification

```bash
go test -count=1 ./apps/edge/internal/openai -run 'Test(VirtualPreset|Managed.*Model|ModelCatalog)'
```

_Actual stdout/stderr:_
```
ok  	iop/apps/edge/internal/openai	0.037s
```

### Dependencies and race tests

```bash
test -f agent-task/m-iop-hot-path-one-shot-execution/02+01_preset_generation/complete.log
test -f agent-task/m-iop-hot-path-one-shot-execution/03+01_preset_model_config/complete.log
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
```

_Actual stdout/stderr:_
```
ok  	iop/packages/go/streamgate	2.008s
ok  	iop/packages/go/config	1.588s
ok  	iop/apps/edge/internal/openai	8.836s
ok  	iop/apps/edge/internal/service	6.995s
```

### Vet and diff

```bash
go vet ./apps/edge/internal/openai
git diff --check
```

_Actual stdout/stderr:_
```
(exit code 0; clean output)
```

---

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section?** Leave review-only sections unchanged.

## Section Ownership

| Section | Owner | Note |
|---------|-------|------|
| Header/Overview/instructions, item names, checklist text, checkpoints, commands | Fixed | Do not rewrite |
| Item status, Deviations, Key Design Decisions, actual output | Implementer | Must complete |
| Review-Only Checklist and Code Review Result/finalization | Review agent | Implementer must not modify |

## Code Review Result

- Overall Verdict: FAIL
- Dimension Assessment:
  - Correctness: Fail
  - Completeness: Fail
  - Test Coverage: Fail
  - API Contract: Fail
  - Code Quality: Pass
  - Implementation Deviation: Fail
  - Verification Trust: Fail
  - Spec Conformance: Fail
- Findings:
  - Required — `apps/edge/internal/openai/principal_routes.go:112`: managed preset references are matched against public `RouteID`/`RouteAlias` text instead of the route's unique canonical catalog binding. Existing managed routing permits an arbitrary public route such as `bound-route` to resolve to an internal model group, so an otherwise authorized preset is omitted and rejected whenever those identities differ; a focused reviewer reproducer failed with `route not found`. The same return path overwrites the selector's real projected route at `apps/edge/internal/openai/principal_routes.go:170` with the virtual model id, causing `credentialBinding()` to fence/lease against a route that does not exist in the projection. Resolve every preset reference by evaluating the principal's routes through `resolveManagedCatalogBinding`, require exactly one route whose `ModelGroupKey` equals the reference, preserve that route's `RouteID` in the credential binding, and keep `ExternalModelID` solely for public response identity.
  - Required — `apps/edge/internal/openai/principal_routes_test.go:1074`: the case labeled ambiguous contains only a missing selector route, while the case labeled alias collision at `apps/edge/internal/openai/principal_routes_test.go:1102` contains only another missing stage route. The planned/SDD S01 zero-one-multiple and collision evidence is therefore absent, and no handler assertion proves that Chat/Anthropic response `model` remains the requested virtual id. Replace these mislabeled fixtures with genuine multiple-catalog-binding and virtual-id/route-alias collision cases, and add dispatch/credential-binding plus public response-echo assertions with route ids independent from canonical model ids.
- Routing Signals:
  - `review_rework_count=1`
  - `evidence_integrity_failure=true`
- Next Step: Invoke the plan skill in `prepare-follow-up` mode with the raw findings and fresh verification evidence, then archive this pair and materialize the freshly routed follow-up pair.
