Skip to content

The agent that grows with you

fix(gateway): a thread's own channel skill binding wins over its parent's in any config order

John Paul Soliva79af3f6cea80
diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py
index 17d875682f2..eaa0febd3ab 100644
--- a/gateway/platforms/base.py
+++ b/gateway/platforms/base.py
@@ -1880,19 +1880,18 @@ def resolve_channel_skills(
bindings = config_extra.get("channel_skill_bindings") or []
if not isinstance(bindings, list) or not bindings:
return None
- ids_to_check = {str(key) for key in (channel_id, parent_id) if key}
- if not ids_to_check:
- return None
- for entry in bindings:
- if not isinstance(entry, dict) or str(entry.get("id", "")) not in ids_to_check:
- continue
- skills = entry.get("skills") or entry.get("skill")
- if isinstance(skills, str):
- return [skills.strip()] if skills.strip() else None
- if isinstance(skills, list) and skills:
- seen = dict.fromkeys(
- nm for name in skills if isinstance(name, str) and (nm := name.strip()))
- return list(seen) or None
+ # One pass per id, not one pass matching either: the parent's entry may be listed first.
+ for wanted in (str(key) for key in (channel_id, parent_id) if key):
+ for entry in bindings:
+ if not isinstance(entry, dict) or str(entry.get("id", "")) != wanted:
+ continue
+ skills = entry.get("skills") or entry.get("skill")
+ if isinstance(skills, str):
+ return [skills.strip()] if skills.strip() else None
+ if isinstance(skills, list) and skills:
+ seen = dict.fromkeys(
+ nm for name in skills if isinstance(name, str) and (nm := name.strip()))
+ return list(seen) or None
return None
diff --git a/tests/gateway/test_discord_channel_skills.py b/tests/gateway/test_discord_channel_skills.py
index 5d45ee810f4..69f62264f8b 100644
--- a/tests/gateway/test_discord_channel_skills.py
+++ b/tests/gateway/test_discord_channel_skills.py
@@ -1,6 +1,8 @@
"""Tests for Discord channel_skill_bindings auto-skill resolution."""
from unittest.mock import MagicMock
+import pytest
+
def _make_adapter():
"""Create a minimal DiscordAdapter with mocked config."""
@@ -24,6 +26,15 @@ class TestResolveChannelSkills:
# channel_id doesn't match, but parent_id does (forum thread)
assert adapter._resolve_channel_skills("999", parent_id="200") == ["forum-skill"]
+ @pytest.mark.parametrize("parent_first", [False, True])
+ def test_thread_binding_wins_over_parent_in_any_config_order(self, parent_first):
+ """A thread's own binding overrides the one it would inherit from its parent; the order
+ the two entries are listed in must not decide which skill a new session loads."""
+ bindings = [{"id": "800", "skill": "thread-specific"}, {"id": "700", "skill": "parent-default"}]
+ adapter = _make_adapter()
+ adapter.config.extra = {"channel_skill_bindings": bindings[::-1] if parent_first else bindings}
+ assert adapter._resolve_channel_skills("800", parent_id="700") == ["thread-specific"]
+
def test_no_match_returns_none(self):
adapter = _make_adapter()
adapter.config.extra = {