Skip to content

fix(providers): refresh unavailable providers on request#357

Merged
SantiagoDePolonia merged 3 commits into
mainfrom
fix/reconnect-to-the-provider
May 28, 2026
Merged

fix(providers): refresh unavailable providers on request#357
SantiagoDePolonia merged 3 commits into
mainfrom
fix/reconnect-to-the-provider

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented May 27, 2026

Summary

  • refresh a provider's model inventory on provider-qualified requests when startup discovery left it unavailable
  • let preflight model resolution trigger the same provider refresh before returning unsupported model
  • clear stale availability errors after successful live model discovery so dashboard status can recover

Tests

  • go test ./internal/...
  • commit hooks: go import/fmt, make test-race, go mod tidy, hot-path performance guard, make lint

Summary by CodeRabbit

  • New Features

    • Request-time provider model refresh when resolution fails, registry is empty, or an alias target may become available; router exposes targeted refresh and registry refresh API; alias service can resolve refresh targets without catalog support.
  • Bug Fixes

    • Improved handling of provider availability timestamps and clearing stale availability errors; clearer error paths for refresh vs. unsupported/missing models.
  • Tests

    • Added tests for refresh-before-resolution, empty-registry behavior, alias-target refresh flows, and refresh error handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3344a123-f952-4d03-b275-8abc50cd06d6

📥 Commits

Reviewing files that changed from the base of the PR and between 8b576f2 and e895b16.

📒 Files selected for processing (2)
  • internal/gateway/request_model_resolution.go
  • internal/gateway/request_model_resolution_test.go

📝 Walkthrough

Walkthrough

Adds request-time provider model refresh across gateway, router, and registry so resolution can refresh provider inventories and retry when selectors fail, registries are empty, or models are unsupported.

Changes

Request-Time Provider Model Refresh

Layer / File(s) Summary
Provider model refresher interface
internal/gateway/request_model_resolution.go, internal/providers/router.go
Introduce optional refresh interfaces used by gateway/router to detect and call RefreshProviderModels(ctx, providerSelector).
Gateway resolution + refresh flow
internal/gateway/request_model_resolution.go, internal/gateway/request_model_resolution_test.go
ResolveRequestModelWithAuthorizer retries selector resolution after conditional provider refreshes for resolution errors, empty registries, or unsupported models; adds helper to derive refresh target and preserve alias-resolved selectors on provider errors; tests validate refresh ordering and error wrapping.
Registry: RefreshProviderModels implementation
internal/providers/registry_provider_refresh.go
New ModelRegistry.RefreshProviderModels and helpers: target resolution by name/type, availability filtering, runtime model fetch, atomic apply of fetched inventory, global map rebuild, cache invalidation, and aggregated error reporting.
Registry initialization & availability tracking
internal/providers/registry_init.go
Centralize metadata enrichment via enrichFetchedProviderModelMaps, record availability-check/OK timestamps during fetch/apply, and apply availability-related runtime updates (trim/clear errors, set timestamps).
Registry tests for availability & targeted refresh
internal/providers/registry_test.go
Tests for clearing prior availability errors on Initialize and for targeted refresh removing stale models when providers return empty inventories.
Router integration and request-time refresh
internal/providers/router.go, internal/providers/router_test.go
Context-aware resolveProvider(ctx, ...) triggers request-time refresh when providers are missing/unresolved, exposes Router.RefreshProviderModels, and includes tests covering qualified requests, targeted refresh, and unavailable-provider behavior.
Alias service refresh-target helper and test
internal/aliases/service.go, internal/aliases/service_test.go
Add Service.ResolveRefreshTarget to expose alias target selector without catalog availability checks; unit test ensures refresh-target resolution works even when catalog lacks the target.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client Request
  participant Gateway as Gateway
  participant Registry as ModelRegistry
  participant Router as Router
  participant Provider as Provider
  Client->>Gateway: ResolveRequestModelWithAuthorizer(requested)
  Gateway->>Registry: ResolveExecutionSelector(requested)
  alt selector fails / empty / unsupported
    Registry-->>Gateway: error or unsupported
    Gateway->>Registry: RefreshProviderModels(ctx, providerSelector)
    Registry->>Provider: CheckAvailability/ListModels
    Provider-->>Registry: models or error
    Registry->>Registry: applyFetchedInventory -> rebuild maps
    Registry-->>Gateway: refreshed count or error
    Gateway->>Registry: ResolveExecutionSelector(requested) (retry)
  end
  Registry-->>Gateway: resolved model
  Gateway->>Router: routeResolvedModelCall(ctx, resolved)
  Router->>Registry: ResolveExecutionSelector(resolved) or RefreshProviderModels if missing
  Router->>Provider: ChatCompletion
  Provider-->>Router: response
  Router-->>Client: response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ENTERPILOT/GoModel#177: Related selector/alias refactor that affects normalization and alias resolution used by refresh flows.
  • ENTERPILOT/GoModel#326: Overlapping changes to registry initialization and availability timestamp handling.

