Skip to content

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

fix(tinyhumans): keep the id guards on context-bearing Delete and Typing

M3gA-Mind84e45601f5e0
diff --git a/crates/openhuman-tinyhumans/src/channels/delivery.rs b/crates/openhuman-tinyhumans/src/channels/delivery.rs
index e7a426e3a5..586ebb5cad 100644
--- a/crates/openhuman-tinyhumans/src/channels/delivery.rs
+++ b/crates/openhuman-tinyhumans/src/channels/delivery.rs
@@ -8,7 +8,6 @@ use openhuman_embed::__host::channel_callback::ChannelCallbackCtx;
use openhuman_embed::__host::security::credentials::session_support::{
get_session_token, is_local_session_token, BackendCredential,
};
-use reqwest::Method;
use serde_json::{json, Map, Value};
use tinychannels_bus::module_progressive::{
ProgressiveTransportRequest, ProgressiveTransportResult,
@@ -243,22 +242,10 @@ async fn send(
receipt,
None,
);
- if context.is_empty() {
- client
- .send_channel_delete(&channel, &message_id, credential.clone())
- .await
- } else {
- let channel = urlencoding::encode(channel.trim().trim_matches('/'));
- let message_id = urlencoding::encode(&message_id);
- client
- .authed_json(
- credential.clone(),
- Method::DELETE,
- &format!("channels/{channel}/messages/{message_id}"),
- Some(json!({"transportContext": context})),
- )
- .await
- }
+ let body = (!context.is_empty()).then(|| json!({"transportContext": context}));
+ client
+ .send_channel_delete(&channel, &message_id, credential.clone(), body)
+ .await
}
ProgressiveTransportRequest::Typing {
channel,
@@ -268,21 +255,14 @@ async fn send(
} => {
let context =
transport_context(turn_id, channel_ref, conversation, None, None, None, None);
- if context.is_empty() {
- client
- .send_channel_typing(&channel, credential.clone())
- .await
+ let body = if context.is_empty() {
+ json!({})
} else {
- let channel = urlencoding::encode(channel.trim().trim_matches('/'));
- client
- .authed_json(
- credential.clone(),
- Method::POST,
- &format!("channels/{channel}/typing"),
- Some(json!({"transportContext": context})),
- )
- .await
- }
+ json!({"transportContext": context})
+ };
+ client
+ .send_channel_typing(&channel, credential.clone(), body)
+ .await
}
};
match result {
diff --git a/crates/openhuman-tinyhumans/src/channels/mod_tests.rs b/crates/openhuman-tinyhumans/src/channels/mod_tests.rs
index 5dccfe82a5..dfeb619e94 100644
--- a/crates/openhuman-tinyhumans/src/channels/mod_tests.rs
+++ b/crates/openhuman-tinyhumans/src/channels/mod_tests.rs
@@ -366,3 +366,44 @@ async fn requests_the_callback_does_not_serve_are_refused() {
.await;
assert!(refused.is_err());
}
+
+#[tokio::test]
+async fn a_context_bearing_delete_or_typing_keeps_the_empty_id_guards() {
+ let tmp = tempfile::tempdir().unwrap();
+ let server = MockServer::start().await;
+ Mock::given(wiremock::matchers::any())
+ .respond_with(
+ ResponseTemplate::new(200).set_body_json(json!({"success": true, "data": {}})),
+ )
+ .mount(&server)
+ .await;
+ let turn = || Some("turn-1".to_string());
+ for request in [
+ ProgressiveTransportRequest::Delete {
+ channel: "telegram".into(),
+ turn_id: turn(),
+ channel_ref: None,
+ conversation: None,
+ message_id: String::new(),
+ receipt: None,
+ },
+ ProgressiveTransportRequest::Typing {
+ channel: " / ".into(),
+ turn_id: turn(),
+ channel_ref: None,
+ conversation: None,
+ },
+ ] {
+ let answer = serve(
+ ctx(test_support::signed_in(&tmp, &server.uri()), None),
+ ChannelBackendRequest::ProgressiveTransport(Box::new(request)),
+ )
+ .await
+ .unwrap();
+ assert!(matches!(
+ answer,
+ ChannelBackendResult::ProgressiveTransport(ProgressiveTransportResult::Failed)
+ ));
+ }
+ assert!(server.received_requests().await.unwrap().is_empty());
+}
diff --git a/crates/openhuman-tinyhumans/src/client/backend_channel_tests.rs b/crates/openhuman-tinyhumans/src/client/backend_channel_tests.rs
index a3721492a9..0226b4ffcd 100644
--- a/crates/openhuman-tinyhumans/src/client/backend_channel_tests.rs
+++ b/crates/openhuman-tinyhumans/src/client/backend_channel_tests.rs
@@ -289,7 +289,7 @@ async fn sdk_backed_channel_typing_surfaces_unauthorized_on_401() {
let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
- .send_channel_typing("telegram", "mock-jwt")
+ .send_channel_typing("telegram", "mock-jwt", json!({}))
.await
.unwrap_err();
@@ -387,7 +387,7 @@ async fn message_not_found_becomes_message_not_found() {
message_id: "abc".into(),
});
let err = client
- .send_channel_delete("discord", "abc", "mock-jwt")
+ .send_channel_delete("discord", "abc", "mock-jwt", None)
.await
.unwrap_err();
let typed = err.downcast_ref::<HostedApiError>().unwrap();
diff --git a/crates/openhuman-tinyhumans/src/client/channel.rs b/crates/openhuman-tinyhumans/src/client/channel.rs
index 142cbb0f0c..5e1b8df625 100644
--- a/crates/openhuman-tinyhumans/src/client/channel.rs
+++ b/crates/openhuman-tinyhumans/src/client/channel.rs
@@ -4,7 +4,7 @@
use anyhow::Result;
use reqwest::Method;
-use serde_json::{json, Value};
+use serde_json::Value;
use openhuman_embed::__host::security::credentials::session_support::BackendCredential;
@@ -43,6 +43,7 @@ impl BackendClient {
&self,
channel: &str,
credential: impl Into<BackendCredential>,
+ body: Value,
) -> Result<Value> {
let channel = channel.trim().trim_matches('/');
anyhow::ensure!(!channel.is_empty(), "channel is required");
@@ -51,7 +52,7 @@ impl BackendClient {
credential,
Method::POST,
&format!("channels/{encoded}/typing"),
- Some(json!({})),
+ Some(body),
)
.await
}
@@ -103,6 +104,7 @@ impl BackendClient {
channel: &str,
message_id: &str,
credential: impl Into<BackendCredential>,
+ body: Option<Value>,
) -> Result<Value> {
let channel = channel.trim().trim_matches('/');
anyhow::ensure!(!channel.is_empty(), "channel is required");
@@ -113,7 +115,7 @@ impl BackendClient {
credential,
Method::DELETE,
&format!("channels/{encoded_channel}/messages/{encoded_id}"),
- None,
+ body,
)
.await
}
diff --git a/crates/openhuman-tinyhumans/src/transport/transport_tests.rs b/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
index e58c81f9ea..0b3834e695 100644
--- a/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
+++ b/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
@@ -365,7 +365,7 @@ async fn core_channel_routes_recover_from_the_transports_typed_404s() {
);
let err = client
- .send_channel_delete("telegram", "1103", "jwt")
+ .send_channel_delete("telegram", "1103", "jwt", None)
.await
.unwrap_err();
assert!(