Cache notification messages for reaction context#132
Open
constkolesnyak wants to merge 1 commit into
Open
Conversation
Notifications sent via NotificationService._deliver_telegram() bypassed TelegramChannel.send() and went directly through bot.send_message(), so they were never stored in _message_cache. When a user reacted to a notification, the reaction handler couldn't find the original text and only showed "[Reaction: 👎]" without context. Now _deliver_telegram caches sent messages via channel._cache_message() so reactions on notifications include the message text. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.
Problem
NotificationService._deliver_telegram()sends notifications by calling either_send_telegram_html()or_send_telegram_inline(), both of which go throughbot.send_message()directly — bypassingTelegramChannel.send()and its_cache_message()call.Consequence: notification messages never land in
_message_cache. When a user reacts to a notification on Telegram, the reaction handler doesself._message_cache.get(message_id)(channels/telegram.py:1352), getsNone, and shows the reaction as:— no original text, no context for the agent to respond to. For approval prompts and questions this is the difference between "the user said no to the rollback question" and "the user said no to something."
Fix
After
_deliver_telegram()lands a message (via either the inline-buttons path or the plain HTML path), capturemsg_idand feed it tochannel._cache_message(int(msg_id), chat_id, text). Same cache, same eviction policy (_message_cache_max = 200) — the entry now flows from the notification path too, so reactions resolve to the actual prompt text.Both branches converge into a single
msg_idand the cache call runs once at the end of the function.Re-application of the previously-closed #50 (closed by me in error without comment 2 months ago, never recreated), rebased onto current
mainand merged with the newerapproval-kind dispatch + emoji button labels added since.Tests
Existing
notifications-keyword tests stay green:58 passed, 1095 deselected.Files
nerve/notifications/service.py— capturemsg_idfrom both inline and HTML paths, then callchannel._cache_message(msg_id, chat_id, text)(+19 / −4)