Skip to content

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

fix(memory): build the embed facade's params; anchor the date-hint deadline

M3gA-Mindc1be33beb01c
diff --git a/crates/openhuman-core/src/memory/lifecycle/date_hint.rs b/crates/openhuman-core/src/memory/lifecycle/date_hint.rs
index e572a5514d..59f7c58901 100644
--- a/crates/openhuman-core/src/memory/lifecycle/date_hint.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/date_hint.rs
@@ -19,6 +19,10 @@ const INSTRUCTION: &str = "Return the calendar date range (local dates) that the
/// The days `user_text` is about, in `zone`, from the user's chat model.
/// `None` when it names no time, or the call fails or answers nonsense.
+///
+/// Not bounded here: the caller owns the deadline (`hooks::pre_turn` wraps
+/// it in the turn's pre-turn timeout), as tinymemory's `pre_turn_dated`
+/// requires of its hint.
pub async fn extract(config: &Config, user_text: &str, zone: &str) -> Option<TimeHint> {
let (model, model_id) =
match crate::inference::provider::create_chat_model_with_model_id("chat", config, 0.0) {
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks.rs b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
index 4a10a28e72..affafe1d73 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks.rs
@@ -217,15 +217,17 @@ pub async fn pre_turn(
let agent_id = identity.agent_id.clone();
let started = std::time::Instant::now();
let timeout = Duration::from_millis(config.memory.recall.pre_turn_timeout_ms.max(1));
- // Answers by the deadline less a margin, so the pack is still ranked and
- // returned before the turn stops waiting for it.
+ // Runs beside the turn log and the reads (tinymemory joins all three) and
+ // answers by the turn's own deadline less a margin, counted from now, so
+ // the pack is still ranked and returned before the turn stops waiting.
let date_hint = (recall && logging && config.memory.recall.date_hint).then(|| {
let config = config.clone();
let text = input.user_text.clone();
- let deadline = timeout.saturating_sub(Duration::from_millis(100));
+ let deadline =
+ tokio::time::Instant::now() + timeout.saturating_sub(Duration::from_millis(100));
async move {
let zone = config.time_zone();
- tokio::time::timeout(deadline, super::date_hint::extract(&config, &text, &zone))
+ tokio::time::timeout_at(deadline, super::date_hint::extract(&config, &text, &zone))
.await
.ok()
.flatten()
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
index 9a5ee99b03..1ec426b72b 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
@@ -505,3 +505,55 @@ async fn a_blank_turn_is_refused_without_a_pack_with_or_without_logging() {
resumed.resumed_after_compaction = true;
assert!(pre_turn(&config, &reader, resumed).await.is_none());
}
+
+/// With `date_hint` on, the turn's text goes to the chat model with the date
+/// line in the user's zone, and the pack comes back whether the model names a
+/// date or answers nonsense: the hint only reorders, it never costs the pack.
+#[tokio::test]
+async fn a_date_hint_asks_the_model_in_the_users_zone_and_never_costs_the_pack() {
+ for answer in ["{\"from\":\"2026-10-03\",\"to\":\"2026-10-03\"}", "no idea"] {
+ let model = std::sync::Arc::new(tinyagents_harness::testkit::ScriptedModel::new(vec![
+ tinyinference_llm::model::ModelResponse::assistant(answer),
+ ]));
+ let _override = crate::inference::provider::factory::test_provider_override::install_model(
+ model.clone(),
+ );
+ let tmp = tempfile::tempdir().unwrap();
+ let mut config = config_in(&tmp);
+ config.memory.recall.date_hint = true;
+ config.user_timezone = Some("Pacific/Chatham".into());
+ let engine = bind_reference(&config);
+ engine
+ .store(StoreItem::learning(
+ "The user's favourite colour is teal",
+ LearningKind::Preference,
+ 0.9,
+ MemoryMeta::default(),
+ ))
+ .await
+ .unwrap();
+ let identity = MemoryIdentity::agent("orchestrator").resolve(&config);
+
+ let pack = pre_turn(
+ &config,
+ &identity,
+ input("t-dated", 0, "what colour did I pick last Saturday?"),
+ )
+ .await
+ .expect("a pack");
+ assert!(
+ pack.markdown.contains("teal"),
+ "{answer}: {}",
+ pack.markdown
+ );
+
+ let requests = model.requests();
+ assert_eq!(requests.len(), 1, "{answer}: one extraction call per turn");
+ let system = requests[0].messages[0].text();
+ assert!(system.contains(" Pacific/Chatham ("), "{system}");
+ assert!(
+ requests[0].messages[1].text().contains("last Saturday"),
+ "the turn's own words are what is dated"
+ );
+ }
+}
diff --git a/crates/openhuman-embed/src/memory.rs b/crates/openhuman-embed/src/memory.rs
index 35f8bb0782..d9a0df37c1 100644
--- a/crates/openhuman-embed/src/memory.rs
+++ b/crates/openhuman-embed/src/memory.rs
@@ -218,6 +218,7 @@ impl Memory {
ops::recall(
&self.config,
types::RecallParams {
+ refers_to: None,
question: question.into(),
filter: Some(self.reading(agent_id)?),
limit,
@@ -236,6 +237,7 @@ impl Memory {
ops::fetch(
&self.config,
types::FetchParams {
+ refers_to: None,
query: query.into(),
mode: None,
filter: Some(MetaFilter {