Skip to content

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

fix(inference): keep the expiry signal when redacting a lookup error

M3gA-Mind1035cfe52806
diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
index 846587e144..73e5f066d7 100644
--- a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
@@ -77,6 +77,30 @@ pub(crate) fn resolve_cloud_slug_for<'a>(
)
}
+/// The user-facing error for a failed credential lookup: the guidance, plus
+/// the expiry signal when the lookup reported one. The doctor's
+/// refresh-required check and the Codex reconnect classifier key on those
+/// fixed phrases; the rest of the lookup error can carry stored-credential
+/// content or a refresh response's body, so it is dropped.
+pub(super) fn lookup_failure(error: &anyhow::Error, guidance: String) -> anyhow::Error {
+ let text = format!("{error:#}");
+ let signal = if text.contains(super::credentials::OAUTH_REFRESH_REQUIRED) {
+ Some(super::credentials::OAUTH_REFRESH_REQUIRED)
+ } else if tinyinference_llm::failure::is_codex_token_expired_text(&text.to_ascii_lowercase()) {
+ Some(CODEX_TOKEN_EXPIRED)
+ } else {
+ None
+ };
+ match signal {
+ Some(signal) => anyhow::anyhow!("{guidance} (underlying error: {signal})"),
+ None => anyhow::anyhow!("{guidance}"),
+ }
+}
+
+/// The Codex OAuth expiry phrase (`openai_oauth::store`) the reconnect
+/// classifier recognises.
+const CODEX_TOKEN_EXPIRED: &str = "Codex authentication token is expired";
+
pub(super) fn resolve_cloud_slug_with_access<'a>(
role: &str,
slug: &str,
@@ -225,12 +249,12 @@ pub(super) fn resolve_cloud_slug_with_access<'a>(
(String::new(), false, None)
} else if credential_access == CredentialAccess::Inspection {
let credential = super::credentials::lookup_key_for_slug_read_only(slug, config)
- .map_err(|_| anyhow::anyhow!("{}", missing_credentials()))?;
+ .map_err(|error| lookup_failure(&error, missing_credentials()))?;
(credential.key, credential.is_oauth, credential.account_id)
} else {
let key = credential_access
.lookup_key_for_slug(slug, config)
- .map_err(|_| anyhow::anyhow!("{}", missing_credentials()))?;
+ .map_err(|error| lookup_failure(&error, missing_credentials()))?;
let is_oauth = slug == "openai" && credential_access.openai_bearer_is_oauth(config);
(key, is_oauth, None)
};
diff --git a/crates/openhuman-core/src/inference/provider/factory/credentials.rs b/crates/openhuman-core/src/inference/provider/factory/credentials.rs
index c424816269..0afa050ff8 100644
--- a/crates/openhuman-core/src/inference/provider/factory/credentials.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/credentials.rs
@@ -41,6 +41,10 @@ impl CredentialAccess {
}
}
+/// The read-only lookup's secret-free report that an OAuth token is due for
+/// a refresh it does not perform.
+pub(super) const OAUTH_REFRESH_REQUIRED: &str = "OpenAI OAuth credential requires refresh";
+
pub(super) struct ReadOnlyCloudCredential {
pub(super) key: String,
pub(super) is_oauth: bool,
@@ -72,7 +76,7 @@ pub(super) fn lookup_key_for_slug_read_only(
expires_at <= chrono::Utc::now() + chrono::Duration::minutes(2)
})
{
- anyhow::bail!("OpenAI OAuth credential requires refresh");
+ anyhow::bail!("{OAUTH_REFRESH_REQUIRED}");
}
if !key.trim().is_empty() {
return Ok(ReadOnlyCloudCredential {
@@ -97,7 +101,7 @@ pub(super) fn lookup_key_for_slug_read_only(
if expires_at.is_some_and(|expires_at| {
expires_at <= chrono::Utc::now() + chrono::Duration::minutes(2)
}) {
- anyhow::bail!("OpenAI OAuth credential requires refresh");
+ anyhow::bail!("{OAUTH_REFRESH_REQUIRED}");
}
return Ok(ReadOnlyCloudCredential {
key,
diff --git a/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs b/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs
index 2655c83516..379f620a06 100644
--- a/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs
@@ -360,3 +360,34 @@ fn the_route_resolves_to_a_provider_the_factory_can_build() {
.expect("the per-call route builds a chat model");
assert_eq!(model_id, "x/y");
}
+
+#[test]
+fn a_failed_lookup_keeps_only_its_expiry_signal() {
+ // The doctor reports "requires refresh" and chat routes a Codex expiry to
+ // the reconnect copy, both from these fixed phrases; the detail beside
+ // them (a refresh response's body) stays out.
+ use super::super::cloud_slug::lookup_failure;
+ let guidance = || "No usable credentials for 'openai'.".to_string();
+ for (error, signal) in [
+ (
+ anyhow::anyhow!("OpenAI OAuth credential requires refresh"),
+ "requires refresh",
+ ),
+ (
+ anyhow::anyhow!(
+ "Codex authentication token is expired — refresh failed: leak-marker. Please reconnect Codex."
+ ),
+ "Codex authentication token is expired",
+ ),
+ ] {
+ let message = lookup_failure(&error, guidance()).to_string();
+ assert!(message.contains(signal), "{message}");
+ assert!(message.contains("No usable credentials"), "{message}");
+ assert!(!message.contains("leak-marker"), "{message}");
+ }
+ let message = lookup_failure(
+ &anyhow::anyhow!("store read failed: leak-marker"),
+ guidance(),
+ );
+ assert_eq!(message.to_string(), guidance());
+}