The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(nous): only fall back to the reachable set when the overlap is empty
Mariano Nicolini04647f15c88a
diff --git a/docs/nous-org-model-policy.md b/docs/nous-org-model-policy.mdindex 942c7985078..7b4027ba72e 100644--- a/docs/nous-org-model-policy.md+++ b/docs/nous-org-model-policy.md@@ -138,13 +138,17 @@ large alphabetical dump of vendor-prefixed models, and swapping it in is theregression `model_switch.py:3070` records.**Do not** treat the policy set as subtract-only either. An allowlist can name-a model the curated manifest has never heard of, and intersecting alone then-empties the picker — strictly worse than an unfiltered list, because the one-model the org may use is the one dropped. When the reachable set is small-enough to be a human-authored allowlist, append what it admits that the-curated list lacks, after the curated entries so their order survives. Bound-it by size: a provider-only policy leaves the whole catalog reachable, and-appending that would bury the curated order.+only models the curated manifest has never heard of, and intersecting alone+then empties the picker — strictly worse than an unfiltered list, because the+models the org may use are the ones dropped. Fall back to the reachable set+itself in exactly that case.++Only when the intersection is empty, and only when the set is small enough to+be an allowlist rather than a whole catalog. A jurisdiction or provider policy+narrows the catalog without emptying the curated overlap; appending its+remainder pushes non-curated alphabetical ids into a picker that shows a+curated order on purpose. A size cap alone does not catch this — a region+filter can leave few enough models to pass it.**Do not** narrow a list on evidence that cannot support it.`nous_policy_allowed_ids()` returns `None` — meaning "leave the list alone" —diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex 4e5f4507a67..e7754fa196c 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -2650,9 +2650,9 @@ def nous_policy_allowed_ids(*, force_refresh: bool = False) -> Optional[set[str]# Above this many reachable models, an allowed set is treated as catalog-wide-# rather than as an allowlist worth enumerating in a picker. NAS caps an-# allowlist at 512, but a set this large is indistinguishable from the full-# catalog for display purposes.+# rather than as an allowlist worth showing in place of an empty picker. NAS+# caps an allowlist at 512, but a set this large is indistinguishable from the+# full catalog for display purposes._NOUS_POLICY_APPEND_MAX = 64@@ -2678,25 +2678,18 @@ def restrict_to_nous_policy(if mid in allowed or mid.split(":", 1)[0] in allowed]- # An allowlist can admit models the curated manifest has never heard of, and- # intersecting alone would then leave the user with nothing to pick at all —- # strictly worse than the unfiltered list. When the reachable set is no- # larger than what would have been shown anyway, it IS the list: append- # whatever it admits that the curated list is missing.+ # An allowlist can admit only models the curated manifest has never heard+ # of, leaving nothing to intersect and an empty picker — strictly worse than+ # the unfiltered list, because the models the org may actually use are the+ # ones dropped. Fall back to the reachable set itself in exactly that case.#- # Bounded by size, which is what separates the two kinds of policy: a model- # allowlist is human-authored and small, while a provider-only policy leaves- # the whole catalog reachable. Appending several hundred alphabetical- # vendor-prefixed ids would bury the curated order — the regression the- # pickers' curated branch exists to avoid. Past the cap the intersection- # stands on its own, and the picker's custom-model entry remains the way to- # reach anything it omits.- if len(allowed) <= _NOUS_POLICY_APPEND_MAX:- covered: set[str] = set()- for mid in kept:- covered.add(mid)- covered.add(mid.split(":", 1)[0])- kept.extend(sorted(a for a in allowed if a not in covered))+ # Only when the intersection is empty. A jurisdiction or provider policy+ # narrows the catalog without emptying the curated overlap, and appending+ # its remainder would push non-curated alphabetical ids into a picker that+ # shows a curated order on purpose. Anything omitted is still reachable+ # through the picker's custom-model entry.+ if not kept and len(allowed) <= _NOUS_POLICY_APPEND_MAX:+ return sorted(allowed)return keptdiff --git a/tests/hermes_cli/test_nous_policy_filter.py b/tests/hermes_cli/test_nous_policy_filter.pyindex 7da078c77ed..b91fe101489 100644--- a/tests/hermes_cli/test_nous_policy_filter.py+++ b/tests/hermes_cli/test_nous_policy_filter.py@@ -203,11 +203,24 @@ class TestAllowlistOutsideTheCuratedList:["vendor/a", "vendor/b"], {"amazon/nova-2-lite-v1"}) == ["amazon/nova-2-lite-v1"]- def test_keeps_curated_order_then_appends_the_rest(self):+ def test_does_not_append_when_the_curated_overlap_is_non_empty(self):+ """A jurisdiction or provider policy narrows the catalog without+ emptying the curated overlap. Appending its remainder would push+ non-curated alphabetical ids into a deliberately curated order."""kept = restrict_to_nous_policy(["z/curated", "a/curated"], {"z/curated", "a/curated", "new/model"})- assert kept == ["z/curated", "a/curated", "new/model"]+ assert kept == ["z/curated", "a/curated"]++ def test_jurisdiction_policy_never_grows_the_list(self):+ """Regression: a region filter leaves few enough models to slip under+ the size cap, so a size-only guard let it append."""+ curated = ["vendor/one", "vendor/two", "vendor/three"]+ reachable = {"vendor/one", "vendor/two"} | {f"cn/model-{i}" for i in range(20)}+ assert restrict_to_nous_policy(curated, reachable) == [+ "vendor/one",+ "vendor/two",+ ]def test_does_not_append_a_free_sibling_already_covered(self):assert restrict_to_nous_policy(["vendor/m:free"], {"vendor/m"}) == [