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(search): surface the credits-exhausted error on the managed path too
Shanu038f7c560586
diff --git a/src/openhuman/search/tools/exa.rs b/src/openhuman/search/tools/exa.rsindex f3588e77b8..d4ca349e1e 100644--- a/src/openhuman/search/tools/exa.rs+++ b/src/openhuman/search/tools/exa.rs@@ -240,7 +240,7 @@ impl ExaClient {Check your Exa API key under Connections > Search engine.");}- if status == reqwest::StatusCode::PAYMENT_REQUIRED || status.as_u16() == 402 {+ if status == reqwest::StatusCode::PAYMENT_REQUIRED {anyhow::bail!("Exa credits exhausted (HTTP 402). \Please top up your Exa account at dashboard.exa.ai or switch search provider."diff --git a/src/openhuman/search/tools/web_search.rs b/src/openhuman/search/tools/web_search.rsindex 6e8b557582..eeafb3503f 100644--- a/src/openhuman/search/tools/web_search.rs+++ b/src/openhuman/search/tools/web_search.rs@@ -15,6 +15,51 @@ use std::sync::Arc;/// through to the UI attribution ("Searched with …", #5136) with no code edit.const MANAGED_DEFAULT_PROVIDER: &str = "Exa";+/// Classify a managed-search backend failure that is really an upstream+/// provider quota or rate-limit fault.+///+/// The managed route resolves to a search provider server-side, so an upstream+/// 402/429 never reaches us as that status: the backend wraps it in its own+/// 4xx and the only trace is the provider's text carried in the detail. Left+/// unclassified it surfaces to the agent as `Backend returned 400 Bad Request+/// for POST /agent-integrations/parallel/search: {"error":"You have exceeded+/// your credits limit…"}`, which tells a user nothing they can act on (#5750).+///+/// Matching is on the *upstream* signature rather than our own status, so it+/// keeps working if the backend changes which 4xx it wraps the fault in, and+/// stays correct when the managed route resolves to a provider other than the+/// current default. Returns `None` for anything else, leaving the original+/// error — and its detail — exactly as it was.+///+/// The replacement text deliberately carries none of the original detail: the+/// provider echoes the submitted query back in its error body, and that body+/// would otherwise reach the agent transcript.+fn managed_search_quota_error(message: &str) -> Option<&'static str> {+ let lowered = message.to_ascii_lowercase();++ // Exa tags credit exhaustion explicitly; the numeric form covers providers+ // that only report the status. `credit` is required alongside the bare+ // status so an unrelated 402 in a URL or id cannot trip this.+ let credits_exhausted = lowered.contains("no_more_credits")+ || (lowered.contains("402") && lowered.contains("credit"));+ if credits_exhausted {+ return Some(+ "Managed web search is temporarily unavailable: the shared search credit pool is \+ exhausted. Configure your own search API key under Connections > Search engine to \+ keep searching, or try again later.",+ );+ }++ if lowered.contains("429") || lowered.contains("rate limit") {+ return Some(+ "Managed web search is rate limited upstream. Please wait a moment before searching \+ again, or configure your own search API key under Connections > Search engine.",+ );+ }++ None+}+/// Resolve the provider name to attribute a managed search to. Uses the/// backend-reported provider when present and non-empty, otherwise falls back/// to [`MANAGED_DEFAULT_PROVIDER`]. Shared with the `tools.web_search` RPC so@@ -305,7 +350,19 @@ impl Tool for WebSearchTool {let resp = client.post::<SearchResponse>("/agent-integrations/parallel/search", &body)- .await?;+ .await+ .map_err(+ |error| match managed_search_quota_error(&error.to_string()) {+ Some(actionable) => {+ // Log the classification, never the detail — it echoes the query.+ tracing::warn!(+ "[web_search] managed search unavailable: upstream quota fault"+ );+ anyhow::anyhow!(actionable)+ }+ None => error,+ },+ )?;// Attribute the search to the provider the managed backend resolved to// (Exa by default). The provider name is echoed in the result text sodiff --git a/src/openhuman/search/tools/web_search_tests.rs b/src/openhuman/search/tools/web_search_tests.rsindex b1bb284e6d..0dff06f09f 100644--- a/src/openhuman/search/tools/web_search_tests.rs+++ b/src/openhuman/search/tools/web_search_tests.rs@@ -598,3 +598,108 @@ async fn test_signed_out_store_does_not_reuse_the_cached_bearer_token() {"a signed-out tool must fail locally rather than appear to work: {result:?}");}++// ── Managed-search quota faults (#5750) ─────────────────────────────────────+//+// The managed route resolves to a provider server-side, so an upstream 402/429+// arrives wrapped in the backend's own 4xx. These cover the classifier that+// turns that into something a user can act on, and the end-to-end wiring.++#[test]+fn managed_quota_classifier_matches_exa_credit_exhaustion() {+ // The exact shape reported in #5750.+ let message = concat!(+ "Backend returned 400 Bad Request for POST ",+ "https://api.tinyhumans.ai/agent-integrations/parallel/search: ",+ r#"Exa API error (402): {"error":"You have exceeded your credits limit. "#,+ r#"Please top up to keep using Exa at dashboard.exa.ai","tag":"NO_MORE_CREDITS"}"#+ );++ let classified = managed_search_quota_error(message).expect("402 credits fault must classify");+ assert!(classified.contains("shared search credit pool is exhausted"));+ assert!(classified.contains("Connections > Search engine"));+}++#[test]+fn managed_quota_classifier_matches_the_tag_alone() {+ // A provider that reports the tag without the numeric status still classifies.+ let classified = managed_search_quota_error(r#"upstream said {"tag":"NO_MORE_CREDITS"}"#)+ .expect("the credits tag alone must classify");+ assert!(classified.contains("credit pool is exhausted"));+}++#[test]+fn managed_quota_classifier_matches_rate_limits() {+ for message in [+ "Backend returned 429 Too Many Requests for POST /agent-integrations/parallel/search: slow down",+ "Backend returned 400 Bad Request for POST /x: provider rate limit exceeded",+ ] {+ let classified =+ managed_search_quota_error(message).expect("rate-limit fault must classify");+ assert!(+ classified.contains("rate limited upstream"),+ "unexpected classification for {message:?}: {classified}"+ );+ }+}++#[test]+fn managed_quota_classifier_leaves_unrelated_failures_alone() {+ // Nothing here is a quota fault; each must fall through so the original+ // error (and its detail) reaches the caller unchanged.+ for message in [+ "Backend returned 500 Internal Server Error for POST /x: upstream exploded",+ "Backend returned 404 Not Found for POST /x: no such route",+ // A bare status that happens to appear in a port or id must not match+ // on its own — the classifier requires the word `credit` alongside it.+ "POST http://127.0.0.1:40200/agent-integrations/parallel/search failed: timed out",+ "Web search unavailable: no backend session token.",+ ] {+ assert!(+ managed_search_quota_error(message).is_none(),+ "must not classify as a quota fault: {message:?}"+ );+ }+}++#[tokio::test]+async fn test_execute_surfaces_actionable_error_when_managed_credits_are_exhausted() {+ // Replays the #5750 failure: the backend wraps Exa's 402 in a 400, so the+ // tool previously failed with `Backend returned 400 Bad Request …` plus the+ // raw provider JSON.+ let app = Router::new().route(+ "/agent-integrations/parallel/search",+ post(|| async {+ (+ axum::http::StatusCode::BAD_REQUEST,+ Json(json!({+ "success": false,+ "error": concat!(+ r#"Exa API error (402): {"error":"You have exceeded your credits "#,+ r#"limit for query: private search","tag":"NO_MORE_CREDITS"}"#+ )+ })),+ )+ }),+ );++ let base_url = start_mock_backend(app).await;+ let client = Arc::new(IntegrationClient::new(base_url, "test-token".into()));+ let error = WebSearchTool::new(Some(client), None, 5, 15)+ .execute(json!({"query": "private search"}))+ .await+ .expect_err("an exhausted managed credit pool must fail with an actionable message");+ let message = error.to_string();++ assert!(+ message.contains("shared search credit pool is exhausted"),+ "expected the actionable message, got: {message}"+ );+ assert!(message.contains("Connections > Search engine"));+ // The replacement carries none of the provider's body, which echoes the query.+ assert!(+ !message.contains("private search"),+ "the submitted query must not reach the transcript: {message}"+ );+ assert!(!message.contains("Backend returned 400"));+}