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

# Virtual Preset Model Authorization and Public Identity

## For the Implementing Agent

Start only after predecessors 02 and 03 have `complete.log`. Implement, run every command, and fill `CODE_REVIEW-cloud-G07.md` with actual notes/output. Keep active files for official review; finalization is review-agent-only.

## Background

A virtual preset model must be listed and admitted only when every selector and stage route resolves uniquely for the authenticated principal, while the external model id remains stable.

## Dependencies and Execution Order

- Required predecessors: `02+01_preset_generation` and `03+01_preset_model_config`.

## Analysis

### Files Read

- `agent-roadmap/sdd/knowledge-tool-optimization-extension/iop-hot-path-one-shot-execution/SDD.md`
- `apps/edge/internal/openai/server.go`
- `apps/edge/internal/openai/route_resolution.go`
- `apps/edge/internal/openai/principal_routes.go`
- `apps/edge/internal/openai/routes.go`
- `apps/edge/internal/openai/openai_auth_routes_models_test.go`
- `apps/edge/internal/openai/principal_routes_test.go`
- `agent-contract/outer/openai-compatible-api.md`
- `agent-contract/outer/anthropic-compatible-api.md`

### SDD Criteria

SDD scenario S01 requires managed zero/one/multiple match handling across selector and all stages, model list/admission behavior, stable response model echo, and no synthetic credential projection.

### Verification Context

Fresh/race Go tests and deterministic managed-route fixtures are sufficient; no external credentials are needed. Confidence: high.

### Test Coverage Gaps

Existing tests cover one managed provider route, not a virtual model whose selector/local/review references must all match uniquely.

### Symbol References

`resolveManagedCatalogBinding` gains a preset-aware sibling rather than changing provider semantics.

### Split Judgment

This is the second refined child of the former preset-model pair. It consumes the accepted virtual model shape and independently closes principal authorization, listing, admission, and public identity.

### Scope Rationale

Exclude mode selection, coordinator state, workspace tools, downstream execution, synthetic projection messages, and credential material in static config.

### Final Routing

`evaluation_mode=isolated-reassessment`; finalizer pair. Build closures are true; scores `(2,1,2,1,1)` yield G07/local-fit, matched risks `boundary_contract,variant_product` (2), no large context/rework/evidence failure/gap; `PLAN-local-G07.md`. Review uses the same scores and official cloud G07 in `CODE_REVIEW-cloud-G07.md`.

## Implementation Checklist

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

### [API-2] Resolve virtual model authorization and public identity

#### Problem

Managed listing publishes projected route ids and admission resolves only one provider group. It cannot prove unique authorization for the selector plus every preset stage or echo the virtual id independently from internal targets.

#### Solution

Represent preset dispatch with the external model id, preset id/generation, and immutable per-role canonical references. In managed mode require exactly one active projected route for every reference; in legacy mode require canonical catalog entries. Filter invalid virtual ids and re-resolve the chosen route/credential revision at dispatch time.

#### Modified Files and Checklist

- [ ] `apps/edge/internal/openai/route_resolution.go` — distinguish provider and preset dispatch.
- [ ] `apps/edge/internal/openai/principal_routes.go` — authorize all canonical references and filter listings.
- [ ] `apps/edge/internal/openai/routes.go` — preserve external model ids on both protocol listings.
- [ ] `apps/edge/internal/openai/openai_auth_routes_models_test.go` — cover legacy listing/admission/echo.
- [ ] `apps/edge/internal/openai/principal_routes_test.go` — cover zero/one/ambiguous matches and revision recheck.

#### Test Strategy

Add `TestVirtualPresetModelAuthorizationMatrix` and managed model-list cases for missing, ambiguous, cross-principal, alias-collision, and internal-target mismatch. Assert response `model` remains the requested virtual id.

#### Verification

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

## Modified Files Summary

| File | Items |
|------|-------|
| `apps/edge/internal/openai/route_resolution.go` | API-2 |
| `apps/edge/internal/openai/principal_routes.go` | API-2 |
| `apps/edge/internal/openai/routes.go` | API-2 |
| `apps/edge/internal/openai/openai_auth_routes_models_test.go` | API-2 |
| `apps/edge/internal/openai/principal_routes_test.go` | API-2 |
| `agent-task/m-iop-hot-path-one-shot-execution/04+02,03_preset_model_authorization/CODE_REVIEW-cloud-G07.md` | API-2 |

## Final Verification

```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 -count=1 ./apps/edge/internal/openai -run 'Test(VirtualPreset|Managed.*Model|ModelCatalog)'
go test -race -count=1 ./packages/go/streamgate ./packages/go/config ./apps/edge/internal/openai ./apps/edge/internal/service
go vet ./apps/edge/internal/openai
git diff --check
```

Expected: all commands exit 0; virtual ids are exposed only for unique all-stage authorization and provider-backed behavior remains unchanged.
