Skip to content

refactor(providers): canonicalize model-router calls - #1165

Open
WebMad wants to merge 4 commits into
Zoo-Code-Org:mainfrom
WebMad:refactor/944-canonicalize-model-router-calls
Open

refactor(providers): canonicalize model-router calls#1165
WebMad wants to merge 4 commits into
Zoo-Code-Org:mainfrom
WebMad:refactor/944-canonicalize-model-router-calls

Conversation

@WebMad

@WebMad WebMad commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • use the shared providerIdentifiers registry for model-router provider options and cache calls
  • canonicalize OpenRouter endpoint routing, LM Studio/Kimi Code/Requesty/Unbound/Poe cache access, and webview router candidates and filters
  • preserve all existing serialized and wire provider values

Validation

  • npx vitest run api/providers/__tests__/poe.spec.ts api/providers/fetchers/__tests__/modelEndpointCache.spec.ts core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts — 28 tests passed
  • pnpm run check-types in src — passed
  • repository pre-commit lint — passed
  • repository pre-push type checks — passed

Related to #944 (remaining-work item 4).

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency and reliability across AI provider and router integrations.
    • Enhanced model discovery, caching, filtering, and refresh behavior.
    • Improved handling of missing credentials, project settings, and custom endpoints.
    • Preserved existing provider behavior while reducing configuration-related issues.
  • Tests

    • Expanded coverage for model loading, cache refreshes, unsaved credentials, provider filtering, error handling, and custom endpoints.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd14c2c3-59e4-442d-aae0-c172c208751e

📥 Commits

Reviewing files that changed from the base of the PR and between efcfa3b and 0a2276f.

📒 Files selected for processing (1)
  • src/api/providers/__tests__/poe.spec.ts

Included review availability: Your plan includes up to 4 reviews per rolling hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Provider handlers now use shared fallback constants. Provider fetchers and webview routing now use shared providerIdentifiers values. Tests cover LM Studio loading, router model refresh paths, cache lookups, and Poe telemetry.

Changes

Provider constant centralization

Layer / File(s) Summary
Standardize fallback values
src/api/providers/constants.ts, src/api/providers/*.ts
Provider handlers use NOT_PROVIDED for missing API keys, project settings, regions, and authorization values. Kimi Code also uses shared authentication-method constants.
Update provider fetcher identifiers
src/api/providers/fetchers/*, src/api/providers/*.ts
Provider handlers and fetchers use shared identifiers for provider names, model discovery, validation, cache lookup, and cache flushing.
Canonicalize webview routing and tests
src/core/webview/webviewMessageHandler.ts, src/core/webview/__tests__/*, src/api/providers/**/__tests__/*
Webview routing uses shared identifiers for candidates, cache operations, provider options, and local provider requests. Tests cover Poe, DeepSeek, OpenRouter, LiteLLM, Moonshot, model-cache, and LM Studio flows.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0a227

This refactor preserves existing provider values while standardizing model-router calls, and the reported checks pass; no actionable merge-blocking risk remains after normal review.

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: taltas

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the change summary and validation results but omits the required template sections and pre-submission checklist. Use the repository template headings, provide the linked issue in the required format, complete the checklist, and address documentation and reviewer notes sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: canonicalizing provider model-router calls.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api/providers/__tests__/poe.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


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

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

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review has-conflicts PR has merge conflicts with the base branch and removed awaiting-review PR changes are ready and waiting for maintainer re-review has-conflicts PR has merge conflicts with the base branch labels Aug 5, 2026
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed has-conflicts PR has merge conflicts with the base branch labels Aug 10, 2026
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review has-conflicts PR has merge conflicts with the base branch and removed awaiting-review PR changes are ready and waiting for maintainer re-review has-conflicts PR has merge conflicts with the base branch labels Aug 14, 2026
@WebMad
WebMad force-pushed the refactor/944-canonicalize-model-router-calls branch from ac0b8f2 to 59c2359 Compare August 16, 2026 21:01
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions github-actions Bot removed the has-conflicts PR has merge conflicts with the base branch label Aug 16, 2026
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 16, 2026

// flushModels should NOT have been called for litellm
const litellmFlushCalls = flushModelsMock.mock.calls.filter((c: any[]) => c[0] === "litellm")
const litellmFlushCalls = flushModelsMock.mock.calls.filter((c: any[]) => c[0] === providerIdentifiers.litellm)

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.

c[0] is an options object — comparing it to a string with === is always false, so litellmFlushCalls is always [] and this assertion cannot fail. The getModels filter two lines down already uses the correct pattern.

Suggested change
const litellmFlushCalls = flushModelsMock.mock.calls.filter((c: any[]) => c[0] === providerIdentifiers.litellm)
const litellmFlushCalls = flushModelsMock.mock.calls.filter((c: any[]) => c[0]?.provider === providerIdentifiers.litellm)

try {
const [models, endpoints] = await Promise.all([
getModels({ provider: "openrouter" }),
getModels({ provider: providerIdentifiers.openrouter }),

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.

This PR canonicalized the getModels / getModelEndpoints calls to use providerIdentifiers.openrouter. Should the ApiProviderError calls in handleStreamingError, createMessage, and completePrompt also use providerIdentifiers.openrouter instead of this.providerName ("OpenRouter") for consistency in telemetry grouping? poe.ts was migrated in the same PR.

})

if (!providerFilter || providerFilter === "kimi-code") {
if (!providerFilter || providerFilter === providerIdentifiers.kimiCode) {

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.

Does the routerModels spec have coverage for this branch? I do not see tests for providerFilter === providerIdentifiers.kimiCode, or for the api-key vs. OAuth dispatch and the null-token exclusion inside it.

const result = handler.getModel()

expect(getModelsFromCache).toHaveBeenCalledWith({
provider: providerIdentifiers.poe,

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.

Since both the production code and this assertion import providerIdentifiers.poe, a regression where production reverts to the literal "poe" goes undetected here. Would using the string literal "poe" in the expectation be more mutation-resistant? (The constant's string value is already pinned in provider-identifiers.test.ts.)

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Aug 16, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants