Skip to content

Cache notification messages for reaction context#132

Open
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:upstream/notif-reaction-cache
Open

Cache notification messages for reaction context#132
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:upstream/notif-reaction-cache

Conversation

@constkolesnyak

Copy link
Copy Markdown
Contributor

Problem

NotificationService._deliver_telegram() sends notifications by calling either _send_telegram_html() or _send_telegram_inline(), both of which go through bot.send_message() directly — bypassing TelegramChannel.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 does self._message_cache.get(message_id) (channels/telegram.py:1352), gets None, and shows the reaction as:

[Reaction: 👎]

— 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), capture msg_id and feed it to channel._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_id and 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 main and merged with the newer approval-kind dispatch + emoji button labels added since.

Tests

Existing notifications-keyword tests stay green: 58 passed, 1095 deselected.

Files

  • nerve/notifications/service.py — capture msg_id from both inline and HTML paths, then call channel._cache_message(msg_id, chat_id, text) (+19 / −4)

Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant