Skip to content

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

fix(learning): keep key-prefix fallback for classless facet rows\n\nReview follow-up (#6077): ProfileFacet.class is Option; a facet can carry a\ncanonical key (style/verbosity) with class: None, and other paths derive the\nclass from the key when absent. Dropping the key-prefix arm entirely hid such\nrows. Restore the fallback ONLY when the class column is None:\n class == Some(cls) || (class.is_none() && key.starts_with("cls/"))\nExplicit class stays authoritative so the #6077 leak stays closed (a row with\nclass == Some(other) still can't match via key prefix). Applied to both the\nschema handler and the tool mirror; classless-row regression test added.\n

shanu0d3cdff204b1
diff --git a/src/openhuman/agent/learning/cache_tests.rs b/src/openhuman/agent/learning/cache_tests.rs
index 4057143106..23396e34ab 100644
--- a/src/openhuman/agent/learning/cache_tests.rs
+++ b/src/openhuman/agent/learning/cache_tests.rs
@@ -156,6 +156,56 @@ async fn class_filter_matches_column_not_key_prefix() {
);
}
+// ── classless rows fall back to the key prefix (#6104) ────────────────────────
+//
+// `class` is `Option`: a facet can carry a canonical key like `style/verbosity`
+// with `class: None`. The column-only filter that #6077 introduced hid such
+// rows entirely. `list_facets` therefore keeps the class column authoritative
+// but falls back to the key prefix **only when the column is absent** — the
+// same predicate both `handle_list_facets` and `LearningListFacetsTool` apply.
+// This proves the fallback restores a legitimate classless row without
+// reopening the leak: the row is returned for its own class and for no other.
+#[tokio::test]
+async fn class_filter_falls_back_to_key_prefix_for_classless_rows() {
+ let cache = make_cache();
+
+ // A facet whose class column is absent but whose canonical key names the
+ // class. `stub_facet` already defaults `class` to `None`.
+ let classless = stub_facet("f1", "style/verbosity", "terse", FacetState::Active, 1.8);
+ assert!(
+ classless.class.is_none(),
+ "precondition: the row under test has no class column"
+ );
+ cache.upsert(&classless).await.unwrap();
+
+ // The exact predicate list_facets applies (both the schema handler and the
+ // tool mirror): class column authoritative, key-prefix fallback only when
+ // the column is None.
+ let all = cache.list_all().await.unwrap();
+ let matched = |cls: &str| -> Vec<&str> {
+ all.iter()
+ .filter(|f| f.state == FacetState::Active)
+ .filter(|f| {
+ f.class.as_deref() == Some(cls)
+ || (f.class.is_none() && f.key.starts_with(&format!("{cls}/")))
+ })
+ .map(|f| f.key.as_str())
+ .collect()
+ };
+
+ // Included under its own class via the key-prefix fallback…
+ assert_eq!(
+ matched("style"),
+ vec!["style/verbosity"],
+ "a classless row must be matched by the class its key prefix names"
+ );
+ // …and never leaks into a different class.
+ assert!(
+ matched("goal").is_empty(),
+ "the key-prefix fallback must not match a different class"
+ );
+}
+
// ── set_user_state_pinned_persists ────────────────────────────────────────────
#[tokio::test]
diff --git a/src/openhuman/agent/learning/schemas_part_02.rs b/src/openhuman/agent/learning/schemas_part_02.rs
index 0a10ee9898..8d2e86a233 100644
--- a/src/openhuman/agent/learning/schemas_part_02.rs
+++ b/src/openhuman/agent/learning/schemas_part_02.rs
@@ -1,4 +1,3 @@
-
// ── list_facets ───────────────────────────────────────────────────────────────
fn handle_list_facets(params: Map<String, Value>) -> ControllerFuture {
@@ -34,11 +33,19 @@ fn handle_list_facets(params: Map<String, Value>) -> ControllerFuture {
f.state == FacetState::Active || f.state == FacetState::Provisional
})
.filter(|f| {
- // Filter on the class column only — it is always derived from
- // the key prefix, so the old `|| key.starts_with(...)` arm was
- // redundant.
+ // Match on the class column when it is set — that stays
+ // authoritative, so a row explicitly tagged with another class
+ // can never match `cls` via its key prefix (the #6077 leak
+ // stays closed). A row with no class column falls back to its
+ // key prefix, which is where a canonical key like
+ // `style/verbosity` carries the class the column omits — the
+ // behaviour the dropped `|| key.starts_with(...)` arm provided
+ // for legitimate classless rows.
match &class_filter {
- Some(cls) => f.class.as_deref() == Some(cls.as_str()),
+ Some(cls) => {
+ f.class.as_deref() == Some(cls.as_str())
+ || (f.class.is_none() && f.key.starts_with(&format!("{cls}/")))
+ }
None => true,
}
})
diff --git a/src/openhuman/agent/learning/tools.rs b/src/openhuman/agent/learning/tools.rs
index 7792109b5e..b8bfc29c62 100644
--- a/src/openhuman/agent/learning/tools.rs
+++ b/src/openhuman/agent/learning/tools.rs
@@ -110,10 +110,18 @@ impl Tool for LearningListFacetsTool {
let facets: Vec<serde_json::Value> = all
.iter()
.filter(|f| f.state == FacetState::Active || f.state == FacetState::Provisional)
- // Filter on the class column only — it is always derived from the key
- // prefix, so the old `|| key.starts_with(...)` arm was redundant.
+ // Match on the class column when it is set — that stays
+ // authoritative, so a row explicitly tagged with another class can
+ // never match `cls` via its key prefix (the #6077 leak stays
+ // closed). A row with no class column falls back to its key prefix,
+ // where a canonical key like `style/verbosity` carries the class the
+ // column omits — the behaviour the dropped `|| key.starts_with(...)`
+ // arm provided for legitimate classless rows.
.filter(|f| match &class_filter {
- Some(cls) => f.class.as_deref() == Some(cls.as_str()),
+ Some(cls) => {
+ f.class.as_deref() == Some(cls.as_str())
+ || (f.class.is_none() && f.key.starts_with(&format!("{cls}/")))
+ }
None => true,
})
.map(facet_to_json)