Skip to content

fix(webview): preserve configured Zoo Gateway model ID in model picker - #2491

Open
myk1yt wants to merge 1 commit into
Zoo-Code-Org:mainfrom
myk1yt:fix/zoo-gateway-preserve-model-id
Open

myk1yt wants to merge 1 commit into
Zoo-Code-Org:mainfrom
myk1yt:fix/zoo-gateway-preserve-model-id

Conversation

@myk1yt

@myk1yt myk1yt commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2490.

With provider Zoo Gateway and model fixed to zoo/glm-5.3-flash, real API requests correctly used the configured model, but the webview UI displayed anthropic/claude-sonnet-4 (settings panel and chat model selector). Three display sites caused it; all three are fixed here with no backend change.

Root cause

  1. webview-ui/src/components/ui/hooks/useSelectedModel.ts, getSelectedModel zooGateway case: getValidatedModelId(...) substituted the provider default whenever the configured ID was absent from the fetched catalog.
  2. webview-ui/src/components/ui/hooks/useSelectedModel.ts, hasValidRouterData gate: zooGateway was not in the LiteLLM/IO Intelligence exception group, so a failed fetch (the zoo-gateway fetcher returns a silent {} on error) never reached the selection logic and landed on the provider-default fallback.
  3. webview-ui/src/components/settings/providers/ZooGateway.tsx, settings auto-init effect: overwrote the stored ID whenever the loaded catalog lacked it.

The backend already preserves the configured ID (src/api/providers/router-provider.ts last-resort branch), so requests were never affected.

