The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(inference): improve cloud slug model resolution logic
Steven Enamakel07124a531123
diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rsindex 94ab5b7e64..0a7030119a 100644--- a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs@@ -9,6 +9,8 @@ use crate::inference::provider::factory::access_gates::verify_backend_session_acuse crate::inference::provider::factory::access_gates::verify_session_active;use crate::inference::provider::fallback_diagnostics;use tinyinference_llm::providers::anthropic::endpoint_is_anthropic_messages;+use tinyinference_llm::providers::openai::codex::resolve_codex_routing;+use tinyinference_llm::providers::registry::resolve_slug_model;/// Look up a `cloud_providers` entry by slug and build the provider./// The shared resolution for a `<slug>:<model>` cloud provider — the cloud@@ -47,87 +49,74 @@ pub(super) fn resolve_cloud_slug_for<'a>()})?;- // Resolve effective model: use provided model if non-empty, else fall back- // to the entry's legacy default_model (if any), else empty → error.- let mut effective_model = if model.trim().is_empty() {- entry.default_model.clone().unwrap_or_default()- } else {- model.to_string()- };-- // Guard: if effective_model is still empty after fallback, bail with an- // actionable error. Sending an empty model string to providers like- // nvidia-nim causes a 400 "model field is required" — a confusing error- // that obscures the real cause (missing model in the provider string or- // unset default_model on the config entry).- // See https://github.com/tinyhumansai/openhuman/issues/2784.- //- // OpenhumanJwt entries are exempt: they always delegate to- // make_openhuman_backend which derives the model from config.default_model,- // ignoring whatever effective_model we computed here.let hosted = crate::config::schema::cloud_providers::is_hosted_auth_style_for(extensions,entry.auth_style,);- if !hosted && effective_model.trim().is_empty() {- log::warn!(- "[providers][chat-factory] role={} slug={} resolved to empty model — \- provider string must include a model id (e.g. '{}:<model-id>') or \- set default_model on the cloud_providers entry",- role,- slug,- slug,- );- anyhow::bail!(- "[chat-factory] no model configured: role '{}' resolved to an empty model id for slug '{}'. \- Include a model in the provider string (e.g. '{slug}:<model-id>') or \- set default_model on the cloud_providers entry for slug '{slug}'.",+ // Hosted routes derive their model from the managed provider and retain the+ // old permissive behavior. BYOK model fallback and hint classification are+ // shared with the provider owner.+ let effective_model = if hosted {+ if model.trim().is_empty() {+ entry.default_model.clone().unwrap_or_default()+ } else {+ model.to_string()+ }+ } else {+ match resolve_slug_model(model, entry.default_model.as_deref(), |candidate| {+ crate::inference::provider_model::is_abstract_model_for(+ extensions,+ PROVIDER_OPENHUMAN,+ candidate,+ )+ }) {+ Ok(model) => model,+ Err(tinyinference_llm::providers::registry::SlugModelError::MissingModel) => {+ log::warn!(+ "[providers][chat-factory] role={} slug={} resolved to empty model — \+ provider string must include a model id (e.g. '{}:<model-id>') or \+ set default_model on the cloud_providers entry",+ role,+ slug,+ slug,+ );+ anyhow::bail!(+ "[chat-factory] no model configured: role '{}' resolved to an empty model id for slug '{}'. \+ Include a model in the provider string (e.g. '{slug}:<model-id>') or \+ set default_model on the cloud_providers entry for slug '{slug}'.",+ role,+ slug,+ );+ }+ Err(tinyinference_llm::providers::registry::SlugModelError::NoConcreteDefault) => {+ anyhow::bail!(+ "[chat-factory] model '{}' is an abstract tier for role '{}', \+ but cloud provider slug '{}' has no concrete default_model configured. \+ Set cloud_providers[].default_model to a provider-native model id.",+ model,+ role,+ slug+ );+ }+ }+ };++ if !hosted && effective_model != model && !model.trim().is_empty() {+ log::info!(+ "[providers][chat-factory] role={} slug={} remapping abstract model {} -> {}",role,slug,+ model,+ effective_model);}- if !hosted- && crate::inference::provider_model::is_abstract_model_for(- extensions,- PROVIDER_OPENHUMAN,- &effective_model,- )- {- if let Some(default_model) = entry.default_model.as_deref().map(str::trim).filter(|m| {- !m.is_empty()- && !crate::inference::provider_model::is_abstract_model_for(- extensions,- PROVIDER_OPENHUMAN,- m,- )- }) {- log::info!(- "[providers][chat-factory] role={} slug={} remapping abstract model {} -> {}",- role,- slug,- effective_model,- default_model- );- effective_model = default_model.to_string();- } else {- anyhow::bail!(- "[chat-factory] model '{}' is an abstract tier for role '{}', \- but cloud provider slug '{}' has no concrete default_model configured. \- Set cloud_providers[].default_model to a provider-native model id (e.g. deepseek-v4-pro).",- effective_model,- role,- slug- );- }- }-log::info!("[providers][chat-factory] role={} slug={} model={} endpoint_host={}",role,slug,effective_model,- redact_endpoint(&entry.endpoint)+ super::super::redact_endpoint_origin(&entry.endpoint));// #5146 §2.1: a raw "failed to read API key for slug 'anthropic'" is@@ -186,8 +175,40 @@ pub(super) fn resolve_cloud_slug_for<'a>(anyhow::bail!("{}", missing_credentials());}let bearer_is_oauth = slug == "openai" && openai_bearer_is_oauth(config);- let codex = resolve_openai_codex_routing(config, slug, &entry.endpoint, &key, bearer_is_oauth)- .map_err(anyhow::Error::msg)?;+ let oauth_credentials = if slug == "openai" {+ match crate::security::credentials::openai_oauth::lookup_openai_oauth_credentials(config) {+ Ok(credentials) => credentials,+ Err(error) if !key.trim().is_empty() => {+ log::warn!(+ "[providers][openai-codex] oauth metadata unavailable; continuing with standard bearer key: {error}"+ );+ None+ }+ Err(error) => {+ return Err(anyhow::anyhow!(+ "[chat-factory] openai oauth lookup failed: {error}"+ ));+ }+ }+ } else {+ None+ };+ let has_oauth_credentials = oauth_credentials.is_some();+ let account_id = oauth_credentials+ .filter(|_| bearer_is_oauth)+ .and_then(|credentials| credentials.account_id);+ let using_codex_oauth = bearer_is_oauth && has_oauth_credentials;+ let mut codex = resolve_codex_routing(+ slug,+ &entry.endpoint,+ using_codex_oauth,+ account_id.as_deref(),+ );+ // The owner helper normalizes standard route slashes. The provider registry+ // previously received the configured endpoint verbatim, so preserve it.+ if !codex.using_oauth {+ codex.endpoint.clone_from(&entry.endpoint);+ }Ok(CloudSlugResolution {entry,