Skip to content

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

fix(learning): forget_facet must not log a drop that never happened

M3gA-Mind0d9ab00fd9dd
diff --git a/src/openhuman/agent/learning/schemas_part_02.rs b/src/openhuman/agent/learning/schemas_part_02.rs
index cb82ae0927..ad7d79a363 100644
--- a/src/openhuman/agent/learning/schemas_part_02.rs
+++ b/src/openhuman/agent/learning/schemas_part_02.rs
@@ -254,6 +254,21 @@ fn handle_unpin_facet(params: Map<String, Value>) -> ControllerFuture {
// ── forget_facet ──────────────────────────────────────────────────────────────
+/// The log line `learning.forget_facet` emits, given whether a row was actually
+/// written.
+///
+/// Split out so the claim can be unit-tested without a cache: the defect this
+/// replaces built the "state=dropped user_state=forgotten" line unconditionally,
+/// *before* the read told it whether there was anything to drop, so an absent key
+/// produced a log asserting a state change that never happened (#6108).
+fn forget_facet_log(full_key: &str, dropped: bool) -> Vec<String> {
+ vec![if dropped {
+ format!("learning.forget_facet: key={full_key} state=dropped user_state=forgotten")
+ } else {
+ format!("learning.forget_facet: key={full_key} not present — no change")
+ }]
+}
+
fn handle_forget_facet(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
use tinymemory_api::provider::{FacetState, UserState};
@@ -281,7 +296,12 @@ fn handle_forget_facet(params: Map<String, Value>) -> ControllerFuture {
.await
.map_err(|e| format!("get failed: {e:#}"))?;
- let facet_json = if let Some(mut f) = facet_before {
+ // Absent is not an error: forgetting is idempotent, and erroring would
+ // leak whether the facet existed — the wrong direction for a privacy
+ // operation. The agent tool (`tools.rs`) has always behaved this way;
+ // what was wrong here was the *log*, built before the branch was known,
+ // so a typo'd key produced a line claiming a row had been dropped.
+ let (facet_json, dropped) = if let Some(mut f) = facet_before {
// Mark Forgotten + Dropped so it doesn't resurface.
f.user_state = UserState::Forgotten;
f.state = FacetState::Dropped;
@@ -294,14 +314,12 @@ fn handle_forget_facet(params: Map<String, Value>) -> ControllerFuture {
.await
.map_err(|e| format!("re-read failed: {e:#}"))?
.unwrap_or(f);
- facet_to_json(&updated)
+ (facet_to_json(&updated), true)
} else {
- serde_json::Value::Null
+ (serde_json::Value::Null, false)
};
- let log = vec![format!(
- "learning.forget_facet: key={fk} state=dropped user_state=forgotten"
- )];
+ let log = forget_facet_log(&fk, dropped);
let payload = serde_json::json!({ "facet": facet_json });
RpcOutcome::new(payload, log).into_cli_compatible_json()
})
diff --git a/src/openhuman/agent/learning/schemas_tests.rs b/src/openhuman/agent/learning/schemas_tests.rs
index 0989af68d1..6ddd7625d2 100644
--- a/src/openhuman/agent/learning/schemas_tests.rs
+++ b/src/openhuman/agent/learning/schemas_tests.rs
@@ -192,3 +192,44 @@ async fn class_taking_handlers_keep_presence_check_before_value_check() {
.expect_err("missing class must error");
assert!(err.contains("missing required `class`"), "got: {err}");
}
+
+// ── #6108: the forget_facet log must describe what actually happened ─────────
+
+/// The line was previously built unconditionally, before the read that decides
+/// whether there is anything to drop. A typo'd key therefore produced a log
+/// asserting `state=dropped user_state=forgotten` for a row that was never
+/// touched. The RPC contract itself is unchanged and deliberately idempotent —
+/// `{"facet": null}`, no error — so the log is the only thing that can tell the
+/// two outcomes apart.
+#[test]
+fn forget_facet_log_claims_a_drop_only_when_a_row_was_written() {
+ let dropped = forget_facet_log("style/observed_key", true);
+ assert_eq!(dropped.len(), 1);
+ assert!(
+ dropped[0].contains("state=dropped") && dropped[0].contains("user_state=forgotten"),
+ "a real drop must still record the state change: {dropped:?}"
+ );
+ assert!(
+ dropped[0].contains("style/observed_key"),
+ "the log must name the key it dropped: {dropped:?}"
+ );
+}
+
+#[test]
+fn forget_facet_log_does_not_claim_a_drop_for_an_absent_key() {
+ let absent = forget_facet_log("style/never_observed", false);
+ assert_eq!(absent.len(), 1);
+ assert!(
+ !absent[0].contains("state=dropped"),
+ "an absent key must not be logged as a state change — this is the #6108 \
+ defect, where the claim was made before the row was read: {absent:?}"
+ );
+ assert!(
+ !absent[0].contains("user_state=forgotten"),
+ "nor may it claim the user forgot something that was never there: {absent:?}"
+ );
+ assert!(
+ absent[0].contains("style/never_observed") && absent[0].contains("not present"),
+ "it must still name the key and say plainly that nothing changed: {absent:?}"
+ );
+}