migrate-apim: against CLI 1.0.0b34, provider and model creates are rejected, read-backs never match, and the Foundry endpoint 404s

Cerrado
#62 2 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@santiagxf ya está trabajando en esto.

Desde el 17/11/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug

Summary

Against az aigateway 1.0.0b34 (default API version 2026-11-01), an end-to-end migrate-apim run can't finish, even for a small, clean APIM source:

  • apply can't create a model provider or a model: the resource provider rejects both with The displayName property is required.
  • The provider and MCP read-backs compare against the 1.0.0b31 resource shape, so correct objects report the object exists but does not match the desired state.
  • The planner copies APIM's .../openai backend URL as the Foundry provider endpoint. Every read-back says verified, but inference returns 404.
  • An authentication-managed-identity policy at API scope (the common APIM pattern) isn't recognized, so the plan has no identity step and no Foundry RBAC prerequisite.

The planner reports N items against CLI 1.0.0b31 (declared, not probed) (with --probe-cli: (probed)), while the installed CLI is 1.0.0b34.

Found while writing the migration section of lab 17 (PR #51). Every finding below was reproduced live with tools/migrate-apim at main 990fd3f. The plugin aigateway@azure v3.1.1 installed from the marketplace has an identical copy.

Environment

  • az aigateway 1.0.0b34, Azure CLI 2.91.0, Python 3.14, macOS
  • Source: APIM BasicV2 @2025-09-01-preview in Sweden Central with a system-assigned identity, one Foundry account (gpt-5-mini 2025-08-07, GlobalStandard), one Azure OpenAI model API with llm-token-limit and set-header, one product with one subscription, and one MCP passthrough API (https://learn.microsoft.com/api/mcp)
  • The source template is labs/17-coding-agent-plugin/infra/apim-source.bicep in PR #51

Repro

TOOL=~/aigateway/tools/migrate-apim
PYTHONPATH=$TOOL python3 -m migrate_apim.cli collect --apim <apim> -g <rg> -o inventory.json
PYTHONPATH=$TOOL python3 -m migrate_apim.cli discover-tools --inventory inventory.json --allow-secret-use mcp:learn-mcp
PYTHONPATH=$TOOL python3 -m migrate_apim.cli plan --inventory inventory.json -o plan.json \
  --target /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.ApiManagement/aigateways/<new-gateway>
# settle the 6 decisions, re-run plan, then for each phase:
PYTHONPATH=$TOOL python3 -m migrate_apim.cli apply --plan plan.json --inventory inventory.json --phase <phase> --execute

apply --status after the run:

steps: 8 in the plan, 2 failed, 6 verified
  gateway      complete   (1 steps)
  identity     complete   (1 steps)
  providers    stopped    (1 steps) (rehearsed)
  models       complete   (1 steps)      <- only because the model was created by hand (workaround below)
  aliases      complete   (1 steps)
  toolServers  stopped    (1 steps) (rehearsed)
  policies     complete   (1 steps)
  keys         complete   (1 steps)
stuck:
  failed: item:modelProvider/modelProvider-foundry-ai-endpoint -- foundry-ai-endpoint: ERROR: (ValidationError) ... The displayName property is required.
  failed: item:mcp/learn-mcp/registration -- learn-mcp: the object exists but does not match the desired state

Findings

1. model-provider create is rejected: displayName is required

apply.py _provider_create (L869) builds az aigateway model-provider create ... --kind Foundry --foundry @<file> with no --display-name. With 1.0.0b34 the RP rejects it:

(ValidationError) One or more fields contain incorrect values:
Exception Details: (ValidationError) The displayName property is required.

The providers phase stops with exit 1: "Stopped in providers. The source APIM is untouched; the gateway is partially built."

Expected: pass --display-name (for example, the APIM backend name or its title).

2. model create is rejected the same way

_model_create (L882) also passes no --display-name, and the RP returns the same displayName property is required error once a provider exists.

3. The provider read-back expects the 1.0.0b31 shape

The comparison reads kind, foundry.endpoint as a string, and foundry.authentication. 1.0.0b34 (2026-11-01) returns:

{
  "modelProviderType": "Foundry",
  "displayName": "foundry-ai-endpoint",
  "foundry": { "endpoint": { "url": "https://<acct>.cognitiveservices.azure.com/" }, "resourceIds": ["..."] },
  "authentication": { "managedIdentity": { "resource": "https://cognitiveservices.azure.com/" } }
}

Even a correct provider reports "the object exists but does not match the desired state". Note the trailing / that the service adds to managedIdentity.resource.

4. The MCP read-back expects the 1.0.0b31 shape

The MCP server is created correctly (az aigateway mcp show and an initialize call through /default/toolservers/learn-mcp/mcp both work), but the read-back compares endpoints[].mcp.url and required: true. 1.0.0b34 returns endpoints[].mcp.endpoint.url, mode: "failClosed", plus id and gatewayEndpoints. The toolServers phase reports failed and stays stopped.

5. The planner uses APIM's /openai backend URL as the Foundry provider endpoint

plan.py _provider (L389) copies the backend URL https://<acct>.cognitiveservices.azure.com/openai into foundry.endpoint. The gateway needs the account root https://<acct>.cognitiveservices.azure.com/. With the /openai endpoint, every step reads back as verified, yet POST /default/models/openai/v1/chat/completions returns 404 Resource not found. This is the dangerous one: the run looks green and serves no traffic.

Expected: strip the API path suffix (/openai, /openai/v1, /models) for Foundry providers, or take the endpoint from the resolved Foundry account (properties.endpoint), which collect already reads.

6. An API-scoped authentication-managed-identity policy leaves provider auth undetermined

collect.py (around L1935-2000) reads provider auth from the backend's credentials.managedIdentity or from the backend-scoped effective policy only. The most common APIM pattern puts <authentication-managed-identity resource="https://cognitiveservices.azure.com" /> in the API policy. Then the provider shows auth=undetermined, and the plan has no identity.assign step and no prereq:foundry-rbac. The migrated gateway has no identity and no grant, and inference fails at runtime.

With credentials.managedIdentity on the backend instead, the inventory shows auth=managedIdentity and the plan includes both.

7. The planner proposes reuse-appinsights for an Azure Monitor logger

With only an azureMonitor logger (resourceId: null, no Application Insights), plan.py (L1025-1047) still proposes reuse-appinsights and adds the prerequisite "Enable the OTLP endpoint on the Application Insights resource APIM reports to". There is no such resource. The coding agent caught it during review ("The generated reuse recommendation is unsupported by the collected evidence"). Suggest proposing gateway-metrics-only or new-appinsights when no logger is applicationInsights.

8. --next-phase returns to a stopped phase

next_phase() (L547) returns the first incomplete phase, so after providers stops, --next-phase returns providers again, even when a later phase could run. The operator has to name every later phase with --phase. Consider a hint ("providers is stopped; later phases can run with --phase models") or a --skip option.

Verified fixes

In a patched copy of the tool (not proposed as a PR, so that the maintainers can choose the shape), the following made a full run finish with model 200 and MCP 200:

  • Pass --display-name <name> in _provider_create and _model_create.
  • Compare the 2026-11-01 provider shape: modelProviderType, foundry.endpoint.url, top-level authentication.managedIdentity.resource (normalized trailing /).
  • Compare the 2026-11-01 MCP shape: mcp.endpoint.url, mode, and ignore id and gatewayEndpoints.
  • Normalize the Foundry endpoint to the account root in plan.py.

Workarounds documented in lab 17

Until this is fixed, the lab tells learners to:

  1. After the identity phase, create the provider with the CLI's Foundry shortcut, which sets the root endpoint, the managed identity, and the Foundry User role:
    az aigateway model-provider create -g <rg> --gateway-name <g> -n foundry-ai-endpoint --foundry-resource-id <account-id>
  2. Create the model with the shortcut, then run --phase models --execute, which reads it back as "already present with the desired state":
    az aigateway model create -g <rg> --gateway-name <g> --provider-name foundry-ai-endpoint -n gpt-5-mini --deployment gpt-5-mini --foundry-resource-id <account-id>
  3. Name each later phase with --phase (aliases, toolServers, policies, keys), and check the MCP server with az aigateway mcp show when toolServers reports "does not match".
  4. Or skip apply and have the coding agent write Bicep or Terraform from the settled plan.json. The lab ships a verified reference of both.
Lenguaje dominante
Python
Estrellas
18
Forks
9
Merge medio
1 d 16 h
PR fusionados (30 d)
23

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Azure/aigateway

Todos los issues de Azure/aigateway

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.