Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(config): update cloud provider seeding logic

Steven Enamakelc9f629affe03
diff --git a/crates/openhuman-core/src/config/migrations/mod.rs b/crates/openhuman-core/src/config/migrations/mod.rs
index 21980c39e1..3b309d0c92 100644
--- a/crates/openhuman-core/src/config/migrations/mod.rs
+++ b/crates/openhuman-core/src/config/migrations/mod.rs
@@ -40,35 +40,10 @@ mod unify_ai_provider_settings;
/// Current target schema version. Bumped alongside every new migration.
pub const CURRENT_SCHEMA_VERSION: u32 = 14;
-/// Give a brand-new [`Config`] the managed `openhuman` cloud-provider entry.
-///
-/// A fresh workspace is created already stamped at [`CURRENT_SCHEMA_VERSION`]
-/// (`Config::load_or_init`), so **every** version gate in [`run_pending`] is
-/// false on its first launch — including the `== 1` step that is the only place
-/// the managed entry has ever been seeded. Nothing was missed and no migration
-/// failed: the entry was simply never created, and no later run can create it,
-/// because the gate that would have is behind a version the workspace skipped.
-///
-/// That is why this is called at the creation site rather than expressed as a
-/// migration. A migration cannot fix a config that is born at the target
-/// version, and bumping [`CURRENT_SCHEMA_VERSION`] to add one only moves the
-/// same hole forward a number.
-///
-/// Seeding is *not* folded into `Config::default()` on purpose. `Config` has no
-/// container-level `#[serde(default)]`, so a default-constructed provider list
-/// would not reach deserialization anyway — but it would reach every test and
-/// helper that builds a `Config` from `Default`, and [`seed_cloud_providers`]
-/// early-returns on a non-empty list. The migration tests that assert "empty
-/// list gets seeded" would then be asserting nothing at all.
-///
-/// [`seed_cloud_providers`]: unify_ai_provider_settings::seed_cloud_providers
+/// Run registered host initializers for a new configuration before its first
+/// save. Bare core has no initializer and remains host-neutral.
pub(crate) fn seed_new_workspace(config: &mut Config) {
- let mut stats = unify_ai_provider_settings::MigrationStats::default();
- unify_ai_provider_settings::seed_cloud_providers(config, &mut stats);
- log::debug!(
- "[migrations] new workspace seeded with {} cloud provider(s)",
- stats.cloud_providers_seeded
- );
+ crate::inference::registry::normalize_config(config);
}
/// Run any migrations whose `schema_version` gate hasn't yet been
diff --git a/crates/openhuman-core/src/config/migrations/unify_ai_provider_settings.rs b/crates/openhuman-core/src/config/migrations/unify_ai_provider_settings.rs
index c35eeed74e..6f9447f8fc 100644
--- a/crates/openhuman-core/src/config/migrations/unify_ai_provider_settings.rs
+++ b/crates/openhuman-core/src/config/migrations/unify_ai_provider_settings.rs
@@ -1,5 +1,5 @@
//! Migration 1 → 2: unify the scattered AI provider settings into the new
-//! per-workload provider-string fields, and seed the `cloud_providers` list.
+//! per-workload provider-string fields and preserve legacy custom endpoints.
//!
//! ## What this migration consolidates
//!
@@ -36,14 +36,10 @@
//! successful run is a no-op.
//! - Never touches keys / secrets. API keys remain in
//! `auth-profiles.json` via [`crate::security::credentials::AuthService`].
-//! - Always seeds an `Openhuman` entry into `cloud_providers` (idempotent —
-//! only when the list is empty).
//! - Migrates `inference_url` into a `Custom` cloud provider entry when the
-//! URL doesn't look like the OpenHuman backend.
+//! URL doesn't look like a registered managed backend.
-use crate::config::schema::cloud_providers::{
- builtin_cloud_provider, generate_provider_id, AuthStyle, CloudProviderCreds,
-};
+use crate::config::schema::cloud_providers::{generate_provider_id, AuthStyle, CloudProviderCreds};
use crate::config::Config;
/// Counters returned by [`run`] for diagnostics. Logged at INFO once per
@@ -63,7 +59,7 @@ pub struct MigrationStats {
pub fn run(config: &mut Config) -> anyhow::Result<MigrationStats> {
let mut stats = MigrationStats::default();
- seed_cloud_providers(config, &mut stats);
+ seed_legacy_custom_provider(config, &mut stats);
set_primary_cloud(config, &mut stats);
derive_workload_providers(config, &mut stats);
@@ -76,44 +72,8 @@ pub fn run(config: &mut Config) -> anyhow::Result<MigrationStats> {
Ok(stats)
}
-/// Seed `cloud_providers` with an OpenHuman entry (and optionally a Custom
-/// entry derived from a legacy `inference_url`).
-pub(super) fn seed_cloud_providers(config: &mut Config, stats: &mut MigrationStats) {
- if !config.cloud_providers.is_empty() {
- log::debug!(
- "[migrations][unify-ai] cloud_providers already populated ({} entries), skipping seed",
- config.cloud_providers.len()
- );
- return;
- }
-
- // Always seed the OpenHuman entry — even if api_url is None, the factory
- // resolves a sensible default at runtime.
- let oh_endpoint = config
- .api_url
- .clone()
- .filter(|s| !s.trim().is_empty())
- .unwrap_or_else(|| {
- builtin_cloud_provider("openhuman")
- .expect("managed builtin")
- .endpoint
- .to_string()
- });
- let oh_default_model = config
- .default_model
- .clone()
- .filter(|s| !s.trim().is_empty())
- .unwrap_or_else(|| crate::config::MODEL_MANAGED_DEFAULT.to_string());
- config.cloud_providers.push(CloudProviderCreds {
- id: generate_provider_id("openhuman"),
- slug: "openhuman".to_string(),
- label: "OpenHuman".to_string(),
- endpoint: oh_endpoint,
- auth_style: AuthStyle::OpenhumanJwt,
- default_model: Some(oh_default_model),
- });
- stats.cloud_providers_seeded += 1;
-
+/// Preserve a custom endpoint from the legacy `inference_url` field.
+fn seed_legacy_custom_provider(config: &mut Config, stats: &mut MigrationStats) {
let hosts = crate::config::enrichers::managed_hosts_for(config);
// If there's a legacy `inference_url` pointing at a non-OpenHuman
diff --git a/crates/openhuman-core/src/config/schema/cloud_providers.rs b/crates/openhuman-core/src/config/schema/cloud_providers.rs
index a35d68067b..7ce0518fb0 100644
--- a/crates/openhuman-core/src/config/schema/cloud_providers.rs
+++ b/crates/openhuman-core/src/config/schema/cloud_providers.rs
@@ -78,7 +78,7 @@ pub fn builtin_cloud_providers() -> Vec<BuiltinCloudProvider> {
.collect()
}
-pub(crate) fn builtin_cloud_provider(type_str: &str) -> Option<BuiltinCloudProvider> {
+pub fn builtin_cloud_provider(type_str: &str) -> Option<BuiltinCloudProvider> {
builtin_cloud_providers()
.into_iter()
.find(|provider| provider.slug == type_str)
diff --git a/crates/openhuman-embed/src/host_internals.rs b/crates/openhuman-embed/src/host_internals.rs
index 3a7e4c81a8..d6ce0c0aab 100644
--- a/crates/openhuman-embed/src/host_internals.rs
+++ b/crates/openhuman-embed/src/host_internals.rs
@@ -133,8 +133,9 @@ pub mod config {
};
pub mod cloud_providers {
pub use openhuman_core::config::schema::cloud_providers::{
- endpoint_host, host_is_builtin_cloud_provider, register_hosted_auth_style,
- register_hosted_cloud_preset, AuthStyle, BuiltinCloudProvider,
+ builtin_cloud_provider, endpoint_host, generate_provider_id,
+ host_is_builtin_cloud_provider, register_hosted_auth_style,
+ register_hosted_cloud_preset, AuthStyle, BuiltinCloudProvider, CloudProviderCreds,
HostedAuthStyleClassifier,
};
}
diff --git a/crates/openhuman-tinyhumans/src/inference/tiers.rs b/crates/openhuman-tinyhumans/src/inference/tiers.rs
index c20d79fe4f..772bb55b08 100644
--- a/crates/openhuman-tinyhumans/src/inference/tiers.rs
+++ b/crates/openhuman-tinyhumans/src/inference/tiers.rs
@@ -131,5 +131,22 @@ pub(crate) fn normalize_config(config: &mut Config) -> bool {
for route in &mut config.model_routes {
changed |= rewrite(&mut route.model);
}
+ if config.cloud_providers.is_empty() {
+ if let Some(preset) = openhuman_embed::__host::config::schema::cloud_providers::builtin_cloud_provider("openhuman") {
+ let id = openhuman_embed::__host::config::schema::cloud_providers::generate_provider_id("openhuman");
+ config.cloud_providers.push(openhuman_embed::__host::config::schema::cloud_providers::CloudProviderCreds {
+ id: id.clone(),
+ slug: preset.slug.to_string(),
+ label: preset.label.to_string(),
+ endpoint: config.api_url.as_deref().filter(|url| !url.trim().is_empty()).unwrap_or(preset.endpoint).to_string(),
+ auth_style: preset.auth_style,
+ default_model: config.default_model.clone(),
+ });
+ if config.primary_cloud.is_none() && config.inference_url.as_deref().is_none_or(|url| url.trim().is_empty()) {
+ config.primary_cloud = Some(id);
+ }
+ changed = true;
+ }
+ }
changed
}