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
fix(inference): stop attributing unscoped saas auth errors to every profile
Steven Enamakel0db6bb987047
diff --git a/crates/openhuman-core/src/inference/auth_error_registry.rs b/crates/openhuman-core/src/inference/auth_error_registry.rsindex cef4d07992..5d93fe0c36 100644--- a/crates/openhuman-core/src/inference/auth_error_registry.rs+++ b/crates/openhuman-core/src/inference/auth_error_registry.rs@@ -59,6 +59,10 @@ pub fn auth_error_message(provider: &str, status: u16) -> String {/// a 401 that repeats per-retry doesn't re-notify. An existing entry is/// refreshed (status / timestamp) and returns `false`.pub fn record(provider: &str, status: u16) -> bool {+ record_in_scope(provider, status, current_scope())+}++fn record_in_scope(provider: &str, status: u16, scope: CurrentScope) -> bool {let timestamp_ms = now_ms();let changed = registry().record(ProviderAuthError {provider: provider.to_string(),@@ -67,17 +71,26 @@ pub fn record(provider: &str, status: u16) -> bool {timestamp_ms,});let mut origins = origins().lock().unwrap_or_else(|error| error.into_inner());- let entry = origins.entry(provider.to_owned()).or_default();- if let CurrentScope::Bound(scope) = current_scope() {- entry.scopes.insert(- scope,- ScopedFailure {- status,- timestamp_ms,- },- );- } else {- entry.unscoped = true;+ match scope {+ CurrentScope::Bound(scope) => {+ origins+ .entry(provider.to_owned())+ .or_default()+ .scopes+ .insert(+ scope,+ ScopedFailure {+ status,+ timestamp_ms,+ },+ );+ }+ CurrentScope::Unbound => {+ origins.entry(provider.to_owned()).or_default().unscoped = true;+ }+ CurrentScope::Unresolved(error) => {+ log::warn!("[auth-errors] record provider={provider} skipped: scope unresolved ({error})");+ }}changed}@@ -183,9 +196,20 @@ fn origins() -> &'static Mutex<HashMap<String, ErrorOrigins>> {}fn current_scope() -> CurrentScope {- let Some(context) = crate::core::runtime::tenant::context_in(crate::core::runtime::is_saas())- else {- return CurrentScope::Unbound;+ let saas = crate::core::runtime::is_saas();+ current_scope_in(saas, crate::core::runtime::tenant::context_in(saas))+}++fn current_scope_in(+ saas: bool,+ context: Option<std::sync::Arc<crate::core::runtime::CoreContext>>,+) -> CurrentScope {+ let Some(context) = context else {+ return if saas {+ CurrentScope::Unresolved("no profile context in SaaS mode".to_owned())+ } else {+ CurrentScope::Unbound+ };};match context.workspace_config_binding() {Ok((workspace, config_path)) => CurrentScope::Bound(ScopeIdentity {diff --git a/crates/openhuman-core/src/inference/auth_error_registry_tests.rs b/crates/openhuman-core/src/inference/auth_error_registry_tests.rsindex 8873ec3c01..7923b963d1 100644--- a/crates/openhuman-core/src/inference/auth_error_registry_tests.rs+++ b/crates/openhuman-core/src/inference/auth_error_registry_tests.rs@@ -30,6 +30,26 @@ fn record_returns_true_only_on_first_episode() {reset_for_tests();}+#[test]+fn an_unscoped_saas_auth_error_is_not_attributed_to_every_profile() {+ let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());+ reset_for_tests();+ let scope = current_scope_in(true, None);+ assert!(matches!(scope, CurrentScope::Unresolved(_)));+ record_in_scope("saas-unscoped-provider", 401, scope);++ let workspace = tempfile::tempdir().expect("profile workspace");+ let (errors, has_unscoped) =+ snapshot_for_scope(workspace.path(), &workspace.path().join("config.toml"), None);+ assert!(errors.is_empty(), "an unscoped SaaS failure has no owner");+ assert!(!has_unscoped, "a SaaS failure is never marked single-user");+ assert!(+ !origins().lock().unwrap().contains_key("saas-unscoped-provider"),+ "the unresolved call must not create a process-wide origin"+ );+ reset_for_tests();+}+#[test]fn clear_removes_entry_and_rearms_latch() {let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex 899fd8758a..f48022890a 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -151,6 +151,8 @@ pub use ops::{ensure_loaded, ensure_loaded_within, state_of};pub use schemas::{all_controller_schemas, all_registered_controllers};#[doc(hidden)]pub use source::local_artifact;+#[doc(hidden)]+pub use source::staged_artifact;/// A `tinybus::module::ModuleClient` that loads modules lazily through the/// process-wide resolver (see [`ops`]). Constructing one starts nothing. In a/// build without the `modules` feature there is no loader, and every call isdiff --git a/tests/inbound_module_e2e.rs b/tests/inbound_module_e2e.rsindex 374cb2baf1..64b29bc331 100644--- a/tests/inbound_module_e2e.rs+++ b/tests/inbound_module_e2e.rs@@ -21,7 +21,7 @@ fn config() -> Config {config.modules.enabled = true;// A fallback to the release must fail loudly rather than download.config.modules.allow_download = false;- let artifact = openhuman_core::modules::local_artifact("tinyeventqueues")+ let artifact = openhuman_core::modules::staged_artifact("tinyeventqueues").expect("stage the verified TinyEventQueues release module");config.modules.overrides = vec![ModuleOverride::with_path("tinyeventqueues",