Skip to content

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

feat(channels): derive inbound identity via channel module

Steven Enamakelf3299c7f2129
diff --git a/Cargo.lock b/Cargo.lock
index d717f01696..90cca87450 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -143,7 +143,7 @@ version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -154,7 +154,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -702,7 +702,7 @@ dependencies = [
"cap-primitives",
"cap-std",
"io-lifetimes 3.0.1",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -719,7 +719,7 @@ dependencies = [
"maybe-owned",
"rustix",
"rustix-linux-procfs",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
"winx",
]
@@ -1560,7 +1560,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -1771,7 +1771,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -3594,7 +3594,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -4800,7 +4800,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -5317,7 +5317,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -5385,7 +5385,7 @@ dependencies = [
"security-framework 3.7.0",
"security-framework-sys",
"webpki-root-certs",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -5965,7 +5965,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6265,7 +6265,7 @@ dependencies = [
"getrandom 0.4.3",
"once_cell",
"rustix",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6278,7 +6278,7 @@ dependencies = [
"parking_lot",
"rustix",
"signal-hook",
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
@@ -6682,7 +6682,7 @@ dependencies = [
[[package]]
name = "tinychannels"
-version = "0.1.21"
+version = "0.1.22"
dependencies = [
"anyhow",
"async-imap",
@@ -6728,7 +6728,7 @@ dependencies = [
[[package]]
name = "tinychannels-bus"
-version = "0.1.21"
+version = "0.1.22"
dependencies = [
"base64 0.23.1",
"schemars",
@@ -6739,7 +6739,7 @@ dependencies = [
[[package]]
name = "tinychannels-runtime"
-version = "0.1.21"
+version = "0.1.22"
dependencies = [
"anyhow",
"async-trait",
@@ -8579,7 +8579,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.60.2",
]
[[package]]
diff --git a/crates/openhuman-core/src/channels/bus/subscriber.rs b/crates/openhuman-core/src/channels/bus/subscriber.rs
index 307e15bf19..e3564e6afe 100644
--- a/crates/openhuman-core/src/channels/bus/subscriber.rs
+++ b/crates/openhuman-core/src/channels/bus/subscriber.rs
@@ -7,7 +7,6 @@
//! [`BackendProgressiveSender`].
use super::delivery::BackendProgressiveSender;
-use super::thread_id::{derive_inbound_client_id, derive_inbound_thread_id};
use crate::core::events::DomainEvent;
use async_trait::async_trait;
use std::sync::Arc;
@@ -75,32 +74,32 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
return;
}
- // Mirror `channels::context::conversation_history_key`: the inbound
- // path must key on `(channel, sender, reply_target, thread_ts)` —
- // not channel alone — or distinct participants in a shared
- // Discord / Slack channel get collapsed into one cached agent
- // session, and the second sender resumes the first's in-flight
- // state (including any prepared wallet quote).
- //
- // Legacy publishers that don't fill in `sender` fall back to the
- // old channel-only key so existing single-DM flows keep working.
- let thread_id = derive_inbound_thread_id(
- channel,
- sender.as_deref(),
- reply_target.as_deref(),
- thread_ts.as_deref(),
- );
- // Per-sender client_id so the `AGENT_TURN_ORIGIN.WebChat.client_id`
- // and the wallet `QuoteOwner.client_id` paired with it differ across
- // distinct senders in the same shared channel. The thread_id is
- // already per-sender via `derive_inbound_thread_id`, and the
- // wallet/approval gates compare both halves of the (thread_id,
- // client_id) owner pair for equality — but a single shared
- // `client_id="inbound"` collapses the surface for any downstream
- // consumer that keys on client_id alone (audit logs, future
- // session-scoped caches, etc.). Build a stable per-sender label
- // here so the surface stays segregated end-to-end.
- let client_id = derive_inbound_client_id(channel, sender.as_deref());
+ let config = match crate::config::rpc::load_config_with_timeout().await {
+ Ok(config) => config,
+ Err(error) => {
+ tracing::error!("[channel-inbound] failed to load configuration: {error}");
+ return;
+ }
+ };
+ let identity = match crate::modules::channel_controller::prepare_identity(
+ &crate::modules::client::ModuleClient::new(config),
+ tinychannels_bus::module_inbound::PrepareChannelIdentityRequest {
+ channel: channel.clone(),
+ sender: sender.clone(),
+ reply_target: reply_target.clone(),
+ thread_ts: thread_ts.clone(),
+ },
+ )
+ .await
+ {
+ Ok(identity) => identity,
+ Err(error) => {
+ tracing::error!("[channel-inbound] identity preparation failed: {error}");
+ return;
+ }
+ };
+ let thread_id = identity.thread_id;
+ let client_id = identity.client_id;
let mut event_rx = crate::web_chat::subscribe_web_channel_events();
let mut reply = ProgressiveReply::new(Arc::new(BackendProgressiveSender), channel.clone());
diff --git a/crates/openhuman-core/src/modules/channel_controller.rs b/crates/openhuman-core/src/modules/channel_controller.rs
index d74f46b913..2e3e4e087f 100644
--- a/crates/openhuman-core/src/modules/channel_controller.rs
+++ b/crates/openhuman-core/src/modules/channel_controller.rs
@@ -77,6 +77,20 @@ pub(crate) async fn prepare_message(
.await
}
+/// Derive persisted hosted-ingress identifiers inside the channel module.
+pub(crate) async fn prepare_identity(
+ client: &ModuleClient,
+ request: tinychannels_bus::module_inbound::PrepareChannelIdentityRequest,
+) -> Result<tinychannels_bus::module_inbound::PreparedChannelIdentity, ModuleCallError> {
+ client
+ .call_confidential(
+ "tinychannels",
+ methods::PREPARE_CHANNEL_IDENTITY,
+ (request,),
+ )
+ .await
+}
+
/// Resolve OpenHuman's proxy scope before transmitting provider configuration.
pub(crate) fn discord_proxy(config: &crate::config::Config) -> HttpProxyPolicy {
let proxy = &config.proxy;
diff --git a/crates/openhuman-core/src/modules/channel_controller_tests.rs b/crates/openhuman-core/src/modules/channel_controller_tests.rs
index 026d4a75c0..b5d9a4ed5f 100644
--- a/crates/openhuman-core/src/modules/channel_controller_tests.rs
+++ b/crates/openhuman-core/src/modules/channel_controller_tests.rs
@@ -173,3 +173,24 @@ fn discord_channel_projection_preserves_type_position_and_category() {
.unwrap();
assert_eq!(serde_json::to_value(channels).unwrap(), wire);
}
+
+#[tokio::test]
+async fn hosted_identity_requires_the_module_and_never_uses_a_local_key_fallback() {
+ let mut config = crate::config::Config::default();
+ config.modules.enabled = false;
+ let result = prepare_identity(
+ &ModuleClient::new(config),
+ tinychannels_bus::module_inbound::PrepareChannelIdentityRequest {
+ channel: "discord:fixture".into(),
+ sender: Some("fixture-private-sender".into()),
+ reply_target: Some("fixture-private-chat".into()),
+ thread_ts: None,
+ },
+ )
+ .await;
+ let error = result
+ .err()
+ .expect("module-disabled identity preparation must fail");
+ assert_eq!(error, ModuleCallError::Unavailable);
+ assert!(!error.to_string().contains("fixture-private"));
+}