Skip to content

fix(providers): Cloudflare Workers AI discovery uses model names, not UUIDs (#4259) - #4282

Merged
diegosouzapw merged 1 commit into
release/v3.8.30from
fix/4259-cloudflare-uuid-models
Jun 19, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.30from
fix/4259-cloudflare-uuid-models

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Closes #4259

Problem

Importing a Cloudflare Workers AI key listed models with internal UUID identifiers (e.g. 429b9e8b-d99e-44de-91ad-706cf8183658) instead of their usable slugs (@cf/meta/llama-3.1-8b-instruct). Reported by @FerLuisxd.

Root cause

Cloudflare's /ai/models/search returns objects shaped { id: "<uuid>", name: "@cf/..." } — name is the callable model slug, id is an internal UUID. The cloudflare-ai entry in PROVIDER_MODELS_CONFIG used parseResponse: (data) => data.result || [], passing the raw objects straight through. Downstream buildResponse maps id: m.id, so the UUID became the model id surfaced in the dashboard/import.

Fix

cloudflare-ai parseResponse now maps each result's name → id (and keeps name/description), mirroring the gemini/huggingface/clarifai normalizers already in the same config map. Entries without a name are dropped; on upstream error the route still falls back to the local catalog, so import never breaks.

Test (TDD, Hard Rule #18)

tests/unit/cloudflare-models-uuid-4259.test.ts — mocks the Cloudflare /ai/models/search response and asserts the discovered model ids are the @cf/... slugs, never the UUIDs. RED before the fix (ids were the UUIDs) → GREEN after.

Validation

  • node --test tests/unit/cloudflare-models-uuid-4259.test.ts ✅
  • provider-models-route.test.ts + executor-cloudflare-ai.test.ts + new test: 63/63 ✅
  • typecheck:core ✅ · eslint (route) 0 errors ✅ · check:file-size ✅ (route.ts 2538→2554, baseline bumped with _rebaseline_2026_06_19_4259_cloudflare_uuid_models)

… UUIDs (#4259)

Cloudflare's /ai/models/search returns { id: "<uuid>", name: "@cf/..." } where
name is the callable slug and id is an internal UUID. The cloudflare-ai discovery
config passed the raw objects through (parseResponse: data.result), so buildResponse
used id (the UUID) as the model id — the dashboard/import listed UUIDs instead of
@cf/... model names. Map each result's name -> id (mirrors the gemini/huggingface/
clarifai parseResponse normalizers in the same map); falls through to the local
catalog on error so import never breaks.

TDD: tests/unit/cloudflare-models-uuid-4259.test.ts (RED on UUID ids -> GREEN on slugs).

Closes #4259
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves issue #4259 by updating the Cloudflare Workers AI model discovery logic to map the human-usable model name (slug) as the model ID instead of the internal UUID, ensuring the dashboard displays callable model IDs. It also adds a comprehensive unit test to verify this behavior. The reviewer recommended using Array.isArray to safely validate the API response structure before mapping, preventing potential runtime errors if the response is malformed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +670 to +672
parseResponse: (data) =>
(data.result || [])
.map((model: any) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the Cloudflare API returns an unexpected response where data.result is not an array (for example, an error payload or an empty object), (data.result || []) will evaluate to that non-array value. Calling .map() on it will then throw a TypeError, causing a hard 500 error instead of gracefully falling back to the local catalog. Using Array.isArray ensures the code is robust against unexpected API responses.

Suggested change
parseResponse: (data) =>
(data.result || [])
.map((model: any) => {
parseResponse: (data) =>
(Array.isArray(data?.result) ? data.result : [])
.map((model: any) => {

@diegosouzapw
diegosouzapw merged commit 550440f into release/v3.8.30 Jun 19, 2026
4 checks passed
@diegosouzapw
diegosouzapw deleted the fix/4259-cloudflare-uuid-models branch June 19, 2026 15:25
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
… UUIDs (diegosouzapw#4259) (diegosouzapw#4282)

Cloudflare's /ai/models/search returns { id: "<uuid>", name: "@cf/..." } where
name is the callable slug and id is an internal UUID. The cloudflare-ai discovery
config passed the raw objects through (parseResponse: data.result), so buildResponse
used id (the UUID) as the model id — the dashboard/import listed UUIDs instead of
@cf/... model names. Map each result's name -> id (mirrors the gemini/huggingface/
clarifai parseResponse normalizers in the same map); falls through to the local
catalog on error so import never breaks.

TDD: tests/unit/cloudflare-models-uuid-4259.test.ts (RED on UUID ids -> GREEN on slugs).

Closes diegosouzapw#4259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant