Skip to content

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

fix(cron): ignore process-wide signed-out state in saas mode

Steven Enamakel3e49686897fd
diff --git a/crates/openhuman-core/src/cron/scheduler_gate/gate.rs b/crates/openhuman-core/src/cron/scheduler_gate/gate.rs
index a458391700..3d4f2bdd3e 100644
--- a/crates/openhuman-core/src/cron/scheduler_gate/gate.rs
+++ b/crates/openhuman-core/src/cron/scheduler_gate/gate.rs
@@ -186,9 +186,14 @@ pub fn current_policy() -> Policy {
/// `true` when the signed-out override is active. Cheap atomic load —
/// safe to call from hot paths (e.g. per-LLM-call short-circuit in
/// `OpenHumanBackendModel`).
+///
+/// Always `false` in SaaS mode: there, signed in is a fact about each user,
+/// checked against that user's own credential when it is used, and one
+/// process-wide flag would let one user's expiry (or the operator's lack of a
+/// credential) stop every user's model calls.
#[cfg(not(test))]
pub fn is_signed_out() -> bool {
- SIGNED_OUT.load(Ordering::Acquire)
+ !crate::core::runtime::is_saas() && SIGNED_OUT.load(Ordering::Acquire)
}
#[cfg(test)]
@@ -213,11 +218,17 @@ pub fn is_signed_out() -> bool {
/// forever in the `paused_poll_ms` branch of [`wait_for_capacity`].
/// Gating at the writer is a belt-and-braces companion to the reader-side
/// guard added in PR #1552.
+///
+/// A no-op in SaaS mode (see [`is_signed_out`]).
#[cfg(not(test))]
pub fn set_signed_out(signed_out: bool) {
if STATE.get().is_none() {
return;
}
+ if crate::core::runtime::is_saas() {
+ log::debug!("[scheduler_gate] SaaS: ignoring process-wide signed_out={signed_out}");
+ return;
+ }
let prev = SIGNED_OUT.swap(signed_out, Ordering::AcqRel);
if prev != signed_out {
log::info!("[scheduler_gate] signed_out {} -> {}", prev, signed_out);
diff --git a/crates/openhuman-core/src/security/credentials/bus.rs b/crates/openhuman-core/src/security/credentials/bus.rs
index c44bf03002..2c93dc48e7 100644
--- a/crates/openhuman-core/src/security/credentials/bus.rs
+++ b/crates/openhuman-core/src/security/credentials/bus.rs
@@ -14,6 +14,9 @@
//! (voice / autocomplete / local AI / dictation).
//! Idempotent — repeat events are safe.
//!
+//! In SaaS mode the handler does nothing process-wide: each user's
+//! credential is theirs, and the gateway refreshes it.
+//!
//! Without this subscriber, a 401 from a background LLM call would only
//! be detected but never acted on, and the same loop would 401 again on
//! the next iteration. This is the fix for issue
@@ -56,6 +59,18 @@ impl EventHandler<DomainEvent> for SessionExpiredSubscriber {
return;
};
+ // SaaS: the credential belongs to one user and the gateway owns its
+ // refresh (`user_agents.set_credential`). Nothing process-wide is torn
+ // down; the failing call already reports the 401 to that user.
+ if crate::core::runtime::is_saas() {
+ tracing::warn!(
+ source = %source,
+ reason = %reason,
+ "[auth] SessionExpired in SaaS mode — left to the gateway; no process-wide teardown"
+ );
+ return;
+ }
+
// (1) Stand down background workers immediately — before any async work.
// Cheap atomic flip; safe to call repeatedly from concurrent publishers.
// We may override this back to `false` below if the current session
diff --git a/tests/saas_mode_e2e.rs b/tests/saas_mode_e2e.rs
index 4cd98b9117..481f30dd1c 100644
--- a/tests/saas_mode_e2e.rs
+++ b/tests/saas_mode_e2e.rs
@@ -793,10 +793,8 @@ fn a_users_turn_reaches_inference_with_their_own_credential() {
Err(_) => break None,
}
};
- let (_, auth) = inference.unwrap_or_else(|| {
- panic!("alice's turn never reached inference; saw {seen:?}")
- });
+ let (_, auth) =
+ inference.unwrap_or_else(|| panic!("alice's turn never reached inference; saw {seen:?}"));
assert_eq!(auth, "Bearer alice-session-jwt");
drop(server);
}
-