Repository navigation
fix(discovery): keep credential catalogs independent #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
5224a4c
d539567
6bcb1a5
d6ff8e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| from decimal import Decimal | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| import json | ||
| import logging | ||
| import math | ||
| import re | ||
| import ssl | ||
|
|
@@ -40,6 +41,7 @@ | |
| from .cost_ledger import PriceBook | ||
|
|
||
| DISCOVERY_TIMEOUT_SECONDS = 15.0 | ||
| _LOGGER = logging.getLogger(__name__) | ||
| # Some discovery endpoints (verified live: models.dev returns Cloudflare HTTP | ||
| # 403 error 1010) reject urllib's default "Python-urllib/X.Y" user agent as a | ||
| # bot signature. A stable, identifying user agent is not a credential and is | ||
|
|
@@ -157,8 +159,8 @@ def configured_gateway_source( | |
| ) | ||
|
|
||
|
|
||
| # NVIDIA NIM is listed twice under two KV credential names (primary + sub) so both | ||
| # keys participate in upstream load balancing without a second provider identity. | ||
| # Each NVIDIA NIM KV credential is an independent account boundary and may expose | ||
| # a different catalog even though both currently use the same API endpoint. | ||
| PROVIDER_MODEL_SOURCES: tuple[ProviderModelSource, ...] = ( | ||
| ProviderModelSource( | ||
| provider_name="openai", | ||
|
|
@@ -442,9 +444,9 @@ def _price_per_1k(value: Any) -> float | None: | |
| return per_1k if _valid_price_component(per_1k) else None | ||
|
|
||
|
|
||
| def _serving_identity(model: DiscoveredModel) -> tuple[str, str]: | ||
| """Return the durable agent identity used by discovery synchronization.""" | ||
| return (model.provider_name, model.model_id) | ||
| def _serving_identity(model: DiscoveredModel) -> tuple[str, str, str]: | ||
| """Return the account-scoped identity used by discovery synchronization.""" | ||
| return (model.provider_name, model.credential_name, model.model_id) | ||
|
Comment on lines
+451
to
+453
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+451
to
+453
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| def _source_tiebreaker(model: DiscoveredModel) -> tuple[str, str, str, str]: | ||
|
|
@@ -462,13 +464,13 @@ def _deduplicate_discovered_models( | |
| ) -> list[DiscoveredModel]: | ||
| """Collapse duplicate agent identities and withhold conflicting price evidence. | ||
|
|
||
| Exact duplicate catalog rows become one candidate. When the same provider/model | ||
| identity is repeated with conflicting metadata or prices, one deterministic | ||
| transport record is retained but its prices become unknown. Provider row order | ||
| Exact duplicate catalog rows from one credential become one candidate. When the | ||
| same account/model identity repeats with conflicting metadata or prices, one | ||
| deterministic transport record is retained but its prices become unknown. Provider row order | ||
| therefore cannot fabricate a cheaper bootstrap candidate or consume failover | ||
| capacity twice. | ||
| """ | ||
| unique: dict[tuple[str, str], DiscoveredModel] = {} | ||
| unique: dict[tuple[str, str, str], DiscoveredModel] = {} | ||
| for model in discovered: | ||
| identity = _serving_identity(model) | ||
| previous = unique.get(identity) | ||
|
|
@@ -1110,7 +1112,15 @@ def discover_provider_models( | |
| """ | ||
| api_key = get_credential(source.credential_name) | ||
| if not api_key: | ||
| _LOGGER.debug( | ||
| "model discovery skipped account=%s reason=key_missing", | ||
| source.provider_name, | ||
| ) | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| return [] | ||
| _LOGGER.debug( | ||
| "model discovery started account=%s", | ||
| source.provider_name, | ||
| ) | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| url = source.list_url | ||
| if source.task_filter: | ||
| url = f"{url}?task={source.task_filter}" | ||
|
|
@@ -1131,7 +1141,13 @@ def discover_provider_models( | |
| # OSError covers ConnectionError/reset failures that are not URLError | ||
| # subclasses, so a raw provider transport failure can never escape the | ||
| # discovery boundary with provider text attached. | ||
| raise ProviderDiscoveryError(source.provider_name, _provider_discovery_error_code(exc)) from None | ||
| error_code = _provider_discovery_error_code(exc) | ||
| _LOGGER.debug( | ||
| "model discovery failed account=%s error_code=%s", | ||
| source.provider_name, | ||
| error_code, | ||
| ) | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| raise ProviderDiscoveryError(source.provider_name, error_code) from None | ||
| if source.models_dev_provider_id: | ||
| if models_dev_metadata is _NOT_FETCHED: | ||
| metadata = _fetch_models_dev_metadata(timeout=timeout) | ||
|
|
@@ -1175,7 +1191,13 @@ def discover_provider_models( | |
| discovered = _parse_bytez(payload, source) | ||
| else: | ||
| discovered = _parse_openai_compatible(payload, source) | ||
| return [replace(model, evidence_only=source.evidence_only) for model in discovered] | ||
| result = [replace(model, evidence_only=source.evidence_only) for model in discovered] | ||
| _LOGGER.debug( | ||
| "model discovery completed account=%s model_count=%d", | ||
| source.provider_name, | ||
| len(result), | ||
| ) | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| return result | ||
|
|
||
|
|
||
| def discover_all_models( | ||
|
|
@@ -1439,13 +1461,6 @@ def _discovery_price_key( | |
| return (0, cost, model.provider_name, model.model_id) | ||
|
|
||
|
|
||
| def _provider_family(provider_name: str) -> str: | ||
| """Collapse credentials that share one upstream provider outage domain.""" | ||
| if provider_name in {"nvidia_nim", "nvidia_nim_sub"}: | ||
| return "nvidia_nim" | ||
| return provider_name | ||
|
|
||
|
|
||
| def select_cheapest_discovered_agent( | ||
| discovered: list[DiscoveredModel], price_book: "PriceBook" | ||
| ) -> DiscoveredModel | None: | ||
|
|
@@ -1492,10 +1507,9 @@ def select_bootstrap_discovered_agents( | |
| """Build a deterministic, price-honest, provider-diverse initial pool. | ||
|
|
||
| Candidates retain the known-price-first ordering above, but the first pass | ||
| takes at most one model from each independent provider family. Remaining | ||
| capacity is filled in the same deterministic cost order. NVIDIA NIM primary | ||
| and sub credentials are one outage domain, so they participate in the second | ||
| pass only after independently hosted providers have had a chance to enter. | ||
| takes at most one model from each independently discovered provider account. | ||
| Remaining capacity is filled in the same deterministic cost order. No vendor | ||
| or endpoint name is used to infer a shared family or collapse credential state. | ||
| Duplicate serving identities never consume capacity twice. | ||
| """ | ||
| if limit <= 0: | ||
|
|
@@ -1514,14 +1528,13 @@ def select_bootstrap_discovered_agents( | |
| ) | ||
| selected: list[DiscoveredModel] = [] | ||
| deferred: list[DiscoveredModel] = [] | ||
| provider_families: set[str] = set() | ||
| providers: set[str] = set() | ||
|
|
||
| for model in ranked: | ||
| family = _provider_family(model.provider_name) | ||
| if family in provider_families: | ||
| if model.provider_name in providers: | ||
| deferred.append(model) | ||
| continue | ||
| provider_families.add(family) | ||
| providers.add(model.provider_name) | ||
| selected.append(model) | ||
| if len(selected) == limit: | ||
| return selected | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,6 @@ | |
| DiscoveredModel, | ||
| PROVIDER_MODEL_SOURCES, | ||
| _currency_is_comparable, | ||
| _provider_family, | ||
| agent_from_discovered, | ||
| agent_id_for, | ||
| discover_all_models, | ||
|
|
@@ -232,11 +231,10 @@ def select_provider_diverse_models( | |
| selected: list[DiscoveredModel] = [] | ||
| seen_providers: set[str] = set() | ||
| for model in ordered: | ||
| provider_family = _provider_family(model.provider_name) | ||
| if provider_family in seen_providers: | ||
| if model.provider_name in seen_providers: | ||
| continue | ||
| selected.append(model) | ||
| seen_providers.add(provider_family) | ||
| seen_providers.add(model.provider_name) | ||
|
Comment on lines
+234
to
+237
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Credential diversity still collapses accounts Both bootstrap selectors use provider names as diversity keys, so same-provider credential accounts compete for one first-pass slot. Tight limits exclude independent accounts. Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| if len(selected) >= limit: | ||
| return selected | ||
| selected_keys = { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Account-specific models share serving identities
When two credentials expose one provider and model,
_serving_identityretains both butagent_id_forgives them one ID. Synchronization overwrites one account, and either account’s pricing can govern both.Was this helpful? React with 👍 or 👎 to provide feedback.