Skip to content

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

test(memory): cover the refused-turn paths of a resumed pre_turn

Ghost Scripterefcb554ae323
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks.rs b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
index 39f946d8b6..0d666341ec 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
@@ -220,48 +220,51 @@ pub async fn pre_turn(
// The first turn after a compaction gets one pack that leads with the
// thread's earlier turns, under the turn's own budget and dedupe.
let resumed = recall && input.resumed_after_compaction;
- let turn = if logging {
- let mut pre = PreTurn::new(&input.thread_id, input.turn_index, &input.user_text);
- pre.in_prompt_from = input.in_prompt_from;
- pre.at = Some(input.at);
- let context = if resumed {
- memory.pre_turn_resumed(pre).await
- } else {
- memory.pre_turn(pre).await
- };
- match context {
- Ok(context) => {
- if let Some(error) = &context.log_error {
- tracing::warn!(
- thread_id = %input.thread_id,
- error = %error,
- "[memory:hooks] user turn not logged"
- );
+ let turn = async {
+ if logging {
+ let mut pre = PreTurn::new(&input.thread_id, input.turn_index, &input.user_text);
+ pre.in_prompt_from = input.in_prompt_from;
+ pre.at = Some(input.at);
+ let context = if resumed {
+ memory.pre_turn_resumed(pre).await
+ } else {
+ memory.pre_turn(pre).await
+ };
+ match context {
+ Ok(context) => {
+ if let Some(error) = &context.log_error {
+ tracing::warn!(
+ thread_id = %input.thread_id,
+ error = %error,
+ "[memory:hooks] user turn not logged"
+ );
+ }
+ Ok(context.pack)
+ }
+ Err(error) => {
+ tracing::warn!(%error, "[memory:hooks] pre_turn refused");
+ Err(MemoryError::from(error))
}
- Ok(context.pack)
- }
- Err(error) => {
- tracing::warn!(%error, "[memory:hooks] pre_turn refused");
- Err(MemoryError::from(error))
}
- }
- } else if resumed {
- memory
- .start_session(SessionStart {
- thread_id: Some(input.thread_id.clone()),
- focus: Some(input.user_text.clone()),
- })
- .await
- .map_err(|error| {
+ } else if resumed {
+ memory
+ .start_session(SessionStart {
+ thread_id: Some(input.thread_id.clone()),
+ focus: Some(input.user_text.clone()),
+ })
+ .await
+ .map_err(|error| {
+ tracing::warn!(%error, "[memory:hooks] recall failed");
+ MemoryError::from(error)
+ })
+ } else {
+ memory.recall(&input.user_text).await.map_err(|error| {
tracing::warn!(%error, "[memory:hooks] recall failed");
MemoryError::from(error)
})
- } else {
- memory.recall(&input.user_text).await.map_err(|error| {
- tracing::warn!(%error, "[memory:hooks] recall failed");
- MemoryError::from(error)
- })
- };
+ }
+ }
+ .await;
if !recall {
return None;
}
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
index 8d358bb0e1..9a5ee99b03 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
@@ -479,3 +479,29 @@ async fn a_resumed_session_without_logging_still_opens_with_the_thread() {
assert!(pack.markdown.contains("Alfama hotel"), "{}", pack.markdown);
assert!(repeated_lines(&pack.markdown).is_empty());
}
+
+#[tokio::test]
+async fn a_blank_turn_is_refused_without_a_pack_with_or_without_logging() {
+ let tmp = tempfile::tempdir().unwrap();
+ let mut config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ let identity = MemoryIdentity::agent("orchestrator").resolve(&config);
+ assert!(pre_turn(&config, &identity, input("t-blank", 0, " "))
+ .await
+ .is_none());
+ assert!(
+ stored(&engine, MetaFilter::kinds([ItemKind::Conversation]))
+ .await
+ .is_empty(),
+ "a refused turn logs nothing"
+ );
+
+ config.memory.conversations.enabled = false;
+ let reader = MemoryIdentity::agent("orchestrator").resolve(&config);
+ assert!(pre_turn(&config, &reader, input("t-blank", 2, " "))
+ .await
+ .is_none());
+ let mut resumed = input(" ", 4, "where were we?");
+ resumed.resumed_after_compaction = true;
+ assert!(pre_turn(&config, &reader, resumed).await.is_none());
+}