fix(webhook): forward Telegram DM-topic routing keys from deliver_extra#33396
Closed
briandevans wants to merge 1 commit into
Closed
fix(webhook): forward Telegram DM-topic routing keys from deliver_extra#33396briandevans wants to merge 1 commit into
briandevans wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Forwards Telegram DM-topic routing signals from deliver_extra through webhook delivery metadata so the Telegram adapter's anchor-required guard can be satisfied or opted out of by webhook routes.
Changes:
- Extend
_deliver_cross_platformto forward four Telegram-specific keys (telegram_reply_to_message_id,telegram_dm_topic_created_for_send,telegram_dm_topic_reply_fallback,direct_messages_topic_id) into the send metadata. - Add four async tests covering forwarding of reply anchor, DM-topic opt-out flags, reply fallback marker, and DM-topic keys without a thread_id.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| gateway/platforms/webhook.py | Forwards Telegram DM-topic signals from deliver_extra into send metadata. |
| tests/gateway/test_webhook_adapter.py | Adds tests verifying each forwarded key reaches the adapter's send metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
16 tasks
f68e862 to
4d40e2a
Compare
PR NousResearch#32270 (2026-05-25) introduced a fail-loud guard in `TelegramAdapter.send()`: a private-chat send carrying a thread_id is rejected with "requires a reply anchor" unless metadata includes one of `telegram_reply_to_message_id`, `direct_messages_topic_id`, or `telegram_dm_topic_created_for_send`. The agent/cron paths populate those keys themselves, but `WebhookAdapter._deliver_cross_platform` only forwarded `thread_id`, so any webhook subscription targeting a private DM topic now fails on every delivery — Hermes accepts the webhook (`HTTP 202`, `delivered: true`), then the cross-platform send is refused before it ever hits Telegram. Plumb the four DM-topic routing keys straight through from `deliver_extra` to the metadata dict. Webhook route configs are the only place the operator can express the opt-out, so this is the canonical place to wire them in. Mirrors `TelegramAdapter.send()` predicate precedence: `telegram_reply_to_message_id` (anchor) > `direct_messages_topic_id` (true Bot-API DM topic) > `telegram_dm_topic_created_for_send` (Hermes-created DM topic) > `telegram_dm_topic_reply_fallback` (reply_to_mode='off' opt-in). Legacy single-key `thread_id` / `message_thread_id` forwarding is unchanged.
4d40e2a to
2de512d
Compare
Contributor
Author
|
Closing to focus the queue on security/file-safety work where civilian merges are landing. Happy to reopen if maintainers want this picked up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
PR #32270 (merged 2026-05-25) tightened
TelegramAdapter.send()with a fail-loud guard: a private-chat send carrying athread_idis rejected withTelegram DM topic delivery requires a reply anchor; refusing to send outside the requested topicunless metadata includes one oftelegram_reply_to_message_id,direct_messages_topic_id, ortelegram_dm_topic_created_for_send. The agent/cron paths populate those keys themselves, butWebhookAdapter._deliver_cross_platformonly forwardsthread_id, so webhook subscriptions targeting private DM topics fail on every delivery — Hermes accepts the webhook (HTTP 202,delivered: true) and the cross-platform send is refused before reaching Telegram.Forward the four DM-topic routing keys straight through from
deliver_extrato the metadata dict so webhook routes can express the opt-out the same way the agent path can. MirrorsTelegramAdapter._is_private_dm_topic_sendpredicate precedence:telegram_reply_to_message_id(anchor) >direct_messages_topic_id(true Bot-API DM topic) >telegram_dm_topic_created_for_send(Hermes-created DM topic) >telegram_dm_topic_reply_fallback(reply_to_mode='off' opt-in). Legacy single-keythread_id/message_thread_idforwarding is unchanged.Related Issue
Fixes #33375
Type of Change
Changes Made
gateway/platforms/webhook.py— in_deliver_cross_platform, forwardtelegram_reply_to_message_id,telegram_dm_topic_created_for_send,telegram_dm_topic_reply_fallback, anddirect_messages_topic_idfromdeliver_extraintometadataso the Telegram adapter's anchor-required guard can route or opt out per the route config.tests/gateway/test_webhook_adapter.py— add four cases toTestDeliverCrossPlatformThreadIdcovering each opt-out key path: reply-anchor forwarding, Bot-API DM-topic opt-out (direct_messages_topic_id+telegram_dm_topic_created_for_send), Hermes-created DM-topic + reply anchor (telegram_dm_topic_reply_fallback), and keys-without-thread_id.How to Test
deliver: telegramdeliver_extraincludes bothchat_id(a private user id) andmessage_thread_id(a DM-topic id fromweb.telegram.org), and a Telegram bot in Hermes.curl. Hermes returns{"delivered": true, "status": 202}but logsTelegram DM topic delivery requires a reply anchor; refusing to send outside the requested topicand nothing reaches Telegram.telegram_reply_to_message_id(ortelegram_dm_topic_created_for_send: true) to the samedeliver_extrablock on this PR's branch — the send goes through and lands in the requested topic.uv run --with pytest --with pytest-xdist --with pytest-asyncio python3 -m pytest tests/gateway/test_webhook_adapter.py -v— 69 passed (5 new inTestDeliverCrossPlatformThreadId, plus the existing 64). Regression guard: stashing only the production change leaves the 4 new assertion-based tests failing withExpected: send(... metadata={...}) Actual: send(... metadata=None), restoring it flips them back to passing.Checklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
docs/, docstrings) — N/A; behavior change is internal to the cross-platform dispatchercli-config.yaml.exampleif I added/changed config keys — N/A; thedeliver_extrakeys are already documented in the issueCONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/ARelated / Positioning
TelegramAdapter.send(). Agent and cron paths populate the opt-out keys themselves; this PR closes the webhook-adapter gap on the same contract.tools/send_message_tool.py. No overlap — different code path, different failure mode.gateway/platforms/webhook.py.