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(web_chat): correct error copy fixture test assertions
Steven Enamakel03cbeb8bce31
diff --git a/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rsindex 4bfead8033..2adce38a76 100644--- a/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs+++ b/crates/openhuman-core/src/web_chat/web_tests_error_copy_fixture_tests.rs@@ -1,55 +1,283 @@-//! GENERATOR (temporary)+//! Literal fixture for the user-facing failure copy (wave 5 "error copy table").+//!+//! Captured from the pre-refactor behaviour: for each failure class the exact+//! `error_type` wire token, `source`, `retryable`, retry-after, provider,+//! fallback flag and user copy. The refactor into one host copy table must keep+//! every row byte-identical. The budget-phrase section additionally compares the+//! shared matcher against verbatim copies of the three legacy matchers+//! (web_chat regex list, triage whole-word list, loop-guard billing list).+use super::*;+use crate::agent::triage::evaluator::{classify_error, ArmError};+use regex::Regex;++/// `(case, input, error_type, source, retryable, retry_after_ms, provider,+/// fallback_available, message)`.+#[allow(clippy::type_complexity)]+const EXPECTED: &[(+ &str,+ &str,+ &str,+ &str,+ bool,+ Option<u64>,+ Option<&str>,+ Option<bool>,+ &str,+)] = &[+ ("codex_expired", "Codex authentication token is expired; sign in again", "provider_error", "auth", false, None, Some("openai_codex"), None, "Your Codex session has expired. Please reconnect it in Settings → Integrations."),+ ("session_expired", "SESSION_EXPIRED", "session_expired", "auth", false, None, None, None, "Your OpenHuman session has expired. Please sign in again to continue."),+ ("action_budget", "Action blocked: rate limit exceeded for tool curl", "action_budget_exceeded", "openhuman_budget", true, None, None, None, "You've hit OpenHuman's per-hour action budget — this is a local safety cap, not your AI provider. The window decays gradually; you can keep chatting in this thread and tool-heavy steps will resume as the budget refills."),+ ("max_iterations", "Agent exceeded maximum tool iterations (10)", "max_iterations", "agent_loop", true, None, None, None, "The agent ran the maximum number of tool steps for one turn without finishing. This usually means a tool kept failing (often a rate limit on a web fetch). You can retry the same question in this thread once the underlying limit clears."),+ ("turn_timeout_marker", "openhuman_turn_wall_clock_timeout: agent turn exceeded its 600s wall-clock budget", "turn_timeout", "agent_loop", true, None, None, None, "This turn ran past its time budget without finishing and was stopped so it wouldn't hang. This usually means a tool call or a delegated sub-agent stalled. You can retry your question in this thread."),+ ("turn_timeout_harness", "run timed out: tool call for run `x` exceeded its remaining wall-clock budget (5 ms)", "turn_timeout", "agent_loop", true, None, None, None, "This turn ran past its time budget without finishing and was stopped so it wouldn't hang. This usually means a tool call or a delegated sub-agent stalled. You can retry your question in this thread."),+ ("empty_response", "The model returned an empty response. Please try again.", "empty_response", "agent_loop", true, None, None, None, "The model returned an empty response. Please retry. If it keeps happening, try a different model or check its setup in Connections → API keys → LLM."),+ ("chat_template", "openai API error (400): Jinja Exception: No user query found in messages.", "chat_template_rejected", "provider", true, None, Some("openai"), None, "This model's chat template rejected the request — it isn't the model, the temperature, or your API key. Local models without native tool calling are driven through their own chat template, and some templates refuse the message shape of a tool step. Start a new chat to reset the history, or pick a model with native tool support in Connections → API keys → LLM."),+ ("rate_limited_transient", "openrouter API error (429 Too Many Requests): Retry-After: 30", "rate_limited", "provider", true, Some(30000), Some("openrouter"), None, "Your AI provider is rate-limiting requests. This is a transient upstream limit, not a thread-level block — you can retry in this thread. Try again in 30 seconds."),+ ("rate_limited_business", "openai API error (429): plan does not include this model; insufficient balance", "rate_limited", "provider", false, None, Some("openai"), None, "Your AI provider is rejecting requests for billing or plan reasons (out of credits, plan limit, or unavailable model). Retrying won't help — open Settings to top up, upgrade your plan, or pick a different model."),+ ("timeout", "request timed out after 30s", "timeout", "transport", true, None, None, None, "The request timed out. Please check your connection and try again."),+ ("auth_error", "openai API error (401 Unauthorized): invalid api key", "auth_error", "config", false, None, Some("openai"), None, "There's an authentication issue with the AI provider. Please check your API key in settings."),+ ("budget_402", "openai API error (402 Payment Required)", "budget_exhausted", "provider", false, None, Some("openai"), None, "You're out of credits, so I can't run the managed (cloud) model right now. You can top up your credits or pick a plan to continue — or, if you've enabled a local model like Ollama, switch routing to \"Use Your Own Models\" in Connections → API keys → LLM."),+ ("budget_phrase", "Insufficient budget: please top up", "budget_exhausted", "openhuman_billing", false, None, None, None, "You're out of credits, so I can't run the managed (cloud) model right now. You can top up your credits or pick a plan to continue — or, if you've enabled a local model like Ollama, switch routing to \"Use Your Own Models\" in Connections → API keys → LLM."),+ ("budget_phrase_provider_source", "openrouter API error (400): out of credits", "budget_exhausted", "provider", false, None, Some("openrouter"), None, "You're out of credits, so I can't run the managed (cloud) model right now. You can top up your credits or pick a plan to continue — or, if you've enabled a local model like Ollama, switch routing to \"Use Your Own Models\" in Connections → API keys → LLM."),+ ("provider_5xx", "anthropic API error (503 Service Unavailable)", "provider_error", "provider", true, None, Some("anthropic"), None, "The AI provider is temporarily unavailable. Please try again later."),+ ("context_overflow", "context length exceeded", "context_overflow", "config", false, None, None, None, "The conversation is too long. Please start a new chat."),+ ("config_rejection", "openai API error (400): model `reasoning-v1` does not exist", "model_unavailable", "config", false, None, Some("openai"), None, "The selected model isn't available on your provider. Check your model settings."),+ ("model_unavailable", "model foo not found on this endpoint", "model_unavailable", "config", false, None, None, None, "The selected model isn't available on your provider. Check your model settings."),+ ("model_transient", "the model is temporarily unavailable", "provider_error", "provider", true, None, None, None, "The AI provider is temporarily unavailable. Please try again later."),+ ("vision", "provider_capability_error capability=vision does not support vision input", "capability_unsupported", "config", false, None, None, None, "This model can't process images. Remove the attachment or switch to a vision-capable model in Connections → API keys → LLM."),+ ("malformed_history_byo", "openai API error (400): messages with role 'tool' must be a response to a preceding message with 'tool_calls'", "provider_request_rejected", "provider", true, None, Some("openai"), None, "We hit a temporary glitch in this conversation — we've cleared it. Please send your message again."),+ ("request_rejected_4xx", "someprovider API error (422 Unprocessable Entity): bad thing", "provider_request_rejected", "provider", false, None, Some("someprovider"), None, "The AI provider rejected the request — this is usually a model or parameter incompatibility. Try a different model in Connections → API keys → LLM."),+ ("network", "error sending request: connection reset by peer", "network", "transport", true, None, None, None, "The connection to the AI service dropped mid-response — usually a sleep/wake or network change. Please try again."),+ ("transient_529", "anthropic API error (529): overloaded", "provider_error", "provider", true, None, Some("anthropic"), None, "The AI provider is temporarily unavailable. Please try again later."),+ ("generic", "kaboom", "inference", "provider", true, None, None, None, "Something went wrong. Please try again."),+ ("fallback_chain", "All providers/models failed. Attempts: x", "inference", "provider", true, None, None, Some(false), "Something went wrong. Please try again."),+ ("be_rate_limited", "OpenHuman API error (429): {\"error\":{\"errorCode\":\"RATE_LIMITED\",\"retryAfter\":30}}", "rate_limited", "provider", true, Some(30000), Some("openhuman"), None, "Your AI provider is rate-limiting requests. You can retry in this thread. Try again in 30 seconds."),+ ("be_credits", "OpenHuman API error (402): {\"error\":{\"errorCode\":\"USER_INSUFFICIENT_CREDITS\"}}", "budget_exhausted", "openhuman_billing", false, None, Some("openhuman"), None, "You're out of credits. Top up, or switch to 'Use Your Own Models' in Settings."),+ ("be_upstream", "OpenHuman API error (502): {\"error\":{\"errorCode\":\"UPSTREAM_UNAVAILABLE\"}}", "provider_error", "provider", true, None, Some("openhuman"), None, "The AI service is temporarily unavailable — we've been notified. Please try again shortly."),+ ("be_model_unavailable", "OpenHuman API error (503): {\"error\":{\"errorCode\":\"MODEL_UNAVAILABLE\"}}", "provider_error", "provider", true, None, Some("openhuman"), None, "The AI service is temporarily unavailable — we've been notified. Please try again shortly."),+ ("be_payload", "OpenHuman API error (413): {\"error\":{\"errorCode\":\"PAYLOAD_TOO_LARGE\"}}", "payload_too_large", "config", false, None, Some("openhuman"), None, "Your message or attachment is too large for this model. Shorten it or remove the attachment — or start a new thread."),+ ("be_context", "OpenHuman API error (400): {\"error\":{\"errorCode\":\"CONTEXT_LENGTH_EXCEEDED\"}}", "context_overflow", "config", false, None, Some("openhuman"), None, "The conversation is too long. Please start a new chat."),+ ("be_bad_request", "OpenHuman API error (400): {\"error\":{\"errorCode\":\"BAD_REQUEST\",\"message\":\"x\"}}", "provider_request_rejected", "provider", false, None, Some("openhuman"), None, "The request was rejected — usually a model or parameter mismatch. Try a different model in Connections → API keys → LLM."),+ ("be_bad_request_malformed", "OpenHuman API error (400): {\"error\":{\"errorCode\":\"BAD_REQUEST\",\"malformed\":true}}", "provider_request_rejected", "provider", false, None, Some("openhuman"), None, "Something went wrong with this message. Try rephrasing it — or start a new thread if it keeps happening."),+ ("be_bad_request_history", "OpenHuman API error (400): {\"error\":{\"errorCode\":\"BAD_REQUEST\",\"message\":\"messages with role 'tool' must be a response to a preceding message with 'tool_calls'\"}}", "provider_request_rejected", "provider", true, None, Some("openhuman"), None, "We hit a temporary glitch in this conversation — we've cleared it. Please send your message again."),+ ("be_internal", "OpenHuman API error (500): {\"error\":{\"errorCode\":\"INTERNAL_ERROR\"}}", "inference", "provider", true, None, Some("openhuman"), None, "Something went wrong — we've been notified. Please try again."),+];++#[test]+fn every_failure_class_keeps_its_exact_copy_and_wire_values() {+ assert_eq!(EXPECTED.len(), 36, "fixture row count drifted");+ for (case, input, error_type, source, retryable, retry_after_ms, provider, fallback, message) in+ EXPECTED+ {+ let got = classify_inference_error(input);+ assert_eq!(got.error_type, *error_type, "{case}: error_type");+ assert_eq!(got.source, *source, "{case}: source");+ assert_eq!(got.retryable, *retryable, "{case}: retryable");+ assert_eq!(got.retry_after_ms, *retry_after_ms, "{case}: retry_after_ms");+ assert_eq!(got.provider.as_deref(), *provider, "{case}: provider");+ assert_eq!(got.fallback_available, *fallback, "{case}: fallback_available");+ assert_eq!(got.message, *message, "{case}: message");+ }+}++#[test]+fn standalone_copy_accessors_are_unchanged() {+ assert_eq!(+ generic_inference_error_user_message(),+ "Something went wrong. Please try again."+ );+ assert_eq!(+ inference_budget_exceeded_user_message(),+ "You're out of credits, so I can't run the managed (cloud) model right now. You can top up your credits or pick a plan to continue \u{2014} or, if you've enabled a local model like Ollama, switch routing to \"Use Your Own Models\" in Connections \u{2192} API keys \u{2192} LLM."+ );+ assert_eq!(+ super::super::web_errors::turn_timeout_error_message(600),+ "openhuman_turn_wall_clock_timeout: agent turn exceeded its 600s wall-clock budget without producing a terminal event (a tool or delegated sub-agent likely stalled)"+ );+ assert_eq!(+ super::super::web_errors::retry_after_hint(Some(0)),+ " You can retry immediately."+ );+ assert_eq!(super::super::web_errors::retry_after_hint(Some(1)), " Try again in 1 second.");+ assert_eq!(super::super::web_errors::retry_after_hint(Some(45)), " Try again in 45 seconds.");+ assert_eq!(super::super::web_errors::retry_after_hint(Some(90)), " Try again in about 2 minutes.");+ assert_eq!(super::super::web_errors::retry_after_hint(Some(60 * 60)), " Try again in about 60 minutes.");+ assert_eq!(super::super::web_errors::retry_after_hint(None), "");+}++// ── Budget-phrase matchers: legacy oracles ──────────────────────────────────-pub(super) const CASES: &[(&str, &str)] = &[- ("codex_expired", "Codex authentication token is expired; sign in again"),- ("session_expired", "SESSION_EXPIRED"),- ("action_budget", "Action blocked: rate limit exceeded for tool curl"),- ("max_iterations", "Agent exceeded maximum tool iterations (10)"),- ("turn_timeout_marker", "openhuman_turn_wall_clock_timeout: agent turn exceeded its 600s wall-clock budget"),- ("turn_timeout_harness", "run timed out: tool call for run `x` exceeded its remaining wall-clock budget (5 ms)"),- ("empty_response", "The model returned an empty response. Please try again."),- ("chat_template", "openai API error (400): Jinja Exception: No user query found in messages."),- ("rate_limited_transient", "openrouter API error (429 Too Many Requests): Retry-After: 30"),- ("rate_limited_business", "openai API error (429): plan does not include this model; insufficient balance"),- ("timeout", "request timed out after 30s"),- ("auth_error", "openai API error (401 Unauthorized): invalid api key"),- ("budget_402", "openai API error (402 Payment Required)"),- ("budget_phrase", "Insufficient budget: please top up"),- ("budget_phrase_provider_source", "openrouter API error (400): out of credits"),- ("provider_5xx", "anthropic API error (503 Service Unavailable)"),- ("context_overflow", "context length exceeded"),- ("config_rejection", "openai API error (400): model `reasoning-v1` does not exist"),- ("model_unavailable", "model foo not found on this endpoint"),- ("model_transient", "the model is temporarily unavailable"),- ("vision", "provider_capability_error capability=vision does not support vision input"),- ("malformed_history_byo", "openai API error (400): messages with role 'tool' must be a response to a preceding message with 'tool_calls'"),- ("request_rejected_4xx", "someprovider API error (422 Unprocessable Entity): bad thing"),- ("network", "error sending request: connection reset by peer"),- ("transient_529", "anthropic API error (529): overloaded"),- ("generic", "kaboom"),- ("fallback_chain", "All providers/models failed. Attempts: x"),- ("be_rate_limited", r#"OpenHuman API error (429): {"error":{"errorCode":"RATE_LIMITED","retryAfter":30}}"#),- ("be_credits", r#"OpenHuman API error (402): {"error":{"errorCode":"USER_INSUFFICIENT_CREDITS"}}"#),- ("be_upstream", r#"OpenHuman API error (502): {"error":{"errorCode":"UPSTREAM_UNAVAILABLE"}}"#),- ("be_model_unavailable", r#"OpenHuman API error (503): {"error":{"errorCode":"MODEL_UNAVAILABLE"}}"#),- ("be_payload", r#"OpenHuman API error (413): {"error":{"errorCode":"PAYLOAD_TOO_LARGE"}}"#),- ("be_context", r#"OpenHuman API error (400): {"error":{"errorCode":"CONTEXT_LENGTH_EXCEEDED"}}"#),- ("be_bad_request", r#"OpenHuman API error (400): {"error":{"errorCode":"BAD_REQUEST","message":"x"}}"#),- ("be_bad_request_malformed", r#"OpenHuman API error (400): {"error":{"errorCode":"BAD_REQUEST","malformed":true}}"#),- ("be_bad_request_history", r#"OpenHuman API error (400): {"error":{"errorCode":"BAD_REQUEST","message":"messages with role 'tool' must be a response to a preceding message with 'tool_calls'"}}"#),- ("be_internal", r#"OpenHuman API error (500): {"error":{"errorCode":"INTERNAL_ERROR"}}"#),+/// Verbatim legacy `web_chat::web_errors::budget::is_inference_budget_exceeded_error`.+fn legacy_web_matcher(message: &str) -> bool {+ let normalize = Regex::new(r"[-_\s]+").unwrap();+ let normalized = normalize+ .replace_all(&message.trim().to_ascii_lowercase(), " ")+ .into_owned();+ let patterns = [+ r"budget.*exceed",+ r"top up",+ r"add.*credits",+ r"out of credits",+ r"no remaining credits",+ ];+ if patterns+ .iter()+ .any(|p| Regex::new(p).unwrap().is_match(&normalized))+ {+ return true;+ }+ legacy_billing_matcher(message)+}++/// Verbatim legacy `tinyinference_providers::is_budget_exhausted_message`+/// (also the loop-guard matcher).+fn legacy_billing_matcher(message: &str) -> bool {+ let lower = message.to_ascii_lowercase();+ [+ "insufficient budget",+ "budget exceeded",+ "add credits",+ "insufficient balance",+ "no remaining credits",+ "credit balance is too low",+ ]+ .iter()+ .any(|p| lower.contains(p))+}++/// Verbatim legacy triage `is_inference_budget_exceeded`.+fn legacy_triage_matcher(message: &str) -> bool {+ let normalized: String = message+ .trim()+ .to_ascii_lowercase()+ .chars()+ .map(|c| if c.is_ascii_alphanumeric() { c } else { ' ' })+ .collect();+ let words: Vec<&str> = normalized.split_whitespace().collect();+ const NEEDLES: &[&str] = &[+ "budget exceeded",+ "budget exceeds",+ "top up",+ "add credits",+ "out of credits",+ "no remaining credits",+ ];+ NEEDLES.iter().any(|needle| {+ let needle_tokens: Vec<&str> = needle.split_whitespace().collect();+ if needle_tokens.is_empty() || words.len() < needle_tokens.len() {+ return false;+ }+ words+ .windows(needle_tokens.len())+ .any(|window| window == needle_tokens.as_slice())+ })+}++const BUDGET_CORPUS: &[&str] = &[+ "",+ " ",+ "Insufficient budget",+ "INSUFFICIENT BALANCE",+ "Budget exceeded",+ "budget-exceeded",+ "budget_has_been exceeded for this period",+ "your budget limit exceeds quota",+ "exceeded the budget",+ "budget was exceeded",+ "Please TOP UP",+ "please top-up your wallet",+ "stop updating the thing",+ "stop updates",+ "add credits",+ "Add more credits to continue",+ "add_more_credits",+ "credits added",+ "You're out of credits",+ "out_of_credits",+ "out of\tcredits",+ "no remaining credits",+ "You have no remaining credits to use the LLM apis.",+ "You have 100 remaining credits this month",+ "Your credit balance is too low to access the API",+ "credit balance is $50.00",+ "{\"error\":\"budget exceeded\"}",+ "{\"error\":\"budget_exceeds\"}",+ "400 Bad Request: Insufficient budget",+ "BUDGET\nEXCEED",+ "budget\n\nexceeds",+ "add\ncredits",+ "ADD CREDITS",+ "unrelated failure with nothing financial",+ "budgets exceeded",+ "overbudget exceeding",+ "xtop upx",+ "top upgrade",+ "d\u{e9}j\u{e0} budget exceeded",];#[test]-fn dump_cases() {- let mut out = String::new();- for (name, input) in CASES {- let c = classify_inference_error(input);- out.push_str(&format!(- " ({name:?}, {input:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}),\n",- c.error_type, c.source, c.retryable, c.retry_after_ms, c.provider, c.fallback_available, c.message- ));+fn shared_budget_matcher_reproduces_each_legacy_matcher_on_the_corpus() {+ for message in BUDGET_CORPUS {+ assert_eq!(+ is_inference_budget_exceeded_error(message),+ legacy_web_matcher(message),+ "web_chat matcher drifted on {message:?}"+ );+ let triage_budget = matches!(+ classify_error((*message).to_string()),+ ArmError::BudgetExhausted(_)+ );+ assert_eq!(+ triage_budget,+ legacy_triage_matcher(message),+ "triage matcher drifted on {message:?}"+ );+ let delegated = format!("All providers/models failed: {message}");+ assert_eq!(+ crate::inference::failure_copy::terminal_inference_failure_kind(&delegated)+ == Some(crate::inference::failure_copy::TerminalInferenceFailure::BudgetExhausted),+ legacy_billing_matcher(message),+ "loop-guard matcher drifted on {message:?}"+ );+ assert_eq!(+ tinyinference_providers::is_budget_exhausted_message(message),+ legacy_billing_matcher(message),+ "billing matcher drifted on {message:?}"+ );}- std::fs::write(concat!(env!("CARGO_MANIFEST_DIR"), "/../../dump.txt"), out).unwrap();+}++// ── Loop-guard halt copy ────────────────────────────────────────────────────++#[test]+fn loop_guard_halt_summaries_are_byte_identical() {+ use crate::inference::failure_copy::{+ recoverable_identical_halt_summary, recoverable_no_progress_halt_summary,+ terminal_inference_halt_summary, user_actionable_escalation, TerminalInferenceFailure,+ };+ assert_eq!(+ terminal_inference_halt_summary(TerminalInferenceFailure::BudgetExhausted, "delegate", "boom"),+ "Stopping: the `delegate` step failed because the account is out of inference budget/credits \u{2014} every retry hits the same wall. Add credits to your account (or, when using a custom/BYO provider, top up that provider's own account) and try again. Details:\nboom"+ );+ assert_eq!(+ terminal_inference_halt_summary(TerminalInferenceFailure::ProviderConfig, "delegate", "boom"),+ "Stopping: the `delegate` step failed because the configured model/provider rejected the request (e.g. an unknown model, a non-chat/embedding model, a missing credential, or a region block) \u{2014} retrying will not help. Fix the model or API key in Connections \u{2192} API keys \u{2192} LLM. Details:\nboom"+ );+ assert_eq!(+ recoverable_identical_halt_summary("curl", 8, "boom"),+ "Stopping: the `curl` call was retried 8 times with identical arguments and kept failing \u{2014} repeating it will not help. Last error:\nboom\n\nThis looked recoverable at first, but the same call exhausted the extended transient-failure headroom. Report this back instead of retrying."+ );+ assert_eq!(+ recoverable_no_progress_halt_summary(12, "curl", "boom"),+ "Stopping: 12 recoverable-looking tool failures happened in a row with no successful progress. Last error (from `curl`):\nboom\n\nThe turn is still bounded by the iteration/cost limits, but this many consecutive transient failures means the goal is not currently reachable. Report this back instead of retrying."+ );+ assert_eq!(+ user_actionable_escalation("gmail", "Gmail is not connected").as_deref(),+ Some("I can't continue without your input: the `gmail` action needs a service that isn't connected. Gmail is not connected\n\nConnect it (Connections), then tell me to retry \u{2014} or tell me how you'd like to proceed instead.")+ );+ assert_eq!(user_actionable_escalation("gmail", "insufficient scope"), None);+ let long = "x".repeat(700);+ let summary = terminal_inference_halt_summary(TerminalInferenceFailure::BudgetExhausted, "t", &long);+ assert!(summary.ends_with(&format!("{}\n\u{2026} [truncated]", "x".repeat(600))));}