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
refactor(observability, web_chat): update error classification logic
Steven Enamakel9d7d4a93b0d9
diff --git a/crates/openhuman-core/src/core/observability.rs b/crates/openhuman-core/src/core/observability.rsindex 1b56e8b494..573d298d8f 100644--- a/crates/openhuman-core/src/core/observability.rs+++ b/crates/openhuman-core/src/core/observability.rs@@ -379,7 +379,11 @@ pub fn expected_error_kind(message: &str) -> Option<ExpectedErrorKind> {// decision is gated on the managed-backend envelope so a BYO payload// carrying an `errorCode`-shaped field is not wrongly suppressed// (CodeRabbit).- if crate::inference::provider::managed_error_skips_sentry(message) {+ let backend_error = crate::inference::registry::classify_backend_error(None, message);+ if backend_error+ .as_ref()+ .is_some_and(|classification| classification.backend_owned && !classification.reportable)+ {return Some(ExpectedErrorKind::BackendErrorCodeOwned);}// A managed-backend client-guard-leak code (`PAYLOAD_TOO_LARGE` /@@ -392,9 +396,17 @@ pub fn expected_error_kind(message: &str) -> Option<ExpectedErrorKind> {// `ContextWindowExceeded` bucket (CodeRabbit). Gated on the managed envelope// so a BYO provider's own context-overflow — genuine user-state, not our// guard — still flows to that matcher and stays demoted.- if crate::inference::provider::is_managed_backend_envelope(message)- && crate::inference::provider::is_backend_client_guard_leak(message)- {+ if backend_error.as_ref().is_some_and(|classification| {+ classification.provider_owned+ && classification.reportable+ && matches!(+ classification.kind,+ Some(+ crate::inference::registry::BackendErrorKind::PayloadTooLarge+ | crate::inference::registry::BackendErrorKind::ContextLengthExceeded+ )+ )+ }) {return None;}// Check the Codex-CLI import envelope first: it is highly specific@@ -2306,7 +2318,9 @@ fn report_expected_message(kind: ExpectedErrorKind, message: &str, domain: &str,// The FE surfaces actionable copy via `classify_inference_error`;// Sentry must not double-report (F2/F4). Demote at `warn!` so the// breadcrumb retains the code for triage without spawning an event.- let code = crate::inference::provider::extract_backend_error_code_token(message)+ let code = backend_error+ .as_ref()+ .and_then(|classification| classification.token.as_deref()).unwrap_or_default();tracing::warn!(domain = domain,@@ -2595,7 +2609,13 @@ pub fn is_backend_error_code_event(event: &sentry::protocol::Event<'_>) -> bool[direct, from_logentry, from_exception].into_iter().flatten()- .any(crate::inference::provider::managed_error_skips_sentry)+ .any(|message| {+ crate::inference::registry::classify_backend_error(None, message).is_some_and(+ |classification| {+ classification.backend_owned && !classification.reportable+ },+ )+ })}/// Defense-in-depth `before_send` filter for transient streaming **transport**diff --git a/crates/openhuman-core/src/web_chat/web_errors/backend_error_code.rs b/crates/openhuman-core/src/web_chat/web_errors/backend_error_code.rsindex 2503cc3753..b57211e5dc 100644--- a/crates/openhuman-core/src/web_chat/web_errors/backend_error_code.rs+++ b/crates/openhuman-core/src/web_chat/web_errors/backend_error_code.rs@@ -24,35 +24,32 @@ pub(super) fn classify_by_backend_error_code(provider: Option<String>,fallback_available: Option<bool>,) -> Option<ClassifiedError> {- use crate::inference::provider::{- body_flags_malformed, extract_backend_error_code, is_managed_backend_envelope,- BackendErrorCode,- };+ use crate::inference::registry::{classify_backend_error, BackendErrorKind};// Managed-vs-BYO gate: an `errorCode` is only trustworthy on a// managed-backend envelope. A BYO / direct-provider body that merely// contains an `errorCode`-shaped field must fall through to the substring// ladder (CodeRabbit), keeping its user-actionable copy intact.- if !is_managed_backend_envelope(err) {+ let classification = classify_backend_error(None, err)?;+ if !classification.provider_owned {return None;}-- let code = extract_backend_error_code(err)?;+ let kind = classification.kind?;// Verbose diagnostics on the new managed-code branch (per CLAUDE.md).// Low-cardinality only — the raw `err` may carry a provider payload / PII// and is logged at the caller, not here.log::debug!("[chat-error][classify][errorCode] code={:?} provider={:?}",- code,+ kind,provider,);use super::classify::{classified, classified_plain, copy_params};use crate::inference::failure_copy::{failure_copy, FailureClass as C};- let classified = match code {- BackendErrorCode::RateLimited => {+ let classified = match kind {+ BackendErrorKind::RateLimited => {let retry_secs = parse_retry_after_secs(err);ClassifiedError {retry_after_ms: retry_secs.map(|s| s.saturating_mul(1000)),@@ -69,7 +66,7 @@ pub(super) fn classify_by_backend_error_code()}}- BackendErrorCode::UserInsufficientCredits => {+ BackendErrorKind::InsufficientCredits => {classified_plain(C::ManagedBudgetExhausted, provider, None)}// Operator fault (our key/account/quota/5xx) OR operator registry /@@ -77,14 +74,14 @@ pub(super) fn classify_by_backend_error_code(// calm "we've been notified" copy; the backend already paged. We// deliberately DROP the "check your API key" (F4) and "pick a// different model" (F6) copy the BYO substring arms would emit.- BackendErrorCode::UpstreamUnavailable | BackendErrorCode::ModelUnavailable => {+ BackendErrorKind::UpstreamUnavailable | BackendErrorKind::ModelUnavailable => {classified_plain(C::ManagedUnavailable, provider, fallback_available)}- BackendErrorCode::PayloadTooLarge => classified_plain(C::PayloadTooLarge, provider, None),- BackendErrorCode::ContextLengthExceeded => {+ BackendErrorKind::PayloadTooLarge => classified_plain(C::PayloadTooLarge, provider, None),+ BackendErrorKind::ContextLengthExceeded => {classified_plain(C::ContextOverflow, provider, None)}- BackendErrorCode::BadRequest => {+ BackendErrorKind::BadRequest => {// Same code, three shapes. FIRST: a tool-ordering rejection// (`validateToolMessageOrdering` — an orphaned `role:'tool'` message// with no matching assistant `tool_call`) is *poisoned history*, not@@ -100,7 +97,7 @@ pub(super) fn classify_by_backend_error_code(// user-parameter rejection is a model/param mismatch the user can// fix. The copy differs: don't tell the user to abandon the thread// for a one-off malformation (only this turn failed).- } else if body_flags_malformed(err) {+ } else if classification.malformed_bad_request {classified_plain(C::ManagedMalformedRequest, provider, None)} else {classified_plain(C::ManagedRequestRejected, provider, None)@@ -108,7 +105,7 @@ pub(super) fn classify_by_backend_error_code(}// Backend already paged its own 500; the FE must not double-report// (gated in the Sentry classifier) and the user just retries.- BackendErrorCode::InternalError => {+ BackendErrorKind::Internal => {classified_plain(C::ManagedInternal, provider, fallback_available)}};