Skip to content

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

fix(channels): refuse relay turns when thread history cannot be loaded

Steven Enamakel4049e60441c5
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs
index 70550794c3..faf8701780 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@ -3,15 +3,15 @@
use std::collections::HashMap;
use std::sync::Arc;
-use serde_json::{Value, json};
+use serde_json::{json, Value};
use super::channel::RelayChannel;
use super::params::RelayInboundParams;
use super::store::{self, Recorded};
use crate::channels::context::MAX_CHANNEL_HISTORY;
use crate::channels::runtime::{
- PromptToolDescs, build_channel_turn_parts, prepare_runtime_limits,
- process_channel_runtime_message, runtime_context,
+ build_channel_turn_parts, prepare_runtime_limits, process_channel_runtime_message,
+ runtime_context, PromptToolDescs,
};
use crate::config::Config;
use crate::core::Outcome;
@@ -241,11 +241,29 @@ pub(crate) async fn run_relay_turn(
_ => unreachable!("prior_turns only returns user and assistant rows"),
})
.collect(),
- Err(error) => tracing::warn!(
- thread_id = %thread_id,
- %error,
- "[channels::relay] could not read the thread's history; running without it"
- ),
+ Err(error) => {
+ tracing::warn!(
+ thread_id = %thread_id,
+ %error,
+ "[channels::relay] could not read the thread's history; refusing to start a session without it"
+ );
+ let reply =
+ "⚠️ This chat's history could not be loaded. Please send your message again.";
+ let _ = tinychannels_runtime::Channel::send(
+ channel.as_ref(),
+ &crate::channels::SendMessage::new(reply, &params.chat_id),
+ )
+ .await;
+ record(
+ &dispatch_ctx,
+ &workspace_dir,
+ &params,
+ &thread_id,
+ &channel.sent(),
+ )
+ .await;
+ return channel.sent();
+ }
};
tracing::debug!(
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
index fc212faae8..5c3d41b7a1 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
@@ -1,6 +1,6 @@
use super::super::channel::CHANNEL_OUTBOUND_EVENT;
use super::*;
-use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, mock_agent_run_turn};
+use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};
use crate::agent::turn_origin::AgentTurnOrigin;
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
use std::sync::Mutex;
@@ -211,16 +211,12 @@ async fn a_relayed_turn_runs_as_an_external_channel_and_keeps_its_thread() {
}
}
assert_eq!(outbound.len(), 2, "one channel_outbound per reply");
- assert!(
- outbound
- .iter()
- .all(|event| event.event_name() == CHANNEL_OUTBOUND_EVENT)
- );
- assert!(
- outbound
- .iter()
- .all(|event| event.context().thread_id == thread)
- );
+ assert!(outbound
+ .iter()
+ .all(|event| event.event_name() == CHANNEL_OUTBOUND_EVENT));
+ assert!(outbound
+ .iter()
+ .all(|event| event.context().thread_id == thread));
assert_eq!(outbound[0].context().request_id, "req-m1");
assert!(matches!(
outbound[0].wire_event(),
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
index 9f0ddb08b4..dbf254e092 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
@@ -1,7 +1,7 @@
//! The orchestrator path: an unbound channel's turn goes over the native bus
//! to the `agent.run_turn` handler, with the orchestrator's tool scoping.
-use crate::agent::bus::{AGENT_RUN_TURN_METHOD, AgentTurnRequest, AgentTurnResponse};
+use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, AGENT_RUN_TURN_METHOD};
use crate::agent::turn_origin::AgentTurnOrigin;
use crate::channels::context::{ChannelRouteSelection, ChannelRuntimeContext};
use crate::core::bus::BUS;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index c2cb7f1154..bb2cb116b4 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -3,10 +3,10 @@
//! delivering the draft/final reply.
use crate::agent::bus::AgentTurnResponse;
-use crate::channels::context::{ChannelRuntimeContext, is_context_window_overflow_error};
-use crate::channels::routes::{
- get_or_create_turn_model_source, get_route_selection, handle_runtime_command_if_needed,
-};
+use crate::channels::context::{is_context_window_overflow_error, ChannelRuntimeContext};
+#[cfg(test)]
+use crate::channels::routes::get_or_create_turn_model_source;
+use crate::channels::routes::{get_route_selection, handle_runtime_command_if_needed};
use crate::channels::{ChannelSendExt, SendMessage};
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
@@ -19,14 +19,14 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::AbortOnDropHandle;
use super::super::helpers::{
- REPLY_LOG_TRUNCATE_CHARS, build_channel_context_block, log_worker_join_result,
- spawn_typing_task,
+ build_channel_context_block, log_worker_join_result, spawn_typing_task,
+ REPLY_LOG_TRUNCATE_CHARS,
};
-use super::super::host_agent::{self, HostChannelTurn, HostRoute, run_host_agent_turn};
-use super::RuntimeChannelMessage;
+use super::super::host_agent::{self, run_host_agent_turn, HostChannelTurn, HostRoute};
use super::approval::{channel_has_approval_surface, try_route_approval_reply};
#[cfg(test)]
use super::bus_turn::dispatch_bus_turn;
+use super::RuntimeChannelMessage;
pub(crate) async fn process_channel_message(
ctx: Arc<ChannelRuntimeContext>,
diff --git a/vendor/tinyagents b/vendor/tinyagents
index 16e066ea95..47a18be4b0 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit 16e066ea955e6bc64643c6bf026781c38fb91dc1
+Subproject commit 47a18be4b026744614e4d3b323bbc2f6fcec9aac