Skip to content

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

fix(agent): handle inference failures in loop guards and triage evaluator

Steven Enamakel6f8a700c5148
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
index 25539994a4..6e734e9b8f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
@@ -1,6 +1,9 @@
-//! Loop-guard thresholds, classifiers, and halt-summary wording shared by the
+//! Loop-guard thresholds and the repeat-call exemption shared by the
//! repeated-failure and repeat-progress breakers (issue #4463), ported verbatim
-//! from the deleted `agent/harness/tool_loop.rs`.
+//! from the deleted `agent/harness/tool_loop.rs`. The halt-summary wording and
+//! the terminal-inference recogniser live in the host copy table
+//! (`inference::failure_copy`); the recoverable-failure marker list in
+//! `tinyinference_llm::failure`.
// ── Loop-guard restorations (issue #4463) ────────────────────────────────────
//
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
index fb0992f692..7429122829 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
@@ -20,11 +20,15 @@ use tinyinference_llm::tool::ToolCall as TaToolCall;
use tinytools::ToolResult as TaToolResult;
use super::loop_guards::{
- is_recoverable_tool_failure, is_repeat_call_exempt, recoverable_identical_halt_summary,
- recoverable_no_progress_halt_summary, terminal_inference_failure_kind,
- terminal_inference_halt_summary, RECOVERABLE_NO_PROGRESS_FAILURE_THRESHOLD,
+ is_repeat_call_exempt, RECOVERABLE_NO_PROGRESS_FAILURE_THRESHOLD,
RECOVERABLE_REPEAT_FAILURE_THRESHOLD,
};
+use crate::inference::failure_copy::{
+ recoverable_identical_halt_summary, recoverable_no_progress_halt_summary,
+ terminal_inference_failure_kind, terminal_inference_halt_summary,
+};
+pub(crate) use crate::inference::failure_copy::user_actionable_escalation;
+use tinyinference_llm::failure::is_recoverable_failure_text as is_recoverable_tool_failure;
/// `after_tool`: stop (or nudge) the run when tool calls keep failing with no
/// progress (issue #4249). The legacy tool loop's progress guard surfaced a
diff --git a/crates/openhuman-core/src/agent/triage/evaluator/arm.rs b/crates/openhuman-core/src/agent/triage/evaluator/arm.rs
index e230c090ac..7acfb5db64 100644
--- a/crates/openhuman-core/src/agent/triage/evaluator/arm.rs
+++ b/crates/openhuman-core/src/agent/triage/evaluator/arm.rs
@@ -282,45 +282,13 @@ fn is_prompt_guard_rejection(message: &str) -> bool {
/// call because the user's inference budget or credit balance is empty —
/// meaning a retry would hit the same wall.
///
-/// The vocabulary matches the OpenHuman backend's error copy and common
-/// third-party provider phrasing. It does **not** mirror the
-/// *semantics* of `web_chat/` (a different code path);
-/// it is an independent, conservative allowlist evaluated inline so the
-/// triage evaluator carries no cross-domain import.
-///
-/// Kept conservative on purpose: a false positive would silently
-/// reclassify a real `Fatal` error as `BudgetExhausted`, hiding it from
-/// Sentry.
+/// Uses the shared matcher at [`BudgetMatch::Strict`]: whole-word needles only,
+/// because a false positive would silently reclassify a real `Fatal` error as
+/// `BudgetExhausted`, hiding it from Sentry. (`stop updating` must not read as
+/// `top up`.) This is deliberately narrower than the chat surface's
+/// `BudgetMatch::Managed`.
fn is_inference_budget_exceeded(message: &str) -> bool {
- // Normalize: lowercase, replace non-alphanumeric with spaces, then
- // split into whitespace-separated tokens. This lets us do
- // whole-word matching: a raw `contains("top up")` against the
- // normalized text would also fire on "stop updating" (which
- // contains the substring "top up" across word boundaries).
- 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())
- })
+ is_budget_message(message, BudgetMatch::Strict)
}
/// Heuristic for transient cloud failures the provider stack didn't
diff --git a/crates/openhuman-core/src/inference/failure_copy/mod.rs b/crates/openhuman-core/src/inference/failure_copy/mod.rs
new file mode 100644
index 0000000000..43b0601bd5
--- /dev/null
+++ b/crates/openhuman-core/src/inference/failure_copy/mod.rs
@@ -0,0 +1,21 @@
+//! One host copy table for user-facing failure text.
+//!
+//! - [`table`]: failure class -> (`error_type` wire token, `source`,
+//! `retryable`, user copy), consumed by `web_chat::web_errors` to build the
+//! `chat_error` envelope.
+//! - [`halt`]: the loop-guard halt summaries and the delegated-inference
+//! recogniser that picks between them.
+//!
+//! Provider-text matching (including the one budget-phrase matcher,
+//! `tinyinference_providers::is_budget_message`) lives upstream in
+//! `tinyinference`; deciding *which class an error is* stays in the callers.
+
+mod halt;
+mod table;
+
+pub(crate) use halt::{
+ recoverable_identical_halt_summary, recoverable_no_progress_halt_summary,
+ terminal_inference_failure_kind, terminal_inference_halt_summary, user_actionable_escalation,
+ TerminalInferenceFailure,
+};
+pub(crate) use table::{failure_copy, FailureClass};
diff --git a/crates/openhuman-core/src/inference/mod.rs b/crates/openhuman-core/src/inference/mod.rs
index 7d6416b932..f464e69d2e 100644
--- a/crates/openhuman-core/src/inference/mod.rs
+++ b/crates/openhuman-core/src/inference/mod.rs
@@ -22,6 +22,7 @@ pub const INFERENCE_COMPILED_IN: bool = cfg!(feature = "inference");
pub mod auth_error_registry;
pub mod embedding_host;
+pub(crate) mod failure_copy;
pub mod host_runtime;
pub mod http;
pub mod model_context;
diff --git a/crates/openhuman-core/src/web_chat/web_errors.rs b/crates/openhuman-core/src/web_chat/web_errors.rs
index b08d86adf0..47b9fef5c9 100644
--- a/crates/openhuman-core/src/web_chat/web_errors.rs
+++ b/crates/openhuman-core/src/web_chat/web_errors.rs
@@ -6,7 +6,6 @@
mod backend_error_code;
mod budget;
mod classify;
-mod response_predicates;
mod retry;
mod timeout;
diff --git a/crates/openhuman-core/src/web_chat/web_errors/response_predicates.rs b/crates/openhuman-core/src/web_chat/web_errors/response_predicates.rs
deleted file mode 100644
index 77131be581..0000000000
--- a/crates/openhuman-core/src/web_chat/web_errors/response_predicates.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-//! User-facing copy tied to a recognised response shape. The string-level
-//! predicates themselves live in `tinyinference_llm::failure`.
-
-/// User-facing copy for a poisoned-history 400 (orphaned tool message). 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.
-pub(crate) fn malformed_history_user_message() -> &'static str {
- "We hit a temporary glitch in this conversation — we've cleared it. \
- Please send your message again."
-}