Skip to content

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

fix: keep billing policy in openhuman

Steven Enamakele61819a818e3
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs
index 3a40f8a161..e959612aff 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs
@@ -159,14 +159,14 @@ pub(super) fn scout_failure_signal(err: &SubagentRunError) -> String {
/// Two billing shapes reach here, both **user-state, not defects**:
/// * the managed OpenHuman backend's budget-exhausted 400
/// (`{"error":"Insufficient budget","errorCode":"USER_INSUFFICIENT_CREDITS"}`),
-/// matched by [`tinyinference_llm::classification::is_budget_exhausted_message`];
+/// matched by [`crate::hosted::billing::classify::is_budget_exhausted_message`];
/// * a BYO provider's insufficient-credits 402, matched by
/// [`crate::core::observability::is_insufficient_credits_message`].
///
/// Both delegate to the crate's single-source classifiers so the phrase sets
/// can't drift from the cron halt / `before_send` nets that share them.
pub(super) fn is_expected_billing_failure(message: &str) -> bool {
- tinyinference_llm::classification::is_budget_exhausted_message(message)
+ crate::hosted::billing::classify::is_budget_exhausted_message(message)
|| crate::core::observability::is_insufficient_credits_message(message)
}
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 2202cd4fea..a1a7d8b6c0 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
@@ -113,7 +113,7 @@ fn has_inference_failure_envelope(result: &str) -> bool {
/// the two tight provider classifiers. Budget takes precedence if both match.
/// Ported from legacy `tool_loop::terminal_inference_failure_kind` (#3104).
pub(crate) fn terminal_inference_failure_kind(result: &str) -> Option<TerminalInferenceFailure> {
- use tinyinference_llm::classification::is_budget_exhausted_message;
+ use crate::hosted::billing::classify::is_budget_exhausted_message;
use tinyinference_providers::is_provider_config_rejection_message;
if !has_inference_failure_envelope(result) {
return None;
diff --git a/crates/openhuman-core/src/api/rest.rs b/crates/openhuman-core/src/api/rest.rs
index ccfb98f54c..5231150b09 100644
--- a/crates/openhuman-core/src/api/rest.rs
+++ b/crates/openhuman-core/src/api/rest.rs
@@ -821,7 +821,7 @@ impl BackendOAuthClient {
let is_transient_infra =
crate::core::observability::is_transient_http_status_code(status_code);
let is_budget_exhausted = status_code == 400
- && tinyinference_llm::classification::is_budget_exhausted_message(&text);
+ && crate::hosted::billing::classify::is_budget_exhausted_message(&text);
if is_budget_exhausted {
tracing::info!(
method = method.as_str(),
diff --git a/crates/openhuman-core/src/core/observability.rs b/crates/openhuman-core/src/core/observability.rs
index ec26744a4f..824a6b21fe 100644
--- a/crates/openhuman-core/src/core/observability.rs
+++ b/crates/openhuman-core/src/core/observability.rs
@@ -648,7 +648,7 @@ pub fn expected_error_kind(message: &str) -> Option<ExpectedErrorKind> {
if is_local_ai_capability_unavailable_message(&lower) {
return Some(ExpectedErrorKind::LocalAiCapabilityUnavailable);
}
- if tinyinference_llm::classification::is_budget_exhausted_message(message) {
+ if crate::hosted::billing::classify::is_budget_exhausted_message(message) {
return Some(ExpectedErrorKind::BudgetExhausted);
}
if is_prompt_injection_blocked_message(&lower) {
@@ -3426,7 +3426,7 @@ fn event_contains_budget_exhausted_message(event: &sentry::protocol::Event<'_>)
if event
.message
.as_deref()
- .is_some_and(tinyinference_llm::classification::is_budget_exhausted_message)
+ .is_some_and(crate::hosted::billing::classify::is_budget_exhausted_message)
{
return true;
}
@@ -3435,7 +3435,7 @@ fn event_contains_budget_exhausted_message(event: &sentry::protocol::Event<'_>)
exception
.value
.as_deref()
- .is_some_and(tinyinference_llm::classification::is_budget_exhausted_message)
+ .is_some_and(crate::hosted::billing::classify::is_budget_exhausted_message)
})
}
diff --git a/crates/openhuman-core/src/cron/scheduler/failure_classification.rs b/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
index e4338c6790..d5f7b7f690 100644
--- a/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
+++ b/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
@@ -193,7 +193,7 @@ pub(super) fn is_budget_exhausted_failure(
return false;
}
let signal = last_agent_error.unwrap_or(last_output);
- tinyinference_llm::classification::is_budget_exhausted_message(signal)
+ crate::hosted::billing::classify::is_budget_exhausted_message(signal)
}
/// TAURI-RUST-HCK — a cron **agent** job pinned to a provider with no
diff --git a/crates/openhuman-core/src/hosted/billing/classify.rs b/crates/openhuman-core/src/hosted/billing/classify.rs
new file mode 100644
index 0000000000..098cf9d79b
--- /dev/null
+++ b/crates/openhuman-core/src/hosted/billing/classify.rs
@@ -0,0 +1,20 @@
+//! OpenHuman billing-state classification used by UI and telemetry policy.
+
+/// Return whether a provider message represents deterministic exhausted-budget
+/// user state rather than a product defect.
+pub fn is_budget_exhausted_message(message: &str) -> bool {
+ const PHRASES: &[&str] = &[
+ "insufficient budget",
+ "budget exceeded",
+ "add credits",
+ "insufficient balance",
+ "no remaining credits",
+ "credit balance is too low",
+ ];
+ let lower = message.to_ascii_lowercase();
+ PHRASES.iter().any(|phrase| lower.contains(phrase))
+}
+
+#[cfg(test)]
+#[path = "classify_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/hosted/billing/classify_tests.rs b/crates/openhuman-core/src/hosted/billing/classify_tests.rs
new file mode 100644
index 0000000000..7c4c81ba9e
--- /dev/null
+++ b/crates/openhuman-core/src/hosted/billing/classify_tests.rs
@@ -0,0 +1,26 @@
+use super::*;
+
+#[test]
+fn detects_known_budget_exhaustion_phrases_case_insensitively() {
+ for message in [
+ "INSUFFICIENT BUDGET",
+ "budget EXCEEDED — ADD credits",
+ "Insufficient BALANCE",
+ "You have no remaining credits to use the LLM apis.",
+ "Your CREDIT BALANCE IS TOO LOW to access the Anthropic API",
+ ] {
+ assert!(is_budget_exhausted_message(message), "{message:?}");
+ }
+}
+
+#[test]
+fn ignores_non_budget_messages() {
+ for message in [
+ "Bad request: missing field",
+ "You have 100 remaining credits this month",
+ "Your credit balance is $50.00",
+ "",
+ ] {
+ assert!(!is_budget_exhausted_message(message), "{message:?}");
+ }
+}
diff --git a/crates/openhuman-core/src/hosted/billing/mod.rs b/crates/openhuman-core/src/hosted/billing/mod.rs
index b058a8a6f7..9dcc71acb3 100644
--- a/crates/openhuman-core/src/hosted/billing/mod.rs
+++ b/crates/openhuman-core/src/hosted/billing/mod.rs
@@ -3,6 +3,7 @@
//! Exposes plan lookup, purchase flows, and credit top-ups through the
//! standard controller registry (`openhuman.billing_*`).
+pub mod classify;
mod ops;
mod schemas;
diff --git a/crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs b/crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs
index e194e736dc..72d4f19a1a 100644
--- a/crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/rpc/embed.rs
@@ -101,7 +101,9 @@ pub async fn test_connection(
);
let result = if let Some(endpoint) = custom_endpoint.as_deref() {
- probe_custom_embeddings(endpoint, &api_key, model, dims).await
+ probe_custom_embeddings(endpoint, &api_key, model, dims)
+ .await
+ .map_err(|error| error.to_string())
} else {
let embedder = create_embedding_provider_with_config(
config,
diff --git a/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs b/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs
index 885188e087..d317ec7592 100644
--- a/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs
+++ b/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs
@@ -5,7 +5,7 @@
/// user-state error that should be demoted from Sentry to an info log.
pub fn is_budget_exhausted_http_400(status: reqwest::StatusCode, body: &str) -> bool {
status == reqwest::StatusCode::BAD_REQUEST
- && tinyinference_llm::classification::is_budget_exhausted_message(body)
+ && crate::hosted::billing::classify::is_budget_exhausted_message(body)
}
pub fn log_budget_exhausted_http_400(
diff --git a/crates/openhuman-core/src/web_chat/web_errors/budget.rs b/crates/openhuman-core/src/web_chat/web_errors/budget.rs
index 057544fd08..91b22bd95f 100644
--- a/crates/openhuman-core/src/web_chat/web_errors/budget.rs
+++ b/crates/openhuman-core/src/web_chat/web_errors/budget.rs
@@ -34,7 +34,7 @@ pub(crate) fn is_inference_budget_exceeded_error(message: &str) -> bool {
// (issue #3088). Without this, an Ollama user with zero credits and
// routing still on Managed sees an opaque "provider error" and has no
// way to self-diagnose that they must top up or switch routing.
- tinyinference_llm::classification::is_budget_exhausted_message(message)
+ crate::hosted::billing::classify::is_budget_exhausted_message(message)
}
pub(crate) fn inference_budget_exceeded_user_message() -> &'static str {
diff --git a/vendor/tinyagents b/vendor/tinyagents
index 89ccce12c3..40c9ab9aa5 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit 89ccce12c3231e029b5e3a8522552ea9b1d152ff
+Subproject commit 40c9ab9aa527ebe037c7ff8398729b476888afe6