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(controller): add lock to clear_consolidated_message_id

cyhhao874efc0db0d5
diff --git a/core/controller.py b/core/controller.py
index 550df3262..6def865d9 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -232,7 +232,7 @@ class Controller:
self._consolidated_message_locks[key] = asyncio.Lock()
return self._consolidated_message_locks[key]
- def clear_consolidated_message_id(
+ async def clear_consolidated_message_id(
self, context: MessageContext, trigger_message_id: Optional[str] = None
) -> None:
"""Clear consolidated message ID so next log message starts fresh.
@@ -251,9 +251,13 @@ class Controller:
thread_key = context.thread_id or context.channel_id
msg_id = trigger_message_id if trigger_message_id else (context.message_id or "")
key = f"{settings_key}:{thread_key}:{msg_id}"
- self._consolidated_message_ids.pop(key, None)
- # Also clear the buffer so we don't append to stale content
- self._consolidated_message_buffers.pop(key, None)
+
+ # Use the same per-key lock as emit_agent_message to avoid race conditions
+ lock = self._get_consolidated_message_lock(key)
+ async with lock:
+ self._consolidated_message_ids.pop(key, None)
+ # Also clear the buffer so we don't append to stale content
+ self._consolidated_message_buffers.pop(key, None)
def _get_consolidated_max_bytes(self) -> int:
# Slack API hard limit is exactly 4000 BYTES (not characters) for chat.update
diff --git a/modules/agents/opencode/question_handler.py b/modules/agents/opencode/question_handler.py
index 4ac4ddb91..14bb4f4a4 100644
--- a/modules/agents/opencode/question_handler.py
+++ b/modules/agents/opencode/question_handler.py
@@ -422,7 +422,7 @@ class OpenCodeQuestionHandler:
# Clear consolidated message ID so subsequent log messages appear after user's reply
# instead of editing the old consolidated message from before the question
- self._controller.clear_consolidated_message_id(request.context, trigger_message_id)
+ await self._controller.clear_consolidated_message_id(request.context, trigger_message_id)
evt = self._question_answer_events.get(request.base_session_id)
if evt: