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(workbench): route avibe chat replies to the web UI, not Slack

cyh3851707ff1d8
diff --git a/core/controller.py b/core/controller.py
index 0696db307..c98b03a2b 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -133,6 +133,22 @@ class Controller:
for platform, client in self.im_clients.items():
self._inject_runtime_dependencies(platform, client)
+ # Avibe (the workbench Web UI) is always available as an in-process
+ # delivery surface, independent of which external IM platforms are
+ # enabled. Register it here — after ``self.im_client`` / callbacks /
+ # injection are wired for the real platforms — so
+ # ``get_im_client_for_context("avibe")`` resolves to the SSE-backed
+ # client instead of silently falling back to the primary platform
+ # (which mis-delivered workbench chat replies to e.g. Slack, where
+ # the send fails with channel_not_found and the user sees nothing).
+ # Avibe needs no inbound runtime thread (ui_server REST owns inbound),
+ # no settings-manager injection (it inherits the primary's via
+ # get_settings_manager_for_context), and no callbacks.
+ if "avibe" not in self.im_clients:
+ from modules.im.avibe import AvibeBot, AvibeConfig
+
+ self.im_clients["avibe"] = AvibeBot(AvibeConfig())
+
def _enabled_agent_backends(self) -> list[str]:
result: list[str] = []
agent_config = getattr(self.config, "agents", None)
diff --git a/core/message_mirror.py b/core/message_mirror.py
index 1cf4feb60..9d838fd06 100644
--- a/core/message_mirror.py
+++ b/core/message_mirror.py
@@ -118,7 +118,16 @@ def mirror_outbound(
if not text or not text.strip():
return
- if not context.platform or context.platform == "avibe":
+ if not context.platform:
+ return
+ if context.platform == "avibe":
+ # Avibe (workbench Web UI) replies are session-scoped, not
+ # channel-scoped: the user message was already written under the
+ # workbench session by ``vibe/ui_server.py``, so the agent reply
+ # must land in that same session + project scope. Route it through
+ # the session-aware writer instead of the channel ``upsert_scope``
+ # path used for external IM platforms.
+ _mirror_avibe_outbound(context, text, native_message_id=native_message_id, kind=kind)
return
try:
engine = create_sqlite_engine()
@@ -139,3 +148,47 @@ def mirror_outbound(
)
except Exception:
logger.exception("mirror_outbound: unexpected failure on platform=%s", context.platform)
+
+
+def _mirror_avibe_outbound(
+ context: MessageContext,
+ text: str,
+ *,
+ native_message_id: Optional[str],
+ kind: str,
+) -> None:
+ """Persist a workbench (avibe) agent reply into the session's transcript.
+
+ The session id rides on ``context.platform_specific["workbench_session_id"]``
+ (set by ``core/internal_server.py`` when it builds the dispatch context);
+ it also falls back to ``channel_id``, which the dispatch payload defaults
+ to the session id. The session row carries the project ``scope_id`` the
+ user message was stored under, so the reply joins the same transcript and
+ survives the post-stream ``refresh()`` in the Chat page.
+ """
+
+ spec = context.platform_specific or {}
+ session_id = spec.get("workbench_session_id") or context.channel_id
+ if not session_id:
+ return
+ try:
+ from core.services import sessions as sessions_service
+
+ engine = create_sqlite_engine()
+ with engine.begin() as conn:
+ try:
+ session = sessions_service.get_session(conn, session_id)
+ except LookupError:
+ return
+ _append_quietly(
+ conn,
+ scope_id=session.get("scope_id"),
+ session_id=session_id,
+ platform="avibe",
+ author="agent",
+ text=text,
+ native_message_id=native_message_id,
+ content={"kind": kind} if kind else None,
+ )
+ except Exception:
+ logger.exception("mirror_outbound(avibe): failed to persist reply for session=%s", session_id)
diff --git a/tests/test_message_mirror.py b/tests/test_message_mirror.py
index aca6a365d..1fcc0273a 100644
--- a/tests/test_message_mirror.py
+++ b/tests/test_message_mirror.py
@@ -11,8 +11,10 @@ These cover the contract that
scope,
* repeated mirror calls with the same ``native_message_id`` are
idempotent (no extra rows, no raised exception),
-* ``platform='avibe'`` is a no-op so the workbench REST writer stays the
- single source of truth.
+* ``platform='avibe'`` inbound is a no-op (the workbench REST writer owns
+ the user row), while avibe *outbound* replies are persisted under the
+ originating session so the Chat transcript shows the agent's answer once
+ the live stream settles.
"""
from __future__ import annotations
@@ -100,7 +102,10 @@ def test_duplicate_native_message_id_is_swallowed(isolated_state):
assert rows[0]["content_text"] == "first"
-def test_avibe_platform_is_noop(isolated_state):
+def test_avibe_inbound_noop_and_unknown_session_outbound_skipped(isolated_state):
+ # avibe inbound is always a no-op (ui_server's REST writer owns the user
+ # row). avibe outbound only persists when it resolves a real session — an
+ # unknown session id must NOT auto-create scopes or rows.
avibe_ctx = MessageContext(
user_id="U_alice",
channel_id="avibe-channel",
@@ -108,7 +113,7 @@ def test_avibe_platform_is_noop(isolated_state):
message_id="avibe_001",
)
mirror_inbound(avibe_ctx, "this should not land")
- mirror_outbound(avibe_ctx, "neither should this", native_message_id="avibe_002")
+ mirror_outbound(avibe_ctx, "no matching session", native_message_id="avibe_002")
engine = create_sqlite_engine()
with engine.connect() as conn:
@@ -116,6 +121,63 @@ def test_avibe_platform_is_noop(isolated_state):
assert rows == []
+def _make_avibe_session() -> tuple[str, str]:
+ """Create a real avibe project scope + session row.
+
+ Mirrors ``tests/test_ui_session_stream.py::_make_session``. Returns
+ ``(scope_id, session_id)``.
+ """
+
+ from core.services import sessions as sessions_service
+ from storage.settings_service import upsert_scope
+
+ engine = create_sqlite_engine()
+ with engine.begin() as conn:
+ scope_id = upsert_scope(
+ conn,
+ platform="avibe",
+ scope_type="project",
+ native_id="proj_mirror",
+ now="2026-05-30T00:00:00Z",
+ )
+ session = sessions_service.create_session(
+ conn,
+ scope_id=scope_id,
+ agent_backend="claude",
+ agent_name="worker",
+ )
+ return scope_id, session["id"]
+
+
+def test_avibe_outbound_persists_reply_under_session(isolated_state):
+ # Regression for the workbench "sent a message, got no response" bug
+ # (#7): avibe agent replies must land in the messages table under the
+ # originating session, because the live SSE stream is ephemeral and the
+ # Chat page's post-stream refresh re-reads the persisted row. The session
+ # id rides on ``platform_specific["workbench_session_id"]``.
+ scope_id, session_id = _make_avibe_session()
+ ctx = MessageContext(
+ user_id="workbench",
+ channel_id=session_id,
+ platform="avibe",
+ message_id=None,
+ platform_specific={"workbench_session_id": session_id},
+ )
+ mirror_outbound(ctx, "the agent reply", native_message_id="avibe_reply_1", kind="result")
+
+ engine = create_sqlite_engine()
+ with engine.connect() as conn:
+ rows = conn.execute(
+ select(messages).where(messages.c.platform == "avibe")
+ ).mappings().all()
+ assert len(rows) == 1
+ assert rows[0]["author"] == "agent"
+ assert rows[0]["content_text"] == "the agent reply"
+ assert rows[0]["session_id"] == session_id
+ assert rows[0]["scope_id"] == scope_id
+ assert rows[0]["native_message_id"] == "avibe_reply_1"
+
+
def test_outbound_mirror_uses_delivery_target_scope(isolated_state):
"""Regression: dispatcher calls mirror_outbound with ``target_context``,
which may carry a different channel/platform than the inbound ``context``