Skip to content

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

docs(agent/experience): add README and tests for experience operations

Steven Enamakel0af6fc976a60
diff --git a/crates/openhuman-core/src/agent/experience/README.md b/crates/openhuman-core/src/agent/experience/README.md
index d143bc15d2..4ffc564da5 100644
--- a/crates/openhuman-core/src/agent/experience/README.md
+++ b/crates/openhuman-core/src/agent/experience/README.md
@@ -75,8 +75,8 @@ Records are stored through the `Memory` trait (no dedicated DB), served by `Driv
## Notes / gotchas
-- Two redaction layers at write time: `capture::build_experience` masks `Bearer …`, `sk-…`, and `token=/password:` pairs with `types::redact_text`; `store::put` then runs the full `memory::safety::sanitize_text` scrubber (private keys, vendor secrets, national-ID / phone / card PII) over the free-text fields.
+- Two redaction layers at write time: `capture::build_experience` masks `Bearer …`, `sk-…`, and `token=/password:` pairs with `types::redact_text`; `store::put` then runs the full `memory::safety::sanitize_text` scrubber (private keys, vendor secrets, national-ID / phone / card PII) over the free-text fields.
- Retrieval scoring is **lexical, not embedding-based**: term sets keep only tokens length > 2, normalized lowercase; score combines tool overlap (weighted highest), tag overlap, query-term overlap over summary+lesson+hints, plus small agent/entrypoint match boosts and a confidence prior. `max_hits == 0` short-circuits to empty. The live-turn path additionally drops hits with no `match_reasons`.
- `render_experience_hits` is hard byte-capped (`max_bytes`) with UTF-8-boundary-safe truncation, so the injected prompt block can't blow the context budget.
- The capture hook is gated by an `enabled` flag passed at construction; when disabled `on_turn_complete` is a no-op, and capture failures only `log::warn!` (never fail the turn).
-- `DriverMemory` wraps the driver, not `MemoryGuard`, on purpose: the guard truncates `store` content at `capture_max_chars`, and truncated base64 does not decode. Its `ops.rs` rustdoc notes it belongs next to `memory::binding` and only sits here because both callers do.
+- `DriverMemory` wraps the driver, not `MemoryGuard`, on purpose: the guard truncates `store` content at `capture_max_chars`, and truncated JSON does not parse. Its `ops.rs` rustdoc notes it belongs next to `memory::binding` and only sits here because both callers do.
diff --git a/crates/openhuman-core/src/agent/experience/ops.rs b/crates/openhuman-core/src/agent/experience/ops.rs
index 0662a2e8ef..c9ca452717 100644
--- a/crates/openhuman-core/src/agent/experience/ops.rs
+++ b/crates/openhuman-core/src/agent/experience/ops.rs
@@ -46,8 +46,8 @@ use std::sync::Arc;
/// `MemoryHooksConfig::default()` sets to **500**. An `AgentExperience` is
/// stored as its serialized JSON, and truncated JSON does not parse, so the
/// record would silently vanish on read. So the pre-#5560 behaviour is
-/// preserved exactly: no policy layer between this store and the driver. The store runs the full scrubber over its own free-text
-/// fields before serialization (`store::redact_experience`), which is what
+/// preserved exactly: no policy layer between this store and the driver. The store runs the full
+/// scrubber over its own free-text fields before serialization (`store::redact_experience`), which is what
/// keeps that safe rather than merely unguarded.
///
/// # Home
diff --git a/crates/openhuman-core/src/agent/experience/store_tests.rs b/crates/openhuman-core/src/agent/experience/store_tests.rs
index 1d2941c482..6dd6fb5233 100644
--- a/crates/openhuman-core/src/agent/experience/store_tests.rs
+++ b/crates/openhuman-core/src/agent/experience/store_tests.rs
@@ -110,3 +110,37 @@ async fn retrieve_ignores_dismissed_records() {
assert!(hits.is_empty());
}
+
+// A Luhn-valid 13-digit epoch-millisecond value: the shape the old strict
+// scrubber rewrote to `[REDACTED_PII_*]` (#5209). The host policy is
+// corroborated since #6855, so the plain JSON must survive it.
+const LUHN_EPOCH_MS: i64 = 1727712000006;
+
+#[tokio::test]
+async fn timestamps_survive_the_host_scrubber_in_the_stored_json() {
+ let (store, memory) = fresh_store();
+ let mut experience = sample_experience("exp_ts", "search docs", vec!["grep"], vec![], 0.5);
+ experience.created_at_ms = LUHN_EPOCH_MS;
+ store.put(experience).await.unwrap();
+
+ let stored = memory
+ .entries
+ .lock()
+ .get(&(AGENT_EXPERIENCE_NAMESPACE.into(), "experience/exp_ts".into()))
+ .map(|entry| entry.content.clone())
+ .expect("stored");
+ assert!(stored.starts_with('{'), "stored as plain JSON: {stored}");
+ let scrubbed = crate::memory::safety::sanitize_text(&stored).value;
+ assert_eq!(scrubbed, stored, "scrubber must leave timestamps alone");
+ let parsed = decode_experience_payload(&scrubbed).unwrap();
+ assert_eq!(parsed.created_at_ms, LUHN_EPOCH_MS);
+}
+
+#[test]
+fn legacy_base64_payload_still_decodes() {
+ let experience = sample_experience("exp_old", "search docs", vec!["grep"], vec![], 0.5);
+ let json = serde_json::to_string(&experience).unwrap();
+ let wrapped = base64::engine::general_purpose::STANDARD.encode(json.as_bytes());
+ assert_eq!(decode_experience_payload(&wrapped).unwrap().id, "exp_old");
+ assert_eq!(decode_experience_payload(&json).unwrap().id, "exp_old");
+}