fix: resolve listed messaging targets consistently#5149
Conversation
|
Good fix for a real issue — the list/resolve asymmetry where Hermes emits The structural improvement is solid: One structural concern — reaching into from tools.send_message_tool import _parse_target_ref
Two cleanups: Option A — promote to public API by dropping the underscore prefix. Signals "other callers depend on this": # send_message_tool.py
def parse_target_ref(platform_name: str, target_ref: str) -> tuple[Optional[str], Optional[str], bool]:
"""Parse a tool target into chat_id/thread_id and whether it is explicit."""
...Option B — extract to a shared utility ( Either way, the import from cron stops reaching past the underscore. Minor observation — the resolution flow re-parses after resolving: parsed_chat_id, parsed_thread_id, is_explicit = _parse_target_ref(platform_key, rest)
# ... set chat_id, thread_id from parse ...
resolved = resolve_channel_name(platform_key, chat_id)
if resolved:
parsed_chat_id, parsed_thread_id, resolved_is_explicit = _parse_target_ref(platform_key, resolved)
if resolved_is_explicit:
chat_id, thread_id = parsed_chat_id, parsed_thread_id
else:
chat_id = resolvedThis is correct (the resolver can return chat_id, thread_id = _coerce_to_chat_thread(platform_key, rest)
resolved = resolve_channel_name(platform_key, chat_id)
if resolved:
chat_id, thread_id = _coerce_to_chat_thread(platform_key, resolved)Ship it — the user-visible behavior is correct, tests exercise the important cases, and the refactor is a net improvement over what was there. |
|
Merged via PR #5288 (consolidated bugfix salvage). Your commit(s) were cherry-picked onto current main with your authorship preserved in git log. Thanks @damianpdr for the fix! |
Summary
resolve_channel_name()accept the exact labels shown bysend_message(action="list")Why this fixes a real issue
send_message(action="list")shows non-Discord targets with type suffixes likeAlice (dm)orCoaching Chat / topic 17585 (group), butresolve_channel_name()previously only matched the raw stored name. Copying a listed target intosend_messageor cron delivery could fail even though it came from Hermes itself.Before this patch on
main, a direct repro returnedNonefor both:resolve_channel_name("telegram", "Alice (dm)")resolve_channel_name("telegram", "Coaching Chat / topic 17585 (group)")After this patch, those resolve to the correct IDs, and cron topic deliveries keep the thread id instead of collapsing to a combined chat id string.
Test Plan
python -m pytest tests/gateway/test_channel_directory.py tests/tools/test_send_message_tool.py tests/cron/test_scheduler.py::TestResolveDeliveryTarget -q -n 0python -m pytest tests/cron/test_scheduler.py -q -n 0(still shows the same 5 pre-existing failures already present onorigin/main, unrelated to this diff)Review notes