Skip to content

The agent that grows with you

fix(kanban): fail closed on invalid dispatch allowlist

KoNit-Ke3d377a5a526
diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.py
index 8aed444ac4d..1c19ef85ba6 100644
--- a/hermes_cli/kanban_db_dispatch.py
+++ b/hermes_cli/kanban_db_dispatch.py
@@ -1534,16 +1534,19 @@ def _dispatch_profile_allowlist(normalize_profile_name) -> Optional[frozenset]:
dispatch_profiles: ["sage", "researcher"] # or "sage,researcher"
Returns ``None`` when the key is unset (upstream behavior: any existing
- profile is claimable). A set value is fail-closed: an empty list claims
- nothing. Config read is fail-open like the sibling ``kanban.*`` readers.
+ profile is claimable). A present value is fail-closed: an empty list,
+ ``null``, or a failed config read claims nothing.
"""
try:
- from hermes_cli.config import load_config_readonly
- raw = (load_config_readonly() or {}).get("kanban", {}).get("dispatch_profiles")
+ from hermes_cli.config_effective import load_user_config_effective
+ kanban = (load_user_config_effective(fail_closed=True) or {}).get("kanban", {})
except Exception:
+ return frozenset()
+ if not isinstance(kanban, Mapping) or "dispatch_profiles" not in kanban:
return None
+ raw = kanban["dispatch_profiles"]
if raw is None:
- return None
+ return frozenset()
names = [str(n) for n in raw] if isinstance(raw, (list, tuple)) else str(raw).split(",")
allowed = set()
for n in names:
diff --git a/tests/hermes_cli/test_kanban_dispatch_claim_allowlist.py b/tests/hermes_cli/test_kanban_dispatch_claim_allowlist.py
index 4af8efa7df4..1f837881083 100644
--- a/tests/hermes_cli/test_kanban_dispatch_claim_allowlist.py
+++ b/tests/hermes_cli/test_kanban_dispatch_claim_allowlist.py
@@ -76,3 +76,49 @@ def test_unset_allowlist_keeps_default_claimable(kanban_home, all_assignees_spaw
res = kbd.dispatch_once(conn, dry_run=True)
assert [t for t, _a, _w in res.spawned] == [tid]
assert res.skipped_nonspawnable == []
+
+
[email protected]("value", ["", None], ids=["blank", "null"])
+def test_present_blank_or_null_allowlist_skips_all_cards(
+ kanban_home, all_assignees_spawnable, value,
+):
+ """A present key with no names must not fall back to unrestricted claims."""
+ rendered = "" if value is None else ' ""'
+ (kanban_home / "config.yaml").write_text(
+ f"kanban:\n dispatch_profiles:{rendered}\n", encoding="utf-8",
+ )
+ with kbc.connect() as conn:
+ tid = kb.create_task(conn, title="foreign card", assignee="default")
+ res = kbd.dispatch_once(conn, dry_run=True)
+ assert res.spawned == []
+ assert res.skipped_nonspawnable == [tid]
+
+
+def test_allowlist_config_read_failure_skips_all_cards(
+ kanban_home, all_assignees_spawnable, monkeypatch,
+):
+ """A broken config read must not make this shared home claim every profile."""
+ from hermes_cli import config_effective
+
+ def raise_read_error(**_kwargs):
+ raise OSError("config unavailable")
+
+ monkeypatch.setattr(config_effective, "load_user_config_effective", raise_read_error)
+ with kbc.connect() as conn:
+ tid = kb.create_task(conn, title="foreign card", assignee="default")
+ res = kbd.dispatch_once(conn, dry_run=True)
+ assert res.spawned == []
+ assert res.skipped_nonspawnable == [tid]
+
+
+def test_valid_allowlist_keeps_named_profile_claimable(
+ kanban_home, all_assignees_spawnable,
+):
+ """A configured name remains claimable after the fail-closed distinction."""
+ (kanban_home / "config.yaml").write_text(
+ "kanban:\n dispatch_profiles:\n - default\n", encoding="utf-8",
+ )
+ with kbc.connect() as conn:
+ tid = kb.create_task(conn, title="local card", assignee="default")
+ res = kbd.dispatch_once(conn, dry_run=True)
+ assert [task_id for task_id, _assignee, _workspace in res.spawned] == [tid]