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: properly manage answer reaction lifecycle

cyhhao401c57376ee3
diff --git a/modules/agents/opencode/agent.py b/modules/agents/opencode/agent.py
index 81ad8614c..77da65f59 100644
--- a/modules/agents/opencode/agent.py
+++ b/modules/agents/opencode/agent.py
@@ -126,7 +126,7 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
await task
except asyncio.CancelledError:
logger.debug(f"OpenCode task cancelled for {request.base_session_id}")
- self._question_handler.clear(request.base_session_id)
+ await self._question_handler.clear(request.base_session_id)
finally:
if self._active_requests.get(request.base_session_id) is task:
self._active_requests.pop(request.base_session_id, None)
@@ -276,6 +276,8 @@ class OpenCodeAgent(OpenCodeMessageProcessorMixin, BaseAgent):
started_at=request.started_at,
)
+ # Clean up answer reaction after result is sent
+ await self._question_handler.clear(request.base_session_id)
self.settings_manager.remove_active_poll(session_id)
except asyncio.CancelledError:
diff --git a/modules/agents/opencode/poll_loop.py b/modules/agents/opencode/poll_loop.py
index b6408ef93..8c93af8a7 100644
--- a/modules/agents/opencode/poll_loop.py
+++ b/modules/agents/opencode/poll_loop.py
@@ -397,12 +397,15 @@ class OpenCodePollLoop:
started_at=started_at,
)
+ # Clean up answer reaction after result is sent
+ await self._question_handler.clear(poll_info.base_session_id)
self._agent.settings_manager.remove_active_poll(session_id)
except asyncio.CancelledError:
logger.info(
f"Restored OpenCode poll cancelled for {poll_info.base_session_id}"
)
+ await self._question_handler.clear(poll_info.base_session_id)
self._agent.settings_manager.remove_active_poll(session_id)
raise
except Exception as e:
diff --git a/modules/agents/opencode/question_handler.py b/modules/agents/opencode/question_handler.py
index a0be43031..a852ef217 100644
--- a/modules/agents/opencode/question_handler.py
+++ b/modules/agents/opencode/question_handler.py
@@ -35,6 +35,9 @@ class OpenCodeQuestionHandler:
self._pending_questions: Dict[str, PendingQuestionPayload] = {}
self._question_answer_events: Dict[str, asyncio.Event] = {}
self._timed_out_questions: set[str] = set()
+ # Track reactions added after question answer for cleanup
+ # Maps base_session_id -> (context, message_id, emoji)
+ self._answer_reactions: Dict[str, tuple] = {}
def get_pending(self, base_session_id: str) -> Optional[PendingQuestionPayload]:
return self._pending_questions.get(base_session_id)
@@ -45,10 +48,22 @@ class OpenCodeQuestionHandler:
def pop_pending(self, base_session_id: str) -> Optional[PendingQuestionPayload]:
return self._pending_questions.pop(base_session_id, None)
- def clear(self, base_session_id: str) -> None:
+ async def clear(self, base_session_id: str) -> None:
+ """Clear all state for a session, including removing any answer reaction."""
self._pending_questions.pop(base_session_id, None)
self._question_answer_events.pop(base_session_id, None)
self._timed_out_questions.discard(base_session_id)
+ await self._remove_answer_reaction(base_session_id)
+
+ async def _remove_answer_reaction(self, base_session_id: str) -> None:
+ """Remove the 👀 reaction added after question answer."""
+ reaction_info = self._answer_reactions.pop(base_session_id, None)
+ if reaction_info and hasattr(self._im_client, "remove_reaction"):
+ context, message_id, emoji = reaction_info
+ try:
+ await self._im_client.remove_reaction(context, message_id, emoji)
+ except Exception as err:
+ logger.debug(f"Failed to remove answer reaction: {err}")
def _get_or_create_question_event(self, base_session_id: str) -> asyncio.Event:
"""Get or create an event for question answer coordination.
@@ -390,10 +405,16 @@ class OpenCodeQuestionHandler:
return
# Add 👀 reaction to question message to indicate answer received
+ # Track it for cleanup when the request completes
if question_message_id and hasattr(self._im_client, "add_reaction"):
try:
+ emoji = "eyes"
await self._im_client.add_reaction(
- request.context, question_message_id, "eyes"
+ request.context, question_message_id, emoji
+ )
+ # Save for cleanup when request completes
+ self._answer_reactions[request.base_session_id] = (
+ request.context, question_message_id, emoji
)
except Exception as err:
logger.debug(f"Failed to add reaction to question message: {err}")