Skip to content

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

fix(threads): skip channel turn claims in saas

Steven Enamakel1e56966659cd
diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rs
index 235a0a4a36..d9a00487ed 100644
--- a/crates/openhuman-core/src/threads/store/bus.rs
+++ b/crates/openhuman-core/src/threads/store/bus.rs
@@ -135,7 +135,23 @@ fn claimed_turns() -> std::sync::MutexGuard<'static, ClaimedTurns> {
/// Mark the channel message `(channel, message_id)` as persisted by its
/// caller, so this subscriber does not mirror it a second time under the
/// listener-derived thread id.
+///
+/// A no-op in SaaS: the subscriber is never registered there, so nothing
+/// would read the claim, and its `(channel, message_id)` key carries no
+/// tenant — one profile's claim would otherwise shadow another profile's
+/// message with the same platform id. Outside SaaS there is one user, and the
+/// subscriber (which runs off the bus, with no caller scope to key on) reads
+/// the bare key.
pub(crate) fn claim_channel_turn(channel: &str, message_id: &str) {
+ claim_channel_turn_in(crate::core::runtime::is_saas(), channel, message_id);
+}
+
+/// [`claim_channel_turn`] as a function of the mode.
+pub(crate) fn claim_channel_turn_in(saas: bool, channel: &str, message_id: &str) {
+ if saas {
+ log::trace!("{LOG_PREFIX} SaaS: channel turn claim skipped channel={channel}");
+ return;
+ }
claimed_turns().claim(channel, message_id);
}
diff --git a/crates/openhuman-core/src/threads/store/bus_tests.rs b/crates/openhuman-core/src/threads/store/bus_tests.rs
index efd851b150..e51ad88c9f 100644
--- a/crates/openhuman-core/src/threads/store/bus_tests.rs
+++ b/crates/openhuman-core/src/threads/store/bus_tests.rs
@@ -531,6 +531,17 @@ async fn claimed_channel_turns_are_left_to_their_caller() {
);
}
+#[test]
+fn saas_claims_nothing() {
+ claim_channel_turn_in(true, "relay-saas-channel", "saas-claim-1");
+ assert!(
+ !is_claimed_channel_turn("relay-saas-channel", "saas-claim-1"),
+ "no subscriber reads a claim in SaaS, so none is kept to collide across profiles"
+ );
+ claim_channel_turn_in(false, "relay-saas-channel", "saas-claim-2");
+ assert!(is_claimed_channel_turn("relay-saas-channel", "saas-claim-2"));
+}
+
#[test]
fn the_claim_list_is_bounded() {
let mut claimed = ClaimedTurns::new(3);