Skip to content

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

fix(channels): enforce per-callback size limits

Steven Enamakel739ec723befb
diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rs
index d19f467007..fe988f6947 100644
--- a/crates/openhuman-core/src/channels/runtime/startup.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup.rs
@@ -1,7 +1,9 @@
//! Channel startup wiring.
mod chat_workload;
+mod callback;
mod credentials;
+mod delivery_store;
mod prompt;
mod relay;
mod start_channels;
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
index 41df3940e6..9752cdbf32 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
@@ -6,7 +6,6 @@ use crate::channels::runtime::dispatch::RuntimeChannelMessage;
use crate::config::Config;
use std::sync::{Arc, OnceLock, Weak};
use tinybus::{Error, Result};
-use tinychannels_bus::names::{HOST_BUS_NAME, host_methods};
use tinychannels_bus::{
ChannelBackendRequest, ChannelBackendResult, DeliveryQueueEntry, DeliveryTerminalResult,
HostEventPublication, HostTranscriptionRequest, HostTranscriptionResult,
@@ -14,6 +13,8 @@ use tinychannels_bus::{
use tokio::sync::mpsc;
const MAX_CALLBACK_BYTES: usize = 128 * 1024;
+const MAX_TRANSCRIPTION_BYTES: usize = 12 * 1024 * 1024;
+const MAX_CONTROLLER_BYTES: usize = 1024 * 1024;
/// Callbacks capture one immutable host config and a weak runtime context.
/// The weak reference avoids a cycle from runtime context -> module channel ->
@@ -177,12 +178,19 @@ impl ChannelHostCallbacks {
&self,
request: HostTranscriptionRequest,
) -> Result<HostTranscriptionResult> {
- Self::validate_callback_size(&request)?;
+ if serde_json::to_vec(&request).map_or(true, |bytes| bytes.len() > MAX_TRANSCRIPTION_BYTES) {
+ return Err(Error::failed("transcription callback exceeds its limit"));
+ }
use tinychannels::host::Transcriber as _;
crate::channels::host::VoiceTranscriber {
config: Arc::clone(&self.config),
}
- .transcribe(request)
+ .transcribe(tinychannels::host::TranscriptionRequest {
+ audio_base64: request.audio_base64,
+ mime_type: request.mime_type,
+ file_name: request.file_name,
+ language: request.language,
+ })
.await
.map(|result| HostTranscriptionResult {
text: result.text,
@@ -205,7 +213,9 @@ impl ChannelHostCallbacks {
&self,
request: ChannelBackendRequest,
) -> Result<ChannelBackendResult> {
- Self::validate_callback_size(&request)?;
+ if serde_json::to_vec(&request).map_or(true, |bytes| bytes.len() > MAX_CONTROLLER_BYTES) {
+ return Err(Error::failed("controller callback exceeds its limit"));
+ }
match request {
ChannelBackendRequest::RemoteControl(request) => {
crate::channels::host::remote_control::dispatch_callback(
@@ -227,7 +237,3 @@ impl ChannelHostCallbacks {
}
}
}
-
-pub(super) fn interface_name() -> &'static str {
- HOST_BUS_NAME
-}