Skip to content

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

fix(web_chat): handle missing error classification for unknown error types

Steven Enamakel0e5827dab24a
diff --git a/crates/openhuman-core/src/web_chat/web_errors/classify.rs b/crates/openhuman-core/src/web_chat/web_errors/classify.rs
index 071090d130..917fbc312e 100644
--- a/crates/openhuman-core/src/web_chat/web_errors/classify.rs
+++ b/crates/openhuman-core/src/web_chat/web_errors/classify.rs
@@ -3,16 +3,16 @@
//! recovery UI from.
use super::backend_error_code::classify_by_backend_error_code;
-use super::budget::{
- generic_inference_error_user_message, inference_budget_exceeded_user_message,
- is_action_budget_exhausted, is_inference_budget_exceeded_error,
-};
-use super::response_predicates::malformed_history_user_message;
+use super::budget::{is_action_budget_exhausted, is_inference_budget_exceeded_error};
use super::retry::{is_non_retryable_rate_limit_text, retry_after_hint};
+use crate::inference::failure_copy::{failure_copy, FailureClass};
use tinyinference_llm::failure::{
- extract_provider_name, is_connection_dropped_text, is_empty_provider_response_text,
- is_fallback_chain_exhausted, is_malformed_tool_history_text, is_provider_request_rejected_text,
- is_transient_unavailability_text, parse_retry_after_secs, with_provider_detail,
+ extract_provider_name, is_auth_error_text, is_codex_token_expired_text,
+ is_connection_dropped_text, is_context_length_text, is_empty_provider_response_text,
+ is_fallback_chain_exhausted, is_malformed_tool_history_text, is_model_unavailable_text,
+ is_payment_required_text, is_provider_request_rejected_text, is_rate_limit_text,
+ is_server_error_text, is_timeout_text, is_transient_unavailability_text,
+ is_vision_unsupported_text, parse_retry_after_secs, with_provider_detail,
};
use super::timeout::is_turn_timeout_error;
@@ -69,7 +69,53 @@ pub(crate) struct ClassifiedError {
pub(crate) fallback_available: Option<bool>,
}
+/// Build the envelope for `class` from the copy table. `message` is the row's
+/// copy with whatever suffix the arm adds (provider detail, retry-after hint).
+pub(super) fn classified(
+ class: FailureClass,
+ message: String,
+ provider: Option<String>,
+ fallback_available: Option<bool>,
+) -> ClassifiedError {
+ let row = failure_copy(class);
+ ClassifiedError {
+ error_type: row.error_type,
+ message,
+ source: row.source,
+ retryable: row.retryable,
+ retry_after_ms: None,
+ provider,
+ fallback_available,
+ }
+}
+
+/// [`classified`] with the row's copy and the provider detail block appended.
+fn classified_with_detail(
+ class: FailureClass,
+ err: &str,
+ provider: Option<String>,
+ fallback_available: Option<bool>,
+) -> ClassifiedError {
+ let message = with_provider_detail(failure_copy(class).copy, err);
+ classified(class, message, provider, fallback_available)
+}
+
+/// [`classified`] with the row's copy verbatim.
+pub(super) fn classified_plain(
+ class: FailureClass,
+ provider: Option<String>,
+ fallback_available: Option<bool>,
+) -> ClassifiedError {
+ classified(
+ class,
+ failure_copy(class).copy.to_string(),
+ provider,
+ fallback_available,
+ )
+}
+
pub(crate) fn classify_inference_error(err: &str) -> ClassifiedError {
+ use FailureClass as C;
let lower = err.to_lowercase();
let provider = extract_provider_name(err);
let fallback_available = if is_fallback_chain_exhausted(err) {
@@ -97,493 +143,162 @@ pub(crate) fn classify_inference_error(err: &str) -> ClassifiedError {
return classified;
}
- // Order matters: the SecurityPolicy hourly cap and the
- // agent-loop max-iterations error both surface as strings that
- // contain "rate limit" / "iteration", so they MUST be checked
- // before the generic provider-429 branch — otherwise users see
- // a confusing "your AI provider is rate-limiting you" message
- // for limits OpenHuman itself enforced (issue #2364).
- // Codex-specific sentinel emitted by `openai_oauth::store` on refresh
- // failure. Checked before `is_session_expired_message` because the sentinel
- // contains "authentication token is expired", which would also match the
- // broader "session expired" substring test and route to the wrong sign-in
- // flow. We require "codex" in the message so generic provider errors that
- // happen to contain "token_expired" or "please try signing in again" are
- // not misclassified as Codex OAuth failures. (#5869)
- const CODEX_SENTINEL: &str = "codex authentication token is expired";
- let classified = if err.to_ascii_lowercase().contains(CODEX_SENTINEL) {
- // The Codex OAuth token has expired and the refresh failed. This is a
- // provider-specific re-auth — the user must reconnect Codex in
- // Settings → Integrations, NOT sign into OpenHuman.
- ClassifiedError {
- error_type: "provider_error",
- message: "Your Codex session has expired. Please reconnect it in \
- Settings → Integrations."
- .to_string(),
- source: "auth",
- retryable: false,
- retry_after_ms: None,
- provider: Some("openai_codex".to_string()),
- fallback_available: None,
- }
+ // Order matters: the SecurityPolicy hourly cap and the agent-loop
+ // max-iterations error both surface as strings that contain "rate limit" /
+ // "iteration", so they MUST be checked before the generic provider-429
+ // branch — otherwise users see a confusing "your AI provider is
+ // rate-limiting you" message for limits OpenHuman itself enforced (#2364).
+ let classified = if is_codex_token_expired_text(&err.to_ascii_lowercase()) {
+ // Codex OAuth refresh failed (#5869): the user must reconnect Codex in
+ // Settings → Integrations, NOT sign into OpenHuman. Checked before
+ // `is_session_expired_message` because the sentinel contains
+ // "authentication token is expired", which the broader "session
+ // expired" test would also match. Requires "codex" so a generic
+ // provider `token_expired` is not misread as a Codex failure.
+ classified_plain(C::CodexSessionExpired, Some("openai_codex".to_string()), None)
} else if crate::core::observability::is_session_expired_message(err) {
- // The OpenHuman app-session JWT expired (or the scheduler gate flagged
- // signed-out / `SESSION_EXPIRED` sentinel). There is NO client-side
- // refresh — recovery is an interactive re-auth only — so this is
- // non-retryable and must route the user to sign-in. Checked after the
- // Codex OAuth arm because "authentication token is expired" would also
- // match `is_session_expired_message`'s broad "session expired" substring.
- // The `auth_error` arm below can't claim the backend's `401 "Invalid token"`
- // envelope (it contains "401") and mislead managed-backend users with
- // "check your API key". `is_session_expired_message` is conjunctively
- // scoped to the OpenHuman/Embedding "Invalid token" envelopes + the
- // `SESSION_EXPIRED` / "no backend session" / "session jwt required"
- // sentinels, so a BYO provider's own 401 still falls through to
- // `auth_error`.
- ClassifiedError {
- error_type: "session_expired",
- message: "Your OpenHuman session has expired. \
- Please sign in again to continue."
- .to_string(),
- source: "auth",
- retryable: false,
- retry_after_ms: None,
- // OpenHuman's own session — provider name (if any leaked into the
- // surrounding chain) is irrelevant to a sign-in prompt.
- provider: None,
- fallback_available: None,
- }
+ // The OpenHuman app-session JWT expired. There is NO client-side
+ // refresh — recovery is an interactive re-auth — so non-retryable, and
+ // it must route to sign-in. Checked after the Codex arm; the
+ // `auth_error` arm below can't claim the backend's `401 "Invalid
+ // token"` envelope (it contains "401") and mislead managed-backend
+ // users with "check your API key". A BYO provider's own 401 still
+ // falls through to `auth_error`. Provider name is irrelevant to a
+ // sign-in prompt.
+ classified_plain(C::SessionExpired, None, None)
} else if is_action_budget_exhausted(&lower) {
- ClassifiedError {
- error_type: "action_budget_exceeded",
- message: with_provider_detail(
- "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.",
- err,
- ),
- source: "openhuman_budget",
- // The window decays gradually so the same thread CAN recover
- // — we just can't predict the exact wait.
- retryable: true,
- retry_after_ms: None,
- // OpenHuman's own cap — provider name (if any was in the
- // surrounding error chain) is irrelevant; the limit isn't
- // from a provider.
- provider: None,
- fallback_available: None,
- }
+ // OpenHuman's own cap (#2364): the window decays gradually so the same
+ // thread CAN recover, but the exact wait is unpredictable. The limit is
+ // not from a provider, so any provider name in the chain is dropped.
+ classified_with_detail(C::ActionBudget, err, None, None)
} else if crate::agent::error::is_max_iterations_error(err) {
- ClassifiedError {
- error_type: "max_iterations",
- message: with_provider_detail(
- "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.",
- err,
- ),
- source: "agent_loop",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available: None,
- }
+ classified_with_detail(C::MaxIterations, err, provider, None)
} else if is_turn_timeout_error(err) {
- // The web turn driver's wall-clock backstop fired: the turn ran past its
- // time budget without ever producing a terminal event — a wedged main
- // agent (stuck mid tool-call) or a delegated sub-agent that never
- // returned. Surface a graceful, retryable chat_error so the client stops
- // "processing" instead of receiving an empty reply / spinning on
- // `inference_heartbeat` until the socket dies (issue #4746). Anchored
- // next to max_iterations — both are deterministic agent-loop outcomes
- // that must not be shadowed by the broad provider-429 / 5xx arms below.
- // No `with_provider_detail`: the marker string carries no provider body.
- ClassifiedError {
- error_type: "turn_timeout",
- message: "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."
- .to_string(),
- source: "agent_loop",
- retryable: true,
- retry_after_ms: None,
- provider: None,
- fallback_available: None,
- }
+ // The web turn driver's wall-clock backstop fired (#4746): a wedged main
+ // agent or a delegated sub-agent that never returned. Anchored next to
+ // max_iterations — both are deterministic agent-loop outcomes that must
+ // not be shadowed by the broad provider-429 / 5xx arms below. No
+ // provider detail: the marker string carries no provider body.
+ classified_plain(C::TurnTimeout, None, None)
} else if is_empty_provider_response_text(&lower) {
- // The agent harness bailed because the provider/model completed a
- // turn with a completely empty body (text_chars=0 thinking_chars=0
- // tool_calls=0) — `AgentError::EmptyProviderResponse`, flattened to
- // a `String` at the native-bus boundary. Without this arm the
- // message falls through to the generic catch-all and the user sees a
- // bare "Something went wrong" with no remedy (Sentry TAURI-RUST-4JW,
- // the single largest source of the #3092 / #3119 chat-error
- // cluster). Placed early next to max_iterations: both are
- // deterministic agent-state outcomes with a specific anchor, so
- // neither can be shadowed by the broad provider-429 / 5xx arms below.
- // No `with_provider_detail` — an empty response carries no JSON body
- // to quote.
- //
- // An empty successful completion is not a billing verdict. In
- // particular, reasoning-only replies can spend output tokens but
- // produce no visible answer. Reserve credit guidance for explicit
- // backend/provider errors; this path has neither an error code nor
- // a response body establishing the user's balance.
- ClassifiedError {
- error_type: "empty_response",
- message: "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."
- .to_string(),
- source: "agent_loop",
- retryable: true,
- retry_after_ms: None,
- provider: None,
- fallback_available: None,
- }
+ // `AgentError::EmptyProviderResponse`, flattened at the native-bus
+ // boundary (Sentry TAURI-RUST-4JW, the largest source of the
+ // #3092 / #3119 cluster). An empty successful completion is not a
+ // billing verdict — reasoning-only replies can spend output tokens and
+ // show nothing — so no credit guidance and no provider detail.
+ classified_plain(C::EmptyResponse, None, None)
} else if tinyinference_llm::providers::openai::is_chat_template_rejection_message(err) {
- // #5291: a local runtime (LM Studio / llama.cpp / Ollama) rendered the
- // request through the model's OWN Jinja chat template and the template
- // raised — `No user query found in messages.` on Qwen 3, against the
- // prompt-guided tool loop's message shape. Neither the model nor the
- // sampling params are at fault, and the request never reached the model.
- //
- // Placed HERE, with the other specific-anchor arms and above the broad
- // substring ladder, because both renderings of this failure are claimed
- // by an earlier-or-lower arm that misdiagnoses them:
- // - the retry aggregate that wraps the failed attempts ends with
- // "…change your default model in Connections → API keys → LLM",
- // and the `auth_error` arm below matches on the bare substring
- // "api key" — the user gets "check your API key" for a template
- // failure;
- // - that same aggregate carries "may not be available on your
- // provider", which the config-rejection arm renders as "your
- // provider rejected the model or temperature setting" (#5291's
- // reported symptom).
- // Both point at a credential/model/temperature that was never the
- // problem, so every remediation they offer is a dead end. The anchors
- // in `is_chat_template_rejection_message` are template-engine strings
- // ("jinja exception", the raised guard text), which no unrelated
- // provider error emits — so claiming the error this early is safe.
- //
- // Retryable: the failure needs a tool-step history with no resolvable
- // user turn, and a fresh turn starts from the user's new message, so
- // the same model can succeed on the next attempt. The harness-side fix
- // (guaranteeing a user turn for non-native-tool models) removes the
- // shape that triggers it at all.
- ClassifiedError {
- error_type: "chat_template_rejected",
- message: with_provider_detail(
- "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.",
- err,
- ),
- source: "provider",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
- } else if lower.contains("rate limit") || lower.contains("429") {
+ // #5291: a local runtime rendered the request through the model's OWN
+ // Jinja chat template and the template raised. Placed above the broad
+ // substring ladder because both renderings of this failure are claimed
+ // by arms that misdiagnose them ("check your API key", "provider
+ // rejected the model or temperature"), pointing at things that were
+ // never the problem. The anchors are template-engine strings no
+ // unrelated provider error emits. Retryable: a fresh turn starts from
+ // the user's new message.
+ classified_with_detail(C::ChatTemplateRejected, err, provider, fallback_available)
+ } else if is_rate_limit_text(&lower) {
let retry_secs = parse_retry_after_secs(err);
// Non-retryable business 429s ("plan does not include", balance
- // exhausted, known provider business codes like Z.AI 1311/1113)
- // also surface here — mark them non-retryable so the FE can hide
- // the "Retry" button and route the user to settings/billing.
+ // exhausted, Z.AI 1311/1113) also surface here — mark them
+ // non-retryable so the FE can hide "Retry" and route to billing.
let non_retryable = is_non_retryable_rate_limit_text(&lower);
- let summary = if non_retryable {
- "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."
- .to_string()
+ let (class, summary) = if non_retryable {
+ (C::RateLimitedBilling, failure_copy(C::RateLimitedBilling).copy.to_string())
} else {
- format!(
- "Your AI provider is rate-limiting requests. This is a transient upstream \
- limit, not a thread-level block — you can retry in this thread.{}",
- retry_after_hint(retry_secs)
+ (
+ C::RateLimited,
+ format!(
+ "{}{}",
+ failure_copy(C::RateLimited).copy,
+ retry_after_hint(retry_secs)
+ ),
)
};
ClassifiedError {
- error_type: "rate_limited",
- message: with_provider_detail(summary.as_str(), err),
- source: "provider",
- retryable: !non_retryable,
retry_after_ms: retry_secs.map(|s| s.saturating_mul(1000)),
- provider,
- fallback_available,
- }
- } else if lower.contains("timeout") || lower.contains("timed out") {
- ClassifiedError {
- error_type: "timeout",
- message: with_provider_detail(
- "The request timed out. Please check your connection and try again.",
- err,
- ),
- source: "transport",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
- } else if lower.contains("401") || lower.contains("unauthorized") || lower.contains("api key") {
- ClassifiedError {
- error_type: "auth_error",
- message: with_provider_detail(
- "There's an authentication issue with the AI provider. Please check your API key in settings.",
- err,
- ),
- source: "config",
- retryable: false,
- retry_after_ms: None,
- provider,
- fallback_available: None,
+ ..classified(
+ class,
+ with_provider_detail(summary.as_str(), err),
+ provider,
+ fallback_available,
+ )
}
- } else if lower.contains("402")
- || lower.contains("payment required")
- || lower.contains("insufficient balance")
- // Issue #3088: the OpenHuman managed backend reports no-credits as a
- // 400 with "Insufficient budget" (not a 402), which previously fell
- // through to the generic "Something went wrong" branch. Catch the
- // canonical budget phrases here so the user gets the actionable
- // top-up / switch-to-your-own-model guidance instead.
+ } else if is_timeout_text(&lower) {
+ classified_with_detail(C::Timeout, err, provider, fallback_available)
+ } else if is_auth_error_text(&lower) {
+ classified_with_detail(C::AuthError, err, provider, None)
+ } else if is_payment_required_text(&lower)
+ // Issue #3088: the managed backend reports no-credits as a 400 with
+ // "Insufficient budget" (not a 402), which previously fell through to
+ // the generic apology. Catch the canonical budget phrases here.
|| is_inference_budget_exceeded_error(err)
{
- // `openhuman_billing` means OpenHuman's own credit/quota system —
- // a 402 carrying the "openhuman" envelope (or no envelope at all,
- // since OpenHuman's backend is the only origin without one in
- // practice). When the 402 comes from an upstream provider envelope
- // (`<provider> API error (402)`), the limit belongs to that
- // provider, not OpenHuman billing, so tag the source as `provider`.
+ // `openhuman_billing` means OpenHuman's own credit system — a 402 with
+ // the "openhuman" envelope (or none). When it comes from an upstream
+ // provider envelope the limit belongs to that provider.
let source: &'static str = match provider.as_deref() {
- Some("openhuman") | None => "openhuman_billing",
+ Some("openhuman") | None => failure_copy(C::BudgetExhausted).source,
Some(_) => "provider",
};
ClassifiedError {
- error_type: "budget_exhausted",
- message: with_provider_detail(inference_budget_exceeded_user_message(), err),
source,
- retryable: false,
- retry_after_ms: None,
- provider,
- fallback_available: None,
- }
- } else if lower.contains("500")
- || lower.contains("internal server")
- || lower.contains("service unavailable")
- || lower.contains("503")
- {
- ClassifiedError {
- error_type: "provider_error",
- message: with_provider_detail(
- "The AI provider is temporarily unavailable. Please try again later.",
- err,
- ),
- source: "provider",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
- } else if lower.contains("context")
- && (lower.contains("length")
- || lower.contains("limit")
- || lower.contains("exceed")
- || lower.contains("token"))
- {
- ClassifiedError {
- error_type: "context_overflow",
- message: with_provider_detail(
- "The conversation is too long. Please start a new chat.",
- err,
- ),
- source: "config",
- retryable: false,
- retry_after_ms: None,
- provider,
- fallback_available: None,
+ ..classified_with_detail(C::BudgetExhausted, err, provider, None)
}
+ } else if is_server_error_text(&lower) {
+ classified_with_detail(C::ProviderUnavailable, err, provider, fallback_available)
+ } else if is_context_length_text(&lower) {
+ classified_with_detail(C::ContextOverflow, err, provider, None)
} else if tinyinference_providers::is_provider_config_rejection_message(err) {
- // #2079 / #2076 / #2202: an OpenHuman abstract tier alias leaked to
- // a custom provider, a stale model pin, or a model-specific
- // temperature constraint. Checked BEFORE the generic
- // model-unavailable arm so config-rejection bodies that also
- // contain "model"/"does not exist"/"does not have access" get the
- // specific "Settings → LLM" remediation instead of the generic
- // copy. Shared predicate keeps this in lockstep with the
- // Sentry-demotion classifier.
- ClassifiedError {
- error_type: "model_unavailable",
- message: with_provider_detail(
- "Your AI provider rejected the request's model or temperature setting. \
- Check your model and routing in Settings → LLM.",
- err,
- ),
- source: "config",
- retryable: false,
- retry_after_ms: None,
- provider,
- fallback_available: None,
- }
- } else if lower.contains("model")
- && (lower.contains("not found")
- || lower.contains("unavailable")
- || lower.contains("does not exist")
- || lower.contains("does not have access"))
- {
- // #5503: this arm previously flattened two distinct failures into one
- // non-retryable "check your model settings" misconfiguration verdict.
- // A TRANSIENT upstream outage ("the model is temporarily unavailable",
- // "currently overloaded") is NOT a user misconfiguration — labelling it
- // `config`/non-retryable tells the user to go fix settings that are
- // fine, and hides the Retry button on a failure a retry would clear. So
- // split on transience: a body carrying a temporary-outage marker routes
- // to the retryable "temporarily unavailable" provider copy (the same
- // class as the `500`/`503` arm above), while a genuine model rejection
- // ("does not exist", "does not have access", "model unavailable on this
- // endpoint" — a stale pin / wrong endpoint) keeps the non-retryable
- // config copy. Genuine config-rejection bodies (`does not exist`,
- // `model_not_found`, `/openai/v1/models`, …) are already claimed by the
- // provider-config-rejection arm above and never reach here.
+ // #2079 / #2076 / #2202: an abstract tier alias leaked to a custom
+ // provider, a stale model pin, or a model-specific temperature
+ // constraint. Checked BEFORE the generic model-unavailable arm so
+ // config-rejection bodies that also contain "model" / "does not exist"
+ // get the specific Settings remediation.
+ classified_with_detail(C::ModelConfigRejected, err, provider, None)
+ } else if is_model_unavailable_text(&lower) {
+ // #5503: split on transience. A temporary outage ("currently
+ // overloaded") is not a user misconfiguration — it routes to the
+ // retryable provider copy; a genuine model rejection ("does not exist",
+ // a stale pin) keeps the non-retryable config copy. Config-rejection
+ // bodies are claimed by the arm above and never reach here.
if is_transient_unavailability_text(&lower) {
- ClassifiedError {
- error_type: "provider_error",
- message: with_provider_detail(
- "The AI provider is temporarily unavailable. Please try again later.",
- err,
- ),
- source: "provider",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
+ classified_with_detail(C::ProviderUnavailable, err, provider, fallback_available)
} else {
- ClassifiedError {
- error_type: "model_unavailable",
- message: with_provider_detail(
- "The selected model isn't available on your provider. Check your model settings.",
- err,
- ),
- source: "config",
- retryable: false,
- retry_after_ms: None,
- provider,
- fallback_available: None,
- }
- }
- } else if lower.contains("does not support vision") || lower.contains("capability=vision") {
- // A multimodal turn sent image markers to a text-only model
- // (`provider_capability_error … capability=vision … does not support
- // vision input`, raised by the tinyagents model adapter). Without
- // this arm it dead-ends on the generic catch-all. Retrying the same
- // image against the same model can't help — the user must drop the
- // attachment or pick a vision-capable model, so this is non-retryable.
- ClassifiedError {
- error_type: "capability_unsupported",
- message: "This model can't process images. Remove the attachment or switch to a \
- vision-capable model in Connections → API keys → LLM."
- .to_string(),
- source: "config",
- retryable: false,
- retry_after_ms: None,
- provider: None,
- fallback_available: None,
+ classified_with_detail(C::ModelUnavailable, err, provider, None)
}
+ } else if is_vision_unsupported_text(&lower) {
+ // A multimodal turn sent image markers to a text-only model. Retrying
+ // the same image against the same model can't help.
+ classified_plain(C::CapabilityUnsupported, None, None)
} else if is_provider_request_rejected_text(&lower) && is_malformed_tool_history_text(&lower) {
- // Same poisoned-history rejection as the managed `BAD_REQUEST` branch,
- // but on a BYO/direct provider (e.g. OpenAI "messages with role 'tool'
- // must be a response to a preceding message with 'tool_calls'"). The
- // de-poison guard already evicted the warm session, so resending works.
- // Checked BEFORE the generic 4xx arm so the actionable copy wins.
- ClassifiedError {
- error_type: "provider_request_rejected",
- message: malformed_history_user_message().to_string(),
- source: "provider",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
+ // Poisoned-history rejection on a BYO/direct provider. The de-poison
+ // guard already evicted the warm session, so resending works. Checked
+ // BEFORE the generic 4xx arm so the actionable copy wins.
+ classified_plain(C::MalformedHistory, provider, fallback_available)
} else if is_provider_request_rejected_text(&lower) {
- // A provider rejected the request with a 4xx that none of the
- // specific arms above claimed (generic 400 Bad Request, 404, 422).
- // The DeepSeek thinking-mode `reasoning_content` round-trip 400
- // (deeper fix tracked separately in #3197) and other model/parameter
- // incompatibilities land here. MUST stay below the
- // provider-config-rejection (invalid temperature, stale model pin)
- // and model-unavailable arms so their more specific 4xx verdicts win
- // first. 4xx is a client/request problem — identical retry fails, so
- // non-retryable. The real provider reason is already secret-scrubbed
- // and length-capped by `with_provider_detail` and quoted to the user.
- ClassifiedError {
- error_type: "provider_request_rejected",
- message: with_provider_detail(
- "The AI provider rejected the request — this is usually a model or \
- parameter incompatibility. Try a different model in Connections → API keys → LLM.",
- err,
- ),
- source: "provider",
- retryable: false,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
+ // A 4xx none of the specific arms above claimed (generic 400, 404,
+ // 422; the DeepSeek `reasoning_content` round-trip 400, #3197). MUST
+ // stay below provider-config-rejection and model-unavailable so their
+ // more specific verdicts win. Identical retry fails, so non-retryable;
+ // the real reason is secret-scrubbed and quoted by
+ // `with_provider_detail`.
+ classified_with_detail(C::RequestRejected, err, provider, fallback_available)
} else if is_connection_dropped_text(&lower) {
// A transport-level drop with no provider status and no managed
- // `errorCode`: a stale keep-alive socket reused after sleep/wake, a
- // network change, or a RAW mid-stream SSE drop — the managed backend
- // intentionally omits `errorCode` for raw upstream/network drops
- // (backend `routes/inference.ts`), so those reach here as
- // `"OpenHuman streaming API error: <body>"` with nothing to branch on.
- // These previously fell to the generic catch-all ("Something went
- // wrong"). The turn's history is NOT poisoned — the agent loop bails
- // before committing the failed iteration (`engine/core.rs`) — so this is
- // cleanly retryable and the warm session is kept. Placed LAST so every
- // specific provider-status / 4xx arm claims its shape first; only an
- // otherwise-unclassified transport error lands here.
- ClassifiedError {
- error_type: "network",
- message: with_provider_detail(
- "The connection to the AI service dropped mid-response — usually a \
- sleep/wake or network change. Please try again.",
- err,
- ),
- source: "transport",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
+ // `errorCode` (stale keep-alive after sleep/wake, a raw mid-stream SSE
+ // drop). The turn's history is NOT poisoned, so it is cleanly
+ // retryable. Placed LAST so every specific status / 4xx arm claims its
+ // shape first.
+ classified_with_detail(C::Network, err, provider, fallback_available)
} else if is_transient_unavailability_text(&lower) {
- // A transient upstream-outage marker that no more specific arm above
- // claimed (e.g. a bare 5xx "overloaded" such as Anthropic's 529, or
- // "please retry later") is a temporary provider outage — surface the
- // retryable "temporarily unavailable" provider copy rather than the flat
- // inference bucket, so the user gets an accurate, retryable error (#5503).
- ClassifiedError {
- error_type: "provider_error",
- message: "The AI provider is temporarily unavailable. Please try again later."
- .to_string(),
- source: "provider",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
+ // A transient outage marker no more specific arm claimed (a bare 5xx
+ // "overloaded" such as Anthropic's 529, "please retry later") — the
+ // retryable "temporarily unavailable" copy rather than the flat
+ // inference bucket (#5503).
+ classified_plain(C::ProviderUnavailable, provider, fallback_available)
} else {
- ClassifiedError {
- error_type: "inference",
- message: with_provider_detail(generic_inference_error_user_message(), err),
- source: "provider",
- retryable: true,
- retry_after_ms: None,
- provider,
- fallback_available,
- }
+ classified_with_detail(C::Inference, err, provider, fallback_available)
};
// Verbose diagnostics on the classification flow (per CLAUDE.md). Stable