Skip to content

fix(catalog): accept Together top-level /models arrays - #639

Merged
Wibias merged 2 commits into
lidge-jun:devfrom
Wibias:fix/617-together-models-array
Jul 29, 2026
Merged

fix(catalog): accept Together top-level /models arrays#639
Wibias merged 2 commits into
lidge-jun:devfrom
Wibias:fix/617-together-models-array

Conversation

@Wibias

@Wibias Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Test plan

  • bun test tests/provider-connection-test.test.ts
  • CI green

Closes #617

Summary by CodeRabbit

  • Bug Fixes
    • Improved provider model discovery to support additional OpenAI-compatible /models response formats, including top-level arrays and alternate object structures.
    • Provider connectivity testing now correctly accepts valid top-level model lists and reports the available model count.
    • Malformed responses continue to receive appropriate validation and fallback handling.

@github-actions github-actions Bot added the bug Something isn't working label Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Wibias, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 15b6b50b-13fd-40f2-baac-9b2d812b9ffa

📥 Commits

Reviewing files that changed from the base of the PR and between a296219 and a2b8458.

📒 Files selected for processing (2)
  • src/codex/catalog/provider-fetch.ts
  • src/server/management/provider-routes.ts
📝 Walkthrough

Walkthrough

Provider model discovery now normalizes top-level arrays and { data: [...] } or { models: [...] } responses. Both catalog discovery and the provider connectivity probe use the shared helper, with a Together-style array response test.

Changes

Provider model discovery

Layer / File(s) Summary
Shared response normalization
src/codex/catalog/provider-fetch.ts
Adds providerModelsListFromResponse for supported /models payload shapes and uses it in fetchProviderModels.
Connectivity probe integration and coverage
src/server/management/provider-routes.ts, tests/provider-connection-test.test.ts
The provider test endpoint uses the shared normalizer, and tests accept a top-level array response from a Together provider.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the core change: accepting Together-style top-level /models arrays.
Linked Issues check ✅ Passed src/codex/catalog/provider-fetch.ts and src/server/management/provider-routes.ts now normalize top-level /models arrays, fixing #617's invalid discovery response.
Out of Scope Changes check ✅ Passed The edits stay focused on provider model-response normalization and the matching test, with no unrelated feature work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review
@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Wibias: Starting a review of #639.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/server/management/provider-routes.ts (1)

343-349: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep connectivity validation aligned with catalog discovery.

Line 346 accepts any array, so responses such as [{}] or [{"error":"invalid key"}] return ok: true even though fetchProviderModels rejects those entries through isProviderModelsApiItems. The dashboard can therefore report “Connected” while discovery still fails.

Reuse the catalog validator before reporting success:

Proposed fix
-import { providerModelsListFromResponse } from "../../codex/catalog/provider-fetch";
+import {
+  isProviderModelsApiItems,
+  providerModelsListFromResponse,
+} from "../../codex/catalog/provider-fetch";