Changes

  • zooGateway joins litellm/ioIntelligence in the hasValidRouterData !isLoading exception group (mirrors fix(settings): preserve configured LiteLLM model ID in model picker #1368 and feat: add IO Intelligence provider #1758), so an empty or failed catalog no longer routes to the default fallback.
  • The zooGateway case preserves apiConfiguration.zooGatewayModelId || defaultModelId. info stays undefined for unlisted IDs per the hook's documented fallback contract, so the hardcoded Claude Sonnet description (zooGatewayDefaultModelInfo) cannot leak into the model info view. || (not ??) matches the IO Intelligence precedent and keeps unconfigured behavior unchanged.
  • The settings auto-init overwrites only an empty value (if (!current)); an explicit selection is never overwritten.
  • The catalog lookup uses an own-property guard (Object.hasOwn), mirroring the friendli case in the same file, so an inherited member cannot resolve as model info.
  • Tests: the stale-ID reassignment test in ZooGateway.spec.tsx is inverted to assert preservation; new zoo-gateway rows in useSelectedModel.spec.ts cover absent-from-catalog, empty router payload, settled-error, and inherited-key IDs. Red-on-head was proven for each new row.

Precedents

Zoo Gateway was the remaining provider missing this protection.

Out of scope (possible follow-ups)

  • Backend behavior: already correct, untouched.
  • Webview/fetcher timeout mismatch (10s vs 15s) and the useZooGatewayRouterModelsSync cache-key sync: they no longer produce a wrong display after this fix.
  • Pre-existing unguarded catalog lookups in sibling provider cases (openrouter, requesty, unbound, litellm, poe, ioIntelligence): same display-only class, left untouched to keep this PR minimal.

Note on #2229

#2229 (draft, conflicting) refactors the same file toward a getModelId accessor and still retains the zooGateway validation fallback, so it would not fix this bug. This change is orthogonal to that refactor and keeps the same call shape.

Verification

  • Red-on-head: 3 tests failed before the fix (2 hook, 1 component), 180 passed; green after.
  • Targeted: 185/185 (useSelectedModel.spec.ts + ZooGateway.spec.tsx); adjacent zoo-gateway specs 108/108.
  • Full webview-ui suite: 195 files / 2599 tests passed.
  • tsc --noEmit clean; ESLint exit 0 on the 4 touched files with no suppression-count increase.
  • blind-qa smoke: 8/8 independent probes (real ZooGateway settings component, real useSelectedModel hook, real chat ModelSelector display), derived from the acceptance criteria before reading the author's tests.
  • Double-blind review: 4 code-reviewer seats + 4 security-reviewer seats, Round 1 (full diff) and Round 2 (fix delta), all PASS (P0=0, P1=0; 0 critical, 0 high). Review findings: one doc fix, one test-parity row, and one own-property guard, all applied and re-verified.

Test plan

  • Configure Zoo Gateway with a model ID absent from the gateway catalog: the picker and settings panel keep the configured ID (no Sonnet default).
  • Simulate a failed catalog fetch (empty payload): the configured ID is still displayed.
  • Leave the model unset: the provider default is used, as before.

The webview replaced a configured Zoo Gateway model ID with the provider default whenever the fetched catalog lacked the entry, and the settings panel overwrote the stored ID on the same condition, while API requests kept using the configured model. Zoo Gateway now joins LiteLLM and IO Intelligence in the readiness-gate exception group, the configured ID is preserved in the picker, and the settings auto-init only fills an empty value.

Mirrors the LiteLLM fix in Zoo-Code-Org#1368 and the IO Intelligence fix in Zoo-Code-Org#1758. The catalog info lookup uses an own-property guard like the friendli case so an inherited member cannot resolve as model info.

Fixes Zoo-Code-Org#2490
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Preserved configured Zoo Gateway model selections when they aren’t listed in the available models.
    • Used the provider’s default model only when no model is configured, and avoided displaying metadata for unlisted models.

Zoo Gateway now preserves configured model IDs when they are absent from router data. The settings effect assigns a default model only when no model ID is configured. Tests cover catalog misses, fetch failures, defaults, and model metadata.

Changes: Zoo Gateway model selection

Layer / File(s) Summary
Router readiness and selected model
webview-ui/src/components/ui/hooks/useSelectedModel.ts, webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
The hook waits for the router fetch to settle but does not require a Zoo Gateway catalog entry. It preserves configured IDs and returns model metadata only for IDs that are own properties of the catalog. Tests cover catalog misses, empty data, fetch failures, defaults, and metadata.
Settings model initialization
webview-ui/src/components/settings/providers/ZooGateway.tsx, webview-ui/src/components/settings/providers/__tests__/ZooGateway.spec.tsx
The settings effect assigns the resolved default only when the configured ID is empty. The test verifies that an ID absent from the catalog remains configured.

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

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to ce438

This change keeps the configured Zoo Gateway model visible in the model picker and settings when it is missing from the catalog or the catalog fails to load. The change is limited to the webview and is covered by targeted tests, so no actionable merge risk remains.

Pre-merge checks: Passed 8

Check name Status Explanation
Title check Passed The title "fix(webview): preserve configured Zoo Gateway model ID in model picker" matches the main change. The PR keeps a configured Zoo Gateway model ID when it is absent from the fetched catalog or…
Description check Passed The description covers the template's main content. It links the issue (Fixes #2490), explains the description's how and root causes, lists key implementation details and trade-offs, and gives a detai…
Linked Issues check Passed Issue #2490 has three coding requirements. Each is implemented in the reviewed head diff.

1. Preserve the configured ID in the zooGateway case of getSelectedModel (useSelectedModel.ts). The head code…
Out of Scope Changes check Passed The whole-PR diff (merge base 75a93a9 to head ce438d7) touches three source files and two test files. All changes map to #2490:
- useSelectedModel.ts: the zooGateway selection case, the hasValidRouter…
Regression Evidence Passed Changed behavior and focused coverage, from the diff (base..head): 1. useSelectedModel.ts zooGateway case now keeps zooGatewayModelId || defaultModelId. Own-property Object.hasOwn lookup gives `…
Security Boundaries Passed The Security boundaries check fails only for a changed path that leaks secrets or PII, trusts or executes unvalidated input, or bypasses approval or allowlist controls. The PR diff (4 files, verified …
Persistence Integrity Passed The check fails only for a changed persistence path that can lose or corrupt state through an un-awaited operation, a non-atomic write, missing rollback or partial-failure handling, or a persisted def…
Lifecycle Resource Cleanup Passed The check fails only for a changed lifecycle path that can leak a listener, watcher, provider, timer, task, or other resource, or that can duplicate work after cancellation, disposal, or restart. The …
Full details: Title check

Explanation

The title "fix(webview): preserve configured Zoo Gateway model ID in model picker" matches the main change. The PR keeps a configured Zoo Gateway model ID when it is absent from the fetched catalog or when catalog loading fails. The changes to useSelectedModel.ts, ZooGateway.tsx, and their tests all support this behavior. The title is short and specific, and it uses a conventional commit prefix. It does not cover the settings auto-init change, but that is a secondary part of the same fix.

Full details: Description check

Explanation

The description covers the template's main content. It links the issue (Fixes #2490), explains the description's how and root causes, lists key implementation details and trade-offs, and gives a detailed test procedure with verification results. The Test Plan section gives manual reproduction steps. Several template items are not addressed: the Visual Snapshots and Videos sections are not discussed (the change is a logic fix, so a *.visual.tsx snapshot may still be needed if the picker display counts as a visible UI change), the Documentation Updates section is not marked, the Pre-Submission Checklist is not ticked, and the Get in Touch section (Discord username) is missing. The description also uses some non-STE terms and contractions-free prose, though it is largely compliant. Overall the description is mostly complete.

Resolution

Consider these additions: (1) state whether a *.visual.tsx snapshot applies to the model picker display change, or explain why it does not; (2) mark the Documentation Updates checkbox; (3) add a Discord username in the Get in Touch section; (4) tick the Pre-Submission Checklist items that apply.

Full details: Linked Issues check

Explanation

Issue #2490 has three coding requirements. Each is implemented in the reviewed head diff.

  1. Preserve the configured ID in the zooGateway case of getSelectedModel (useSelectedModel.ts). The head code uses apiConfiguration.zooGatewayModelId || defaultModelId in place of getValidatedModelId. A configured ID absent from the catalog is kept.
  2. Let selection run after a failed or empty fetch. zooGateway is added to the dynamicProvider === litellm || ioIntelligence exception group, which uses !routerModels.isLoading (useSelectedModel.ts, hasValidRouterData).
  3. Limit the settings auto-init overwrite to the empty case (ZooGateway.tsx). The condition changes from !current || !modelIds.includes(current) to !current.

The issue also requires that info stay undefined for unlisted IDs. The head code returns info only from an own property of the fetched catalog (Object.hasOwn), so unlisted IDs get undefined. The issue requires the provider default when nothing is configured. The || fallback covers that case.

The issue asks for tests. The diff changes ZooGateway.spec.tsx and useSelectedModel.spec.ts, as the summary describes. I did not run these tests. The PASS rests on the source diff, which matches the stated requirements.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff (merge base 75a93a9 to head ce438d7) touches three source files and two test files. All changes map to #2490:

  • useSelectedModel.ts: the zooGateway selection case, the hasValidRouterData gate, and the related comments.
  • ZooGateway.tsx: the auto-init condition.
  • ZooGateway.spec.tsx and useSelectedModel.spec.ts: tests for the changed behavior.

The Object.hasOwn guard is a small defensive change inside the zooGateway case. It directly supports the requirement that unlisted IDs keep undefined info. The PR does not change backend code, and the PR description excludes backend work. The PR description lists other sibling provider lookups and the timeout mismatch as follow-ups and leaves them untouched. No unrelated change is visible in the reviewed diff.

Full details: Regression Evidence

Explanation

Changed behavior and focused coverage, from the diff (base..head): 1. useSelectedModel.ts zooGateway case now keeps zooGatewayModelId || defaultModelId. Own-property Object.hasOwn lookup gives info undefined for unlisted IDs. Covered at the hook layer in useSelectedModel.spec.ts by new zoo-gateway provider rows: absent-from-populated-catalog (preserve ID, info undefined), unset ID (default plus catalog info), inherited key "toString" (no inherited info), and a settled error branch (isError: true, ID preserved). The author reports the new rows failed on head. 2. hasValidRouterData gate adds zooGateway to the !isLoading exception group. Covered by the empty-router-payload row (createRouterModelsResult({})), which exercises the gate directly. 3. ZooGateway.tsx auto-init now overwrites only an empty value. Covered in ZooGateway.spec.tsx: the stale-ID test is inverted to assert preservation (not.toHaveBeenCalled). The existing tests cover the unset case ("auto-selects ... when the profile has no model id"), the valid-ID case ("does not overwrite a model id that is already valid"), and the loading-empty case. Unit tests at the hook and component layers are the lowest valid layers for this pure selection and settings-effect logic. Error, empty, unset, and inherited-key branches are all present. Playwright: the repo has *.visual.tsx component snapshot tests (webview-ui/playwright-ct.config.ts). I found no ZooGateway or model-picker visual test and no repo rule requiring a snapshot for this change. The change corrects which model ID text is shown. It does not add or restyle a durable visual element, so the snapshot requirement is not triggered by this check's wording. No concrete changed behavior lacks focused coverage.

Full details: Security Boundaries

Explanation

The Security boundaries check fails only for a changed path that leaks secrets or PII, trusts or executes unvalidated input, or bypasses approval or allowlist controls. The PR diff (4 files, verified with git diff against the review base) changes only webview display logic: - useSelectedModel.ts: Zoo Gateway joins the LiteLLM/IO Intelligence settled-fetch group. The zooGateway case now returns apiConfiguration.zooGatewayModelId || defaultModelId and reads catalog info through Object.hasOwn. The own-property guard narrows lookups; it does not widen them. - ZooGateway.tsx: the auto-init effect now writes the default only when the stored ID is empty. It no longer overwrites an explicit ID. - Test files: assertions only. No secrets, credentials, or PII are read, logged, or transmitted in the changed lines. The configured model ID is user-supplied settings data. The backend already used that ID before this PR, and the PR does not touch backend code. The ID is rendered as display text, not executed. No approval, allowlist, or permission check is removed or bypassed. The PR does not add a new trust boundary. No changed path matches an explicit failure condition, so the check passes.

Full details: Persistence Integrity

Explanation

The check fails only for a changed persistence path that can lose or corrupt state through an un-awaited operation, a non-atomic write, missing rollback or partial-failure handling, or a persisted default that does not reach a consumer. The diff (refs/coderabbit/pre-merge-check/base..head) touches four webview files: - ZooGateway.tsx: the settings auto-init effect changes from if (!current || !modelIds.includes(current)) to if (!current). It now writes via setApiConfigurationField less often. It no longer overwrites a stored ID that is missing from the catalog. This removes a write rather than adding one. No new write, storage call, or await path is introduced. - useSelectedModel.ts: the selection logic now returns apiConfiguration.zooGatewayModelId || defaultModelId and reads catalog info with Object.hasOwn. It is a read-only display path. It adds zoo-gateway to the settled-fetch gate. It does not write or persist anything. - The two spec files only change tests. The configured ID is preserved for display. The backend already preserves the same ID, per the PR and the linked issue. The change therefore makes the displayed model match the model used for requests. It does not drop or corrupt stored state. No changed code path matches a failure condition in the check: no un-awaited persistence call, no non-atomic write, no missing rollback, and no persisted default that fails to reach its consumer. Context: refs/coderabbit/pre-merge-check/base and head are available, so the patch evidence is complete. No CodeRabbit review threads were supplied.

Full details: Lifecycle Resource Cleanup

Explanation

The check fails only for a changed lifecycle path that can leak a listener, watcher, provider, timer, task, or other resource, or that can duplicate work after cancellation, disposal, or restart. The PR changes four files in webview-ui. The committed diff (refs/coderabbit/pre-merge-check/base..head) shows these production changes: 1. webview-ui/src/components/settings/providers/ZooGateway.tsx: the auto-init effect now calls setApiConfigurationField only when zooGatewayModelId is empty. The effect has no subscription, timer, or cleanup function. Its dependency array is unchanged. The change reduces the number of field writes. It does not create a new lifecycle path. 2. webview-ui/src/components/ui/hooks/useSelectedModel.ts: hasValidRouterData adds Zoo Gateway to the existing LiteLLM/IO Intelligence !routerModels.isLoading group. This changes which render-time selection branch runs. It does not start a fetch, subscribe to anything, or add a timer. The router query is unchanged. 3. The zooGateway getSelectedModel case now returns the configured ID and reads model info with an own-property check. It is a pure synchronous computation. 4. The test files change assertions and add cases. They do not change runtime code. No changed code adds or removes a listener, watcher, provider, timer, or task. No changed code runs after a cancellation, disposal, or restart path. The changes are React render and state logic only. I found no concrete changed path that matches the check's failure condition.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Resolve the merge conflicts. The review sequence resumes after the branch is mergeable.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Nov 18, 2026
@myk1yt

myk1yt commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Nov 18, 2026
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

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.

@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer has-conflicts PR has merge conflicts with the base branch awaiting-author PR is waiting for the author to address requested changes and removed awaiting-maintainer CodeRabbit approved; waiting for a human maintainer labels Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes has-conflicts PR has merge conflicts with the base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zoo Gateway: configured model ID silently reverts to claude-sonnet default in UI

1 participant