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(platform): move scheduler_gate to platform::llm_gate
Steven Enamakel241598913b45
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rsindex 780c6f0f47..ad85d23ff2 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs@@ -7,7 +7,7 @@//! It declares [`BudgetGate`] instead, and this module is the single place//! OpenHuman's three metering concerns meet it://!-//! * **admission / back-pressure** — [`scheduler_gate::wait_for_capacity`],+//! * **admission / back-pressure** — [`llm_gate::wait_for_capacity`],//! which owns the single-slot global LLM semaphore and the//! AC-power / CPU / signed-out policy backoff;//! * **pricing hints and budgets** — [`tinyagents_registry::pricing::estimate_cost_usd`] on@@ -90,7 +90,7 @@ pub struct OpenHumanBudgetGate {/// mismatch (1) in the module docs.last_model: RwLock<String>,/// Whether this session's model calls are **background** work that must- /// queue behind [`scheduler_gate`].+ /// queue behind [`llm_gate`].////// Defaults to `false`, because that gate is for background AI only: its/// `Paused` arm polls indefinitely while background work is disabled or the@@ -138,7 +138,7 @@ impl OpenHumanBudgetGate {/// Marks this session's model calls as background work.////// Only then does [`acquire`](Self::acquire) queue behind- /// [`scheduler_gate`], which is the concurrency limiter for background AI —+ /// [`llm_gate`], which is the concurrency limiter for background AI —/// cron jobs, memory workers. Interactive turns must/// **not** opt in: the gate's `Paused` arm waits for background work to be/// re-enabled, which for a user-initiated chat means waiting until the turn@@ -287,7 +287,7 @@ impl BudgetGate for OpenHumanBudgetGate {/// Ordered budget-check-first on purpose: a refusal must not first occupy/// the single global LLM slot that another, affordable, call could use.///- /// The returned [`Permit`] owns the [`scheduler_gate::LlmPermit`] inside its+ /// The returned [`Permit`] owns the [`llm_gate::LlmPermit`] inside its/// release hook, so dropping the crate permit — on return, on `?`, on/// cancellation, on unwind — is what returns the semaphore slot. There is/// exactly one owner and it is never cloned; the crate's `Permit` is@@ -355,7 +355,7 @@ impl BudgetGate for OpenHumanBudgetGate {// caller treats that as "skip the gate" rather than an error, and so// does this one — failing here would deadlock the pipeline on a// condition that is not the user's fault.- let Some(llm_permit) = scheduler_gate::wait_for_capacity().await else {+ let Some(llm_permit) = llm_gate::wait_for_capacity().await else {log::warn!("[tinyagents][budget] scheduler gate returned no permit (semaphore closed); \proceeding ungated"diff --git a/crates/openhuman-core/src/agent/triage/evaluator/chain.rs b/crates/openhuman-core/src/agent/triage/evaluator/chain.rsindex eaddf49189..d7bdb5e125 100644--- a/crates/openhuman-core/src/agent/triage/evaluator/chain.rs+++ b/crates/openhuman-core/src/agent/triage/evaluator/chain.rs@@ -8,7 +8,7 @@ use std::time::Duration;use anyhow::Context;-use crate::cron::scheduler_gate::LlmPermit;+use crate::cron::llm_gate::LlmPermit;use super::super::envelope::TriggerEnvelope;use super::super::events;@@ -89,7 +89,7 @@ pub async fn run_triage(let local = build_local_provider_with_config(ctx, &config);let outcome = run_triage_with_arms_inner(cloud, local, envelope, Some(retry_state()), || {- crate::cron::scheduler_gate::wait_for_capacity()+ crate::cron::llm_gate::wait_for_capacity()}).await;if let Err(err) = &outcome {@@ -125,7 +125,7 @@ pub(crate) async fn run_triage_with_arms_for_test_with_state(////// `acquire_permit` is called exactly once, on the local-fallback arm,/// to obtain the global LLM permit. Production callers pass-/// `scheduler_gate::wait_for_capacity`; tests pass `|| async { None }`+/// `llm_gate::wait_for_capacity`; tests pass `|| async { None }`/// to skip the shared semaphore.async fn run_triage_with_arms_inner<F, Fut>(cloud: ResolvedProvider,diff --git a/crates/openhuman-core/src/core/observability.rs b/crates/openhuman-core/src/core/observability.rsindex 07a75efd48..f3c80287ec 100644--- a/crates/openhuman-core/src/core/observability.rs+++ b/crates/openhuman-core/src/core/observability.rs@@ -935,7 +935,7 @@ fn is_embedding_model_rejected(lower: &str) -> bool {/// streaming 401s still escalate — guarded by/// `does_not_classify_streaming_byo_key_401_as_session_expired`./// - `"SESSION_EXPIRED: backend session not active — sign in to resume LLM work"`-/// — the `scheduler_gate::is_signed_out` sentinel from+/// — the `llm_gate::is_signed_out` sentinel from/// `providers::openhuman_backend::resolve_bearer`./// - `"no backend session token; run auth_store_session first"` and/// `"session JWT required"` — local pre-flight guards that fire when thediff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rsindex 3da2da000a..bfa33c3eb2 100644--- a/crates/openhuman-core/src/cron/mod.rs+++ b/crates/openhuman-core/src/cron/mod.rs@@ -7,7 +7,6 @@// Host-condition policy (battery / AC / CPU) that throttles background LLM// work such as memory digests. The cron poll loop itself does not consult it.-pub mod scheduler_gate;pub mod bus;pub mod channel_bridge;diff --git a/crates/openhuman-core/src/flows/ops/inference_readiness.rs b/crates/openhuman-core/src/flows/ops/inference_readiness.rsindex 7ed90dde25..e829000ca1 100644--- a/crates/openhuman-core/src/flows/ops/inference_readiness.rs+++ b/crates/openhuman-core/src/flows/ops/inference_readiness.rs@@ -38,7 +38,7 @@ use super::*;// Two layers, cheapest and most decisive first://// - **Layer 1 (sync)** — the desktop session itself: signed out-// (`scheduler_gate::is_signed_out`), or no valid `app-session` JWT+// (`llm_gate::is_signed_out`), or no valid `app-session` JWT// (`inference::provider::factory::verify_session_active`, the exact check// every custom-provider construction already gates on).// - **Layer 2 (async, cached)** — one cheap real probe per DISTINCT resolved@@ -102,7 +102,7 @@ pub(super) static INFERENCE_PROBE_CACHE: LazyLock<std::sync::Mutex<InferenceProb/// window. Clears the whole cache rather than just the current key: a/// sign-out is a session-wide event, not scoped to one role.fn invalidate_inference_probe_cache_if_signed_out() {- if crate::cron::scheduler_gate::is_signed_out() {+ if crate::cron::llm_gate::is_signed_out() {INFERENCE_PROBE_CACHE.lock().unwrap_or_else(std::sync::PoisonError::into_inner)@@ -296,7 +296,7 @@ pub(super) async fn evaluate_inference_readiness(// Layer 1: signed-out is the cheapest, most decisive check. Session-wide// — checked once for the whole graph, not per node/role.- if needs_session && crate::cron::scheduler_gate::is_signed_out() {+ if needs_session && crate::cron::llm_gate::is_signed_out() {tracing::debug!(target: "flows",node = %first_node.id,diff --git a/crates/openhuman-core/src/integrations/task_sources/route.rs b/crates/openhuman-core/src/integrations/task_sources/route.rsindex 9d874fc08f..7a48e960b9 100644--- a/crates/openhuman-core/src/integrations/task_sources/route.rs+++ b/crates/openhuman-core/src/integrations/task_sources/route.rs@@ -56,7 +56,7 @@ async fn dispatch_triage() -> Result<(), String> {// Respect background-AI throttling. When the gate denies capacity// (Off / paused), we keep the card but skip the proactive turn.- let Some(_permit) = scheduler_gate::wait_for_capacity().await else {+ let Some(_permit) = llm_gate::wait_for_capacity().await else {tracing::info!(source_id = %source.id,"[task_sources:route] scheduler gate denied capacity; agent turn skipped"diff --git a/crates/openhuman-core/src/cron/scheduler_gate/README.md b/crates/openhuman-core/src/platform/llm_gate/README.mdsimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/README.mdrename to crates/openhuman-core/src/platform/llm_gate/README.mddiff --git a/crates/openhuman-core/src/cron/scheduler_gate/decide.rs b/crates/openhuman-core/src/platform/llm_gate/decide.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/decide.rsrename to crates/openhuman-core/src/platform/llm_gate/decide.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/decide_tests.rs b/crates/openhuman-core/src/platform/llm_gate/decide_tests.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/decide_tests.rsrename to crates/openhuman-core/src/platform/llm_gate/decide_tests.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/gate.rs b/crates/openhuman-core/src/platform/llm_gate/gate.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/gate.rsrename to crates/openhuman-core/src/platform/llm_gate/gate.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/gate_test_state_tests.rs b/crates/openhuman-core/src/platform/llm_gate/gate_test_state_tests.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/gate_test_state_tests.rsrename to crates/openhuman-core/src/platform/llm_gate/gate_test_state_tests.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/gate_tests.rs b/crates/openhuman-core/src/platform/llm_gate/gate_tests.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/gate_tests.rsrename to crates/openhuman-core/src/platform/llm_gate/gate_tests.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/mod.rs b/crates/openhuman-core/src/platform/llm_gate/mod.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/mod.rsrename to crates/openhuman-core/src/platform/llm_gate/mod.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/signals.rs b/crates/openhuman-core/src/platform/llm_gate/signals.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/signals.rsrename to crates/openhuman-core/src/platform/llm_gate/signals.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/signals_tests.rs b/crates/openhuman-core/src/platform/llm_gate/signals_tests.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/signals_tests.rsrename to crates/openhuman-core/src/platform/llm_gate/signals_tests.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/throttle.rs b/crates/openhuman-core/src/platform/llm_gate/throttle.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/throttle.rsrename to crates/openhuman-core/src/platform/llm_gate/throttle.rsdiff --git a/crates/openhuman-core/src/cron/scheduler_gate/throttle_tests.rs b/crates/openhuman-core/src/platform/llm_gate/throttle_tests.rssimilarity index 100%rename from crates/openhuman-core/src/cron/scheduler_gate/throttle_tests.rsrename to crates/openhuman-core/src/platform/llm_gate/throttle_tests.rsdiff --git a/crates/openhuman-core/src/platform/mod.rs b/crates/openhuman-core/src/platform/mod.rsindex bc2a0ffe19..d21d415a5f 100644--- a/crates/openhuman-core/src/platform/mod.rs+++ b/crates/openhuman-core/src/platform/mod.rs@@ -10,6 +10,7 @@ pub mod cost;pub mod doctor;pub mod health;pub mod proc_metrics;+pub mod llm_gate;pub(crate) mod resource_admission;pub mod service;pub mod socket;diff --git a/crates/openhuman-core/src/security/credentials/bus.rs b/crates/openhuman-core/src/security/credentials/bus.rsindex b9dff45bdf..6e7d43c646 100644--- a/crates/openhuman-core/src/security/credentials/bus.rs+++ b/crates/openhuman-core/src/security/credentials/bus.rs@@ -91,7 +91,7 @@ impl SessionExpiredSubscriber {// Cheap atomic flip; safe to call repeatedly from concurrent publishers.// We may override this back to `false` below if the current session// turns out to be a local offline session (never truly expired).- scheduler_gate::set_signed_out(true);+ llm_gate::set_signed_out(true);match ctx.load_config().await {Ok(config) => {@@ -103,7 +103,7 @@ impl SessionExpiredSubscriber {reason = %reason,"[auth] SessionExpired ignored — runtime authenticates with an API key; re-enabling scheduler gate");- scheduler_gate::set_signed_out(false);+ llm_gate::set_signed_out(false);return;}let is_local_session =@@ -122,7 +122,7 @@ impl SessionExpiredSubscriber {"[auth] SessionExpired ignored for local offline session — re-enabling scheduler gate");// Undo the eager flip: local sessions are never truly expired.- scheduler_gate::set_signed_out(false);+ llm_gate::set_signed_out(false);return;}diff --git a/crates/openhuman-core/src/security/credentials/bus_tests.rs b/crates/openhuman-core/src/security/credentials/bus_tests.rsindex 2d52581be0..d56a21c200 100644--- a/crates/openhuman-core/src/security/credentials/bus_tests.rs+++ b/crates/openhuman-core/src/security/credentials/bus_tests.rs@@ -19,13 +19,13 @@ async fn handle_ignores_non_auth_events() {// events to every subscriber. The handler must guard internally.let s = SessionExpiredSubscriber::new();// Reset state we depend on.- scheduler_gate::set_signed_out(false);+ llm_gate::set_signed_out(false);s.handle(&DomainEvent::SystemStartup {component: "test".into(),}).await;assert!(- !scheduler_gate::is_signed_out(),+ !llm_gate::is_signed_out(),"non-auth event must not flip the override");}@@ -33,7 +33,7 @@ async fn handle_ignores_non_auth_events() {#[tokio::test]async fn session_expired_in_saas_returns_before_any_teardown() {let s = SessionExpiredSubscriber::new();- scheduler_gate::set_signed_out(false);+ llm_gate::set_signed_out(false);// In single-user mode this would load the config and may flip the gate;// in SaaS it must return at once, leaving the gate untouched.tokio::time::timeout(@@ -49,5 +49,5 @@ async fn session_expired_in_saas_returns_before_any_teardown() {).await.expect("SaaS early return must not await the config load");- assert!(!scheduler_gate::is_signed_out());+ assert!(!llm_gate::is_signed_out());}