Skip to content

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

fix(inference): give each scope its own auth failure in the doctor read

M3gA-Minda1774744af7e
diff --git a/crates/openhuman-core/src/inference/auth_error_registry.rs b/crates/openhuman-core/src/inference/auth_error_registry.rs
index e82afc2c33..78dc77b568 100644
--- a/crates/openhuman-core/src/inference/auth_error_registry.rs
+++ b/crates/openhuman-core/src/inference/auth_error_registry.rs
@@ -214,10 +214,8 @@ pub fn snapshot_for_scope(
let errors = registry()
.snapshot()
.into_iter()
- .filter(|error| {
- let Some(origin) = origins.get(&error.provider) else {
- return false;
- };
+ .filter_map(|error| {
+ let origin = origins.get(&error.provider)?;
let partial_match = origin.scopes.keys().any(|recorded| {
recorded.config_path.is_none()
&& recorded.workspace == scope.workspace
@@ -226,13 +224,8 @@ pub fn snapshot_for_scope(
if partial_match {
has_unscoped = true;
}
- if origin.scopes.contains_key(&scope) {
- return true;
- }
- if !partial_match {
- return false;
- }
- false
+ // This scope's own status and time, not another scope's latest.
+ Some(origin.scopes.get(&scope)?.view(error))
})
.collect();
(errors, has_unscoped)
diff --git a/crates/openhuman-core/src/inference/auth_error_registry_tests.rs b/crates/openhuman-core/src/inference/auth_error_registry_tests.rs
index 133706d967..8873ec3c01 100644
--- a/crates/openhuman-core/src/inference/auth_error_registry_tests.rs
+++ b/crates/openhuman-core/src/inference/auth_error_registry_tests.rs
@@ -305,3 +305,43 @@ fn auth_errors_stay_in_the_scope_that_recorded_them() {
reset_for_tests();
});
}
+
+/// The doctor's scope read gets the status that scope recorded, not the one a
+/// later failure for the same provider in another config root left behind.
+#[test]
+fn a_scope_read_returns_that_scopes_own_status() {
+ with_test_lock(async {
+ reset_for_tests();
+ let workspace = tempfile::tempdir().expect("shared workspace");
+ let config_root_a = tempfile::tempdir().expect("config root A");
+ let config_root_b = tempfile::tempdir().expect("config root B");
+ let config_path_a = config_root_a.path().join("config.toml");
+ let config_path_b = config_root_b.path().join("config.toml");
+ let mut config = crate::config::Config::default();
+ config.workspace_dir = workspace.path().to_path_buf();
+ config.config_path = config_path_a.clone();
+ let context = crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ config,
+ );
+ crate::core::runtime::CoreContext::scope(context.clone(), async {
+ record("shared-provider", 401);
+ })
+ .await;
+ context
+ .rebind_workspace(workspace.path(), Some(&config_path_b))
+ .expect("rebind config origin");
+ crate::core::runtime::CoreContext::scope(context, async {
+ record("shared-provider", 403);
+ })
+ .await;
+
+ let status = |config_path: &std::path::Path| {
+ let (errors, _) = snapshot_for_scope(workspace.path(), config_path, None);
+ errors.iter().map(|error| error.status).collect::<Vec<_>>()
+ };
+ assert_eq!(status(&config_path_a), [401]);
+ assert_eq!(status(&config_path_b), [403]);
+ reset_for_tests();
+ });
+}