-      if (!Array.isArray(list)) {
+      if (!isProviderModelsApiItems(list)) {
         return jsonResponse({ ok: false, latencyMs, error: "upstream /models returned an unexpected shape" });
       }

As per path instructions, provider/adapter contract drift should be prevented across the catalog and connectivity paths.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/management/provider-routes.ts` around lines 343 - 349, Update the
connectivity validation around providerModelsListFromResponse in the management
route to reuse the same isProviderModelsApiItems validator used by
fetchProviderModels. Reject arrays containing invalid entries, such as error
objects, with the existing unexpected-shape response; only report success when
the catalog entries pass the shared validator.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/provider-connection-test.test.ts`:
- Around line 138-149: Add focused coverage for fetchProviderModels using the
Together-style top-level array response, reusing the existing mock payload and
Together configuration. Assert the discovered catalog includes both “meta/llama”
and “Qwen/Qwen”, alongside—not instead of—the existing probe test.

---

Outside diff comments:
In `@src/server/management/provider-routes.ts`:
- Around line 343-349: Update the connectivity validation around
providerModelsListFromResponse in the management route to reuse the same
isProviderModelsApiItems validator used by fetchProviderModels. Reject arrays
containing invalid entries, such as error objects, with the existing
unexpected-shape response; only report success when the catalog entries pass the
shared validator.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 42ab0570-c897-444b-a549-1c1c0bd3e2e3

📥 Commits

Reviewing files that changed from the base of the PR and between ca7b104 and a296219.

📒 Files selected for processing (3)
  • src/codex/catalog/provider-fetch.ts
  • src/server/management/provider-routes.ts
  • tests/provider-connection-test.test.ts

Comment on lines +138 to +149
test("Together-style top-level /models array is accepted (#617)", async () => {
globalThis.fetch = (async () => new Response(JSON.stringify([{ id: "meta/llama" }, { id: "Qwen/Qwen" }]), {
status: 200,
headers: { "content-type": "application/json" },
})) as typeof fetch;
const config = baseConfig({
together: { adapter: "openai-chat", baseUrl: "https://api.together.xyz/v1", apiKey: "tg-key" },
});
const { body } = await probe(config, "together");
expect(body.ok).toBe(true);
expect(body.models).toBe(2);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add catalog-discovery coverage for the Together response.

This test verifies only /api/providers/test; it never exercises fetchProviderModels, which is the primary path fixed by the PR. A future regression in catalog normalization could therefore leave this test green while Together model discovery fails.

Add a focused catalog test using the same top-level array and assert that the discovered catalog contains meta/llama and Qwen/Qwen.

As per path instructions, a behavior change in src/ should have a focused regression test near the existing tests for that subsystem; the current test covers only the connectivity probe.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/provider-connection-test.test.ts` around lines 138 - 149, Add focused
coverage for fetchProviderModels using the Together-style top-level array
response, reusing the existing mock payload and Together configuration. Assert
the discovered catalog includes both “meta/llama” and “Qwen/Qwen”, alongside—not
instead of—the existing probe test.

Source: Path instructions

@Wibias Wibias linked an issue Jul 28, 2026 that may be closed by this pull request
2 tasks

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a29621972a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (json !== null && typeof json === "object") {
const obj = json as { data?: unknown; models?: unknown };
if (Array.isArray(obj.data)) return obj.data;
if (Array.isArray(obj.models)) return obj.models;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reconcile the catalog test before accepting models

For an OpenAI-chat provider returning { models: [] }, this branch now yields an empty array; isProviderModelsApiItems accepts it vacuously, so discovery becomes authoritative-empty and drops the configured fallback. That directly contradicts the unchanged missing-data case in tests/codex-catalog.test.ts:1888-1917, which expects static-fallback and an invalid_response status, so the catalog suite will fail. Either restrict this envelope to provider-aware Google handling or update the catalog contract and add a focused top-level-array catalog regression, rather than testing only the management probe.

AGENTS.md reference: AGENTS.md:L93-L95

Useful? React with 👍 / 👎.

@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex @coderabbitai: addressed in a2b8458 — catalog discovery accepts top-level arrays + data[] only; models[] remains probe-only for Google.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@Wibias Thanks for clarifying. The response-shape handling now preserves the intended boundary: catalog discovery accepts top-level arrays and data[], while models[] remains restricted to the Google connectivity probe.

🐇 ✅


✏️ Learnings added
Learnt from: Wibias
URL: https://github.com/lidge-jun/opencodex/pull/639

Timestamp: 2026-07-28T17:46:20.142Z
Learning: In `src/codex/catalog/provider-fetch.ts`, catalog model discovery should accept only top-level model arrays and OpenAI-compatible `{ data: [...] }` payloads. The `{ models: [...] }` response shape is Google-specific and should remain supported only by the provider connectivity probe in `src/server/management/provider-routes.ts`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@Wibias
Wibias merged commit 9d181fc into lidge-jun:dev Jul 29, 2026
9 checks passed
@Wibias

Wibias commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Transition complete for #639:

  1. Merged to dev: 9d181fc4
  2. Carry + Go port onto dev2-go: fix(catalog): carry Together /models array fix onto dev2-go (#639) #682
  3. Go decision: ported now (go/internal/codex/catalog_provider_fetch.go accepts Together-style top-level /models arrays).

Wibias added a commit that referenced this pull request Jul 29, 2026
* fix(catalog): accept Together top-level /models arrays

Closes #617

* fix(catalog): keep models[] for probe only; array+data for discovery

(cherry picked from commit 9d181fc)
Wibias added a commit that referenced this pull request Jul 29, 2026
Align FetchProviderModels with the TS oracle: accept top-level arrays
and {data:[...]}, reject stray {models} for catalog discovery.
Wibias added a commit that referenced this pull request Jul 29, 2026
fix(catalog): carry Together /models array fix onto dev2-go (#639)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Together model discovery fails with "invalid response"

1 participant