Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix: address review comments on reaction cleanup

yh c068171107b60
diff --git a/core/handlers/message_handler.py b/core/handlers/message_handler.py
index d2f21aa68..c17b417a2 100644
--- a/core/handlers/message_handler.py
+++ b/core/handlers/message_handler.py
@@ -229,11 +229,11 @@ class MessageHandler:
await self.controller.agent_service.handle_message(agent_name, request)
except KeyError:
await self._handle_missing_agent(context, agent_name)
+ # Clean up reaction on error
+ await self._remove_ack_reaction(context, request)
finally:
if request.ack_message_id:
await self._delete_ack(context.channel_id, request)
- # Note: reaction removal is now handled by the agent when sending result message
- # See BaseAgent.emit_result_message and _remove_ack_reaction
except Exception as e:
logger.error(f"Error processing user message: {e}", exc_info=True)
await self.im_client.send_message(
@@ -389,6 +389,23 @@ class MessageHandler:
finally:
request.ack_message_id = None
+ async def _remove_ack_reaction(
+ self, context: MessageContext, request: AgentRequest
+ ):
+ """Remove acknowledgement reaction if it still exists."""
+ if request.ack_reaction_message_id and request.ack_reaction_emoji:
+ try:
+ await self.im_client.remove_reaction(
+ context,
+ request.ack_reaction_message_id,
+ request.ack_reaction_emoji,
+ )
+ except Exception as err:
+ logger.debug(f"Failed to remove reaction ack: {err}")
+ finally:
+ request.ack_reaction_message_id = None
+ request.ack_reaction_emoji = None
+
def _get_ack_text(self, agent_name: str) -> str:
"""Unified acknowledgement text before agent processing."""
label = agent_name or self.controller.agent_service.default_agent
diff --git a/modules/agents/claude_agent.py b/modules/agents/claude_agent.py
index 3c3a66187..527bdc011 100644
--- a/modules/agents/claude_agent.py
+++ b/modules/agents/claude_agent.py
@@ -25,10 +25,9 @@ class ClaudeAgent(BaseAgent):
self.claude_client = controller.claude_client
self._last_assistant_text: dict[str, str] = {}
self._pending_assistant_message: dict[str, str] = {}
- # Store reaction info per session for cleanup after result
- self._pending_reactions: dict[
- str, tuple[str, str]
- ] = {} # session_id -> (message_id, emoji)
+ # Store reaction info per session as a queue (FIFO) for cleanup after result
+ # Each entry is (reaction_message_id, emoji)
+ self._pending_reactions: dict[str, list[tuple[str, str]]] = {}
async def handle_message(self, request: AgentRequest) -> None:
context = request.context
@@ -48,11 +47,12 @@ class ClaudeAgent(BaseAgent):
await self._delete_ack(context, request)
- # Store reaction info for cleanup after result message
+ # Store reaction info for cleanup after result message (queue for multiple messages)
if request.ack_reaction_message_id and request.ack_reaction_emoji:
- self._pending_reactions[request.composite_session_id] = (
- request.ack_reaction_message_id,
- request.ack_reaction_emoji,
+ if request.composite_session_id not in self._pending_reactions:
+ self._pending_reactions[request.composite_session_id] = []
+ self._pending_reactions[request.composite_session_id].append(
+ (request.ack_reaction_message_id, request.ack_reaction_emoji)
)
if (
@@ -294,10 +294,17 @@ class ClaudeAgent(BaseAgent):
async def _remove_pending_reaction(
self, composite_key: str, context: MessageContext
) -> None:
- """Remove stored reaction for a session after result is sent."""
- reaction_info = self._pending_reactions.pop(composite_key, None)
- if reaction_info:
- message_id, emoji = reaction_info
+ """Remove the oldest stored reaction for a session after result is sent.
+
+ Uses FIFO queue to handle multiple messages in the same session.
+ """
+ reactions = self._pending_reactions.get(composite_key)
+ if reactions:
+ # Pop the oldest reaction (FIFO)
+ message_id, emoji = reactions.pop(0)
+ # Clean up empty list
+ if not reactions:
+ self._pending_reactions.pop(composite_key, None)
try:
await self.im_client.remove_reaction(context, message_id, emoji)
except Exception as err:
diff --git a/modules/agents/opencode/agent.py b/modules/agents/opencode/agent.py
index d9ffae483..9afae3d36 100644
--- a/modules/agents/opencode/agent.py
+++ b/modules/agents/opencode/agent.py
@@ -149,6 +149,7 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
"notify",
f"Failed to start OpenCode server: {e}",
)
+ await self._remove_ack_reaction(request)
return
await self._delete_ack(request)
@@ -163,6 +164,7 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
"notify",
"Failed to obtain OpenCode session ID",
)
+ await self._remove_ack_reaction(request)
return
self._session_manager.set_request_session(
@@ -300,6 +302,7 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
except asyncio.CancelledError:
logger.info(f"OpenCode request cancelled for {request.base_session_id}")
await self._question_handler.clear(request.base_session_id)
+ await self._remove_ack_reaction(request)
if session_id:
self.settings_manager.remove_active_poll(session_id)
raise
@@ -320,6 +323,7 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
# Clean up answer reaction on error
await self._question_handler.clear(request.base_session_id)
+ await self._remove_ack_reaction(request)
if session_id:
self.settings_manager.remove_active_poll(session_id)
@@ -391,6 +395,21 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
finally:
request.ack_message_id = None
+ async def _remove_ack_reaction(self, request: AgentRequest) -> None:
+ """Remove acknowledgement reaction on error paths."""
+ if request.ack_reaction_message_id and request.ack_reaction_emoji:
+ try:
+ await self.im_client.remove_reaction(
+ request.context,
+ request.ack_reaction_message_id,
+ request.ack_reaction_emoji,
+ )
+ except Exception as err:
+ logger.debug(f"Could not remove ack reaction: {err}")
+ finally:
+ request.ack_reaction_message_id = None
+ request.ack_reaction_emoji = None
+
async def restore_active_polls(self) -> int:
"""Restore active poll loops that were interrupted by vibe-remote restart."""