Skip to content

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

fix(memory): time a free-period answer from its arrival; log no error text

M3gA-Mind1577fb033936
diff --git a/crates/openhuman-core/src/memory/billing.rs b/crates/openhuman-core/src/memory/billing.rs
index 752d660f91..757725f082 100644
--- a/crates/openhuman-core/src/memory/billing.rs
+++ b/crates/openhuman-core/src/memory/billing.rs
@@ -130,12 +130,15 @@ where
}
let active = match fetch().await {
Ok(active) => active,
- Err(error) => {
- tracing::debug!(%error, "[memory:billing] free period unknown; treating as not free");
+ Err(_) => {
+ // The error text can carry the backend's response; it is not
+ // logged.
+ tracing::debug!("[memory:billing] free period unknown; treating as not free");
false
}
};
- answers.insert(key.to_string(), (now, active));
+ // The answer's age starts when it arrives, not when it was asked for.
+ answers.insert(key.to_string(), (clock(), active));
active
}
diff --git a/crates/openhuman-core/src/memory/billing_tests.rs b/crates/openhuman-core/src/memory/billing_tests.rs
index 0bec73cb88..2c9ca0618c 100644
--- a/crates/openhuman-core/src/memory/billing_tests.rs
+++ b/crates/openhuman-core/src/memory/billing_tests.rs
@@ -275,3 +275,32 @@ fn the_cache_key_digest_is_the_full_sha256() {
assert_eq!(key.len(), 64, "{key}");
assert_ne!(key, digest("th_account_b"));
}
+
+#[tokio::test]
+async fn an_answer_is_timed_from_when_it_arrives() {
+ let cache = Answer::new();
+ let base = Instant::now();
+ let calls = AtomicUsize::new(0);
+ let ticks = AtomicUsize::new(0);
+ // The fetch takes longer than the TTL: asked at `base`, answered at
+ // `base + 90s`.
+ let clock = || {
+ if ticks.fetch_add(1, Ordering::SeqCst) == 0 {
+ base
+ } else {
+ base + Duration::from_secs(90)
+ }
+ };
+ let ask = || {
+ calls.fetch_add(1, Ordering::SeqCst);
+ async { Ok(true) }
+ };
+ assert!(active_with_cache(&cache, KEY, CACHE_TTL, clock, ask).await);
+ let later = || base + Duration::from_secs(120);
+ assert!(active_with_cache(&cache, KEY, CACHE_TTL, later, ask).await);
+ assert_eq!(
+ calls.load(Ordering::SeqCst),
+ 1,
+ "still fresh 30s after it arrived"
+ );
+}