Skip to content

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

fix(inference): handle empty failure table in copy operation

Steven Enamakel630d93bc7370
diff --git a/crates/openhuman-core/src/inference/failure_copy/table.rs b/crates/openhuman-core/src/inference/failure_copy/table.rs
new file mode 100644
index 0000000000..19e34dd521
--- /dev/null
+++ b/crates/openhuman-core/src/inference/failure_copy/table.rs
@@ -0,0 +1,278 @@
+//! The one table mapping a chat-failure class to the `error_type` wire token,
+//! the `source` tag, the retry verdict and the user-facing copy.
+//!
+//! Matching a raw error string to a class is the ladder in
+//! `web_chat::web_errors::classify`; the strings and wire values live only
+//! here. A literal fixture (`web_chat/web_tests_error_copy_fixture_tests.rs`)
+//! pins every row.
+
+/// One row: what the frontend branches on (`error_type`, `source`,
+/// `retryable`) and what the user reads (`copy`).
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) struct FailureCopy {
+ /// Stable `error_type` wire token of the `chat_error` event.
+ pub(crate) error_type: &'static str,
+ /// Where the limit originated (`provider`, `openhuman_budget`,
+ /// `agent_loop`, `openhuman_billing`, `transport`, `config`, `auth`).
+ pub(crate) source: &'static str,
+ /// Whether the same prompt can be retried in the same thread.
+ pub(crate) retryable: bool,
+ /// User copy. A few classes take a suffix at the call site (retry-after
+ /// hint, provider detail block); the base text is always this string.
+ pub(crate) copy: &'static str,
+}
+
+/// A failure class the chat surface renders copy for. Several classifier arms
+/// share a class (the "temporarily unavailable" copy is reached from four).
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum FailureClass {
+ CodexSessionExpired,
+ SessionExpired,
+ ActionBudget,
+ MaxIterations,
+ TurnTimeout,
+ EmptyResponse,
+ ChatTemplateRejected,
+ RateLimited,
+ RateLimitedBilling,
+ ManagedRateLimited,
+ Timeout,
+ AuthError,
+ BudgetExhausted,
+ ManagedBudgetExhausted,
+ ProviderUnavailable,
+ ManagedUnavailable,
+ PayloadTooLarge,
+ ContextOverflow,
+ ModelConfigRejected,
+ ModelUnavailable,
+ CapabilityUnsupported,
+ MalformedHistory,
+ RequestRejected,
+ ManagedRequestRejected,
+ ManagedMalformedRequest,
+ Network,
+ Inference,
+ ManagedInternal,
+}
+
+/// The row for `class`.
+pub(crate) fn failure_copy(class: FailureClass) -> &'static FailureCopy {
+ use FailureClass::*;
+ macro_rules! row {
+ ($ty:expr, $src:expr, $retry:expr, $copy:expr) => {{
+ static ROW: FailureCopy = FailureCopy {
+ error_type: $ty,
+ source: $src,
+ retryable: $retry,
+ copy: $copy,
+ };
+ &ROW
+ }};
+ }
+ match class {
+ CodexSessionExpired => row!(
+ "provider_error",
+ "auth",
+ false,
+ "Your Codex session has expired. Please reconnect it in \
+ Settings → Integrations."
+ ),
+ SessionExpired => row!(
+ "session_expired",
+ "auth",
+ false,
+ "Your OpenHuman session has expired. \
+ Please sign in again to continue."
+ ),
+ ActionBudget => row!(
+ "action_budget_exceeded",
+ "openhuman_budget",
+ true,
+ "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."
+ ),
+ MaxIterations => row!(
+ "max_iterations",
+ "agent_loop",
+ true,
+ "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."
+ ),
+ TurnTimeout => row!(
+ "turn_timeout",
+ "agent_loop",
+ true,
+ "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."
+ ),
+ EmptyResponse => row!(
+ "empty_response",
+ "agent_loop",
+ true,
+ "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."
+ ),
+ ChatTemplateRejected => row!(
+ "chat_template_rejected",
+ "provider",
+ true,
+ "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."
+ ),
+ RateLimited => row!(
+ "rate_limited",
+ "provider",
+ true,
+ "Your AI provider is rate-limiting requests. This is a transient upstream \
+ limit, not a thread-level block — you can retry in this thread."
+ ),
+ RateLimitedBilling => row!(
+ "rate_limited",
+ "provider",
+ false,
+ "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."
+ ),
+ ManagedRateLimited => row!(
+ "rate_limited",
+ "provider",
+ true,
+ "Your AI provider is rate-limiting requests. You can retry in this thread."
+ ),
+ Timeout => row!(
+ "timeout",
+ "transport",
+ true,
+ "The request timed out. Please check your connection and try again."
+ ),
+ AuthError => row!(
+ "auth_error",
+ "config",
+ false,
+ "There's an authentication issue with the AI provider. Please check your API key in settings."
+ ),
+ // Source is `provider` instead when the 402 carries a non-OpenHuman
+ // provider envelope; the classifier applies that override.
+ BudgetExhausted => row!(
+ "budget_exhausted",
+ "openhuman_billing",
+ false,
+ "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."
+ ),
+ ManagedBudgetExhausted => row!(
+ "budget_exhausted",
+ "openhuman_billing",
+ false,
+ "You're out of credits. Top up, or switch to 'Use Your Own Models' \
+ in Settings."
+ ),
+ ProviderUnavailable => row!(
+ "provider_error",
+ "provider",
+ true,
+ "The AI provider is temporarily unavailable. Please try again later."
+ ),
+ ManagedUnavailable => row!(
+ "provider_error",
+ "provider",
+ true,
+ "The AI service is temporarily unavailable — we've been notified. \
+ Please try again shortly."
+ ),
+ PayloadTooLarge => row!(
+ "payload_too_large",
+ "config",
+ false,
+ "Your message or attachment is too large for this model. Shorten it \
+ or remove the attachment — or start a new thread."
+ ),
+ ContextOverflow => row!(
+ "context_overflow",
+ "config",
+ false,
+ "The conversation is too long. Please start a new chat."
+ ),
+ ModelConfigRejected => row!(
+ "model_unavailable",
+ "config",
+ false,
+ "Your AI provider rejected the request's model or temperature setting. \
+ Check your model and routing in Settings → LLM."
+ ),
+ ModelUnavailable => row!(
+ "model_unavailable",
+ "config",
+ false,
+ "The selected model isn't available on your provider. Check your model settings."
+ ),
+ CapabilityUnsupported => row!(
+ "capability_unsupported",
+ "config",
+ false,
+ "This model can't process images. Remove the attachment or switch to a \
+ vision-capable model in Connections → API keys → LLM."
+ ),
+ // The de-poison guard (`run_task.rs`) has already evicted the
+ // offending warm session by the time this is shown, so "send it
+ // again" is literally true.
+ MalformedHistory => row!(
+ "provider_request_rejected",
+ "provider",
+ true,
+ "We hit a temporary glitch in this conversation — we've cleared it. \
+ Please send your message again."
+ ),
+ RequestRejected => row!(
+ "provider_request_rejected",
+ "provider",
+ false,
+ "The AI provider rejected the request — this is usually a model or \
+ parameter incompatibility. Try a different model in Connections → API keys → LLM."
+ ),
+ ManagedRequestRejected => row!(
+ "provider_request_rejected",
+ "provider",
+ false,
+ "The request was rejected — usually a model or parameter \
+ mismatch. Try a different model in Connections → API keys → LLM."
+ ),
+ ManagedMalformedRequest => row!(
+ "provider_request_rejected",
+ "provider",
+ false,
+ "Something went wrong with this message. Try rephrasing it — \
+ or start a new thread if it keeps happening."
+ ),
+ Network => row!(
+ "network",
+ "transport",
+ true,
+ "The connection to the AI service dropped mid-response — usually a \
+ sleep/wake or network change. Please try again."
+ ),
+ Inference => row!(
+ "inference",
+ "provider",
+ true,
+ "Something went wrong. Please try again."
+ ),
+ ManagedInternal => row!(
+ "inference",
+ "provider",
+ true,
+ "Something went wrong — we've been notified. Please try again."
+ ),
+ }
+}
diff --git a/dump.txt b/dump.txt
deleted file mode 100644
index 677c47c507..0000000000
--- a/dump.txt
+++ /dev/null
@@ -1,37 +0,0 @@
- ("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."),