Poem

🐰 I nibble at stale model seeds at dawn,

I tap the providers until catalogs yawn,
A gentle refresh, then a hopeful retry,
Resolved selectors dance and requests fly.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enabling provider model refresh on request for unavailable providers, which is the core objective of this changeset.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/reconnect-to-the-provider

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 and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 27, 2026

Greptile Summary

This PR adds request-time provider inventory refresh when model resolution cannot find a requested provider model. It changes:

  • Targeted provider refresh through the registry and router.
  • Gateway model resolution retries after refreshing provider-qualified requests.
  • Alias refresh-target lookup without requiring current catalog support.
  • Runtime availability state updates after successful live discovery.
  • Tests for refresh recovery, alias targets, and empty refresh behavior.

Confidence Score: 4/5

This is close, but the batch path should be fixed before merging.

  • Translated request resolution now refreshes unavailable provider inventories.
  • Native inline batch selection still returns unsupported model before trying the same refresh.
  • The gap affects provider-qualified batch items after startup discovery left a provider empty.

internal/gateway/batch_selection.go

Important Files Changed

Filename Overview
internal/gateway/request_model_resolution.go Adds refresh and retry behavior for translated request model resolution.
internal/gateway/batch_selection.go Parallel model preflight path still lacks the new refresh behavior.
internal/providers/registry_provider_refresh.go Adds targeted registry refresh and inventory replacement for provider models.

Reviews (2): Last reviewed commit: "fix(gateway): surface refresh target res..." | Re-trigger Greptile

Comment thread internal/gateway/request_model_resolution.go Outdated
Comment thread internal/providers/registry_provider_refresh.go
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 27, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 65.57971% with 95 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/providers/registry_provider_refresh.go 68.46% 33 Missing and 8 partials ⚠️
internal/providers/router.go 55.35% 18 Missing and 7 partials ⚠️
internal/gateway/request_model_resolution.go 63.15% 12 Missing and 9 partials ⚠️
internal/aliases/service.go 38.46% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@internal/gateway/request_model_resolution_test.go`:
- Around line 167-222: Add a new unit test (e.g.,
TestResolveRequestModelRefreshTargetErrorHandling) that configures the request
refresh provider to make ResolveRefreshTarget return an error (use the existing
newRequestRefreshProvider or set the provider flag that triggers a resolve
error), call ResolveRequestModelWithAuthorizer with that provider and a selector
that triggers the refresh-target flow, and assert that
ResolveRequestModelWithAuthorizer returns a non-nil error which matches the
underlying ResolveRefreshTarget error; reference
requestRefreshTargetResolver/ResolveRefreshTarget and
ResolveRequestModelWithAuthorizer in the test to locate where to inject the
failure and the assertion.

In `@internal/gateway/request_model_resolution.go`:
- Around line 165-168: The code currently calls ResolveRefreshTarget on
targetResolver (type modelRefreshTargetResolver) and discards any error, which
masks real configuration/alias faults; change the logic in the block where
ResolveRefreshTarget(requested) is invoked so that when err != nil you return or
propagate that error (or wrap it with context) instead of silently ignoring it,
otherwise continue only when err == nil and ok == true and set providerSelector
accordingly; update the containing function's error flow to propagate the error
from ResolveRefreshTarget.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ee0e151c-0e67-4ff2-ba6c-c05f78f833d4

📥 Commits

Reviewing files that changed from the base of the PR and between 0778a27 and 8b576f2.

📒 Files selected for processing (6)
  • internal/aliases/service.go
  • internal/aliases/service_test.go
  • internal/gateway/request_model_resolution.go
  • internal/gateway/request_model_resolution_test.go
  • internal/providers/registry_provider_refresh.go
  • internal/providers/registry_test.go

Comment thread internal/gateway/request_model_resolution_test.go
Comment thread internal/gateway/request_model_resolution.go
@SantiagoDePolonia SantiagoDePolonia merged commit 666066b into main May 28, 2026
19 checks passed
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.

2 participants