Skip to content

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

fix(learning): reject a facet class name containing a slash\n\nparse_facet_class_name delegated to class_from_key, which matches on the first\n/-segment, so "style/" was accepted and then composed an unmatchable key —\nreintroducing the silent-empty behaviour the fix removes. Reject any class name\ncontaining a slash up front.\n

shanu1292ad9a4772
diff --git a/src/openhuman/agent/learning/cache.rs b/src/openhuman/agent/learning/cache.rs
index b6d4b589fe..3027c4b0d4 100644
--- a/src/openhuman/agent/learning/cache.rs
+++ b/src/openhuman/agent/learning/cache.rs
@@ -155,11 +155,19 @@ pub fn class_from_key(key: &str) -> Option<FacetClass> {
/// own prefix and an unknown name is rejected with a caller-facing error rather
/// than silently composing a key no facet can ever carry.
pub(crate) fn parse_facet_class_name(class: &str) -> Result<FacetClass, String> {
- class_from_key(class).ok_or_else(|| {
+ // A taxonomy name never contains a `/`. Reject one up front so a value like
+ // `"style/"` (which `class_from_key` would accept via its first segment,
+ // then compose into a key no facet can carry) fails loudly instead of
+ // reintroducing the silent-empty behaviour this fix removes.
+ let invalid = || {
format!(
"invalid class `{class}` (expected one of style, identity, tooling, veto, goal, channel)"
)
- })
+ };
+ if class.contains('/') {
+ return Err(invalid());
+ }
+ class_from_key(class).ok_or_else(invalid)
}
/// Delete every non-`Pinned` facet, returning `(deleted, pinned_preserved)`.
diff --git a/src/openhuman/agent/learning/cache_tests.rs b/src/openhuman/agent/learning/cache_tests.rs
index c951b42135..4057143106 100644
--- a/src/openhuman/agent/learning/cache_tests.rs
+++ b/src/openhuman/agent/learning/cache_tests.rs
@@ -104,6 +104,16 @@ fn parse_facet_class_name_rejects_unknown_class() {
);
}
+#[test]
+fn parse_facet_class_name_rejects_a_name_with_a_slash() {
+ // `"style/"` shares a first `/`-segment with a real class, so a bare
+ // `class_from_key` would accept it and then compose an unmatchable key —
+ // the silent-empty behaviour #6077 removes. The slash guard rejects it.
+ let err =
+ parse_facet_class_name("style/").expect_err("a slash in a class name must be rejected");
+ assert!(err.contains("invalid class `style/`"), "got: {err}");
+}
+
// ── class filter is column-only (#6077) ───────────────────────────────────────
//
// `list_facets` filters on the `class` column alone; the redundant