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.

feat(indicator): stamp a terminal receipt on turns that end without a result

qiqi9089627b098a
diff --git a/core/processing_indicator.py b/core/processing_indicator.py
index 0a097b776..434f23d2f 100644
--- a/core/processing_indicator.py
+++ b/core/processing_indicator.py
@@ -36,6 +36,15 @@ QUEUED_REACTION_EMOJI = "👌"
STEERED_REACTION_EMOJI = "✍️"
UNCONFIRMED_REACTION_EMOJI = "🤔"
NOT_DELIVERED_REACTION_EMOJI = "🤷"
+# Terminal receipts that REPLACE the running 👀 instead of clearing it. Plain
+# removal is the right ending for a turn that produced its own result — the
+# result IS the receipt — but it is ambiguous for a turn that ended without one:
+# a stopped turn and a turn whose runtime died both leave a message that simply
+# stopped having a reaction, which is also what a healthy silent completion
+# looks like. These two say which happened, and they persist on the triggering
+# message rather than costing a line in the thread.
+STOPPED_REACTION_EMOJI = "⏹️"
+INTERRUPTED_REACTION_EMOJI = "⚠️"
# Delivery state -> admission receipt. States that own a turn (``claimed``,
# ``steering``, ``interrupt_waiting``) are absent on purpose: their feedback is
# the turn's own processing indicator, and an ``accepted`` Delivery is only
@@ -521,6 +530,40 @@ class ProcessingIndicatorService:
handle.ack_reaction_emoji = emoji
return True
+ async def stamp_orphaned_terminal_reaction(
+ self,
+ context: MessageContext,
+ message_id: str,
+ terminal_emoji: str,
+ ) -> bool:
+ """Retire a running 👀 left behind by a runtime that died mid-turn.
+
+ The in-memory handle does NOT survive a service restart — only the
+ OpenCode poll loop snapshots one, and it restores after the promotion to
+ 👀 — so a turn whose process disappeared leaves its running reaction on
+ the user's message with nothing left to clear it. Recovery recovers the
+ originating message id from the durable ledger, so it can finish the
+ lifecycle the dead process could not: drop the stale 👀 and leave the
+ terminal receipt in its place.
+
+ Both halves are best-effort and independent. A platform that already lost
+ the reaction (message deleted, history trimmed) must still get the
+ terminal receipt attempted, so the removal failing does not skip it.
+ """
+
+ if not message_id or not terminal_emoji:
+ return False
+ im_client = self._get_im_client(context)
+ try:
+ await im_client.remove_reaction(context, message_id, ACK_REACTION_EMOJI)
+ except Exception as err:
+ logger.debug("Failed to remove orphaned ack reaction: %s", err)
+ try:
+ return bool(await im_client.add_reaction(context, message_id, terminal_emoji))
+ except Exception as err:
+ logger.debug("Failed to stamp orphaned terminal reaction: %s", err)
+ return False
+
def _resolve_handle(self, request_or_handle: Any) -> tuple[ProcessingIndicatorHandle, Optional[Any]]:
if isinstance(request_or_handle, ProcessingIndicatorHandle):
return request_or_handle, None
@@ -743,7 +786,23 @@ class ProcessingIndicatorService:
if getattr(request, "processing_indicator", None) is None:
request.processing_indicator = handle
- async def finish(self, request_or_handle: Any) -> None:
+ async def finish(
+ self,
+ request_or_handle: Any,
+ *,
+ terminal_emoji: Optional[str] = None,
+ ) -> None:
+ """Clear the turn's indicator, optionally leaving a terminal receipt.
+
+ ``terminal_emoji`` replaces the running 👀 rather than clearing it, for
+ the endings that produce no result of their own (see
+ ``STOPPED_REACTION_EMOJI`` / ``INTERRUPTED_REACTION_EMOJI``). Omitting it
+ keeps the historical behavior — a turn that emitted a result needs no
+ second receipt. Adding the replacement is best-effort: the removal is
+ what the handle's bookkeeping is keyed on, so a platform that rejects the
+ new emoji still ends with a cleanly cleared indicator.
+ """
+
if isinstance(request_or_handle, ProcessingIndicatorHandle):
handle = request_or_handle
request = None
@@ -779,6 +838,7 @@ class ProcessingIndicatorService:
request.typing_indicator_active = False
if handle.ack_reaction_message_id and handle.ack_reaction_emoji:
+ reaction_message_id = handle.ack_reaction_message_id
try:
await self._get_im_client(handle.context).remove_reaction(
handle.context,
@@ -787,6 +847,16 @@ class ProcessingIndicatorService:
)
except Exception as err:
logger.debug("Failed to remove reaction ack: %s", err)
+ else:
+ if terminal_emoji:
+ try:
+ await self._get_im_client(handle.context).add_reaction(
+ handle.context,
+ reaction_message_id,
+ terminal_emoji,
+ )
+ except Exception as err:
+ logger.debug("Failed to add terminal reaction: %s", err)
finally:
handle.ack_reaction_message_id = None
handle.ack_reaction_emoji = None
diff --git a/modules/agents/base.py b/modules/agents/base.py
index da5337490..66cf47d69 100644
--- a/modules/agents/base.py
+++ b/modules/agents/base.py
@@ -521,18 +521,26 @@ class BaseAgent(ABC):
self._pin_agent_session_id(request.context, reserved_id)
return ensured_id
- async def _remove_ack_reaction(self, request: AgentRequest) -> None:
+ async def _remove_ack_reaction(
+ self,
+ request: AgentRequest,
+ *,
+ terminal_emoji: Optional[str] = None,
+ ) -> None:
"""Remove the acknowledgement reaction / typing indicator.
Called after sending result message or on terminal error to clean up
the 👀 reaction. This is the **single** implementation — subclasses
should NOT override it. The guard (check-then-clear) is idempotent so
calling it more than once is harmless.
+
+ ``terminal_emoji`` leaves a terminal receipt in place of the 👀 for an
+ ending that emits no result of its own; a stop is the live caller.
"""
service = getattr(self.controller, "processing_indicator", None)
if service is None:
return
- await service.finish(request)
+ await service.finish(request, terminal_emoji=terminal_emoji)
async def emit_result_message(
self,
diff --git a/modules/agents/claude_agent.py b/modules/agents/claude_agent.py
index f94a3e23f..67757bf92 100644
--- a/modules/agents/claude_agent.py
+++ b/modules/agents/claude_agent.py
@@ -17,6 +17,7 @@ from core.message_output import (
terminal_turn_output,
)
from core.native_dispatch_phase import mark_backend_dispatch_attempted
+from core.processing_indicator import STOPPED_REACTION_EMOJI
from core.reply_enhancer import strip_silent_blocks
from core.runtime_activation import RuntimeActivationIdentity
from core.runtime_work import RuntimeWorkLane
@@ -1264,7 +1265,10 @@ class ClaudeAgent(BaseAgent):
if stopped_request is not None:
try:
await self._remove_specific_pending_reaction(composite_key, request.context, stopped_request)
- await self._remove_ack_reaction(stopped_request)
+ await self._remove_ack_reaction(
+ stopped_request,
+ terminal_emoji=STOPPED_REACTION_EMOJI,
+ )
except Exception:
logger.debug("Failed to clear Claude stop processing indicator", exc_info=True)
@@ -1283,7 +1287,9 @@ class ClaudeAgent(BaseAgent):
# A user-initiated stop is terminal but intentional, so it carries
# NO user-facing message: a single SILENT result settles the dot to
# idle + releases the SSE waiter through the outbound chokepoint
- # WITHOUT a bubble. Emit only after cleanup so the next turn cannot
+ # WITHOUT a bubble. IM says it in the reaction instead — the ⏹️
+ # stamped above is the receipt, at no cost in thread noise. Emit
+ # only after cleanup so the next turn cannot
# acquire the gate and reuse a client that this stop is still
# disconnecting. ``stop_output_for`` (not the terminal-turn default) keeps
# this empty body out of the run's terminal state so the stop settles it
diff --git a/modules/agents/codex/agent.py b/modules/agents/codex/agent.py
index 7f4087629..5e6d7b2ec 100644
--- a/modules/agents/codex/agent.py
+++ b/modules/agents/codex/agent.py
@@ -20,6 +20,7 @@ from core.backend_failure import emit_backend_failure
from core.caller_context import caller_env_for_platform_payload
from core.message_output import stop_output_for, terminal_output_for
from core.native_dispatch_phase import mark_backend_dispatch_attempted
+from core.processing_indicator import STOPPED_REACTION_EMOJI
from core.services.agent_steering import (
ActiveSteerTarget,
SteerOutcome,
@@ -635,12 +636,15 @@ class CodexAgent(BaseAgent):
)
interrupted_request = self._event_handler.clear_pending(turn_id)
if interrupted_request:
- await self._remove_ack_reaction(interrupted_request)
+ await self._remove_ack_reaction(
+ interrupted_request,
+ terminal_emoji=STOPPED_REACTION_EMOJI,
+ )
# A user-initiated stop is terminal but intentional, so it carries NO
# user-facing message: a single SILENT result settles the dot to idle +
# releases the SSE waiter through the outbound chokepoint without a
# bubble. The user already knows they stopped it (avibe shows the dot go
- # idle; IM shows the ack reaction removed above). ``level="silent"`` is
+ # idle; IM shows the ⏹️ receipt stamped above). ``level="silent"`` is
# the explicit visibility grade rather than faking it via empty text.
# ``stop_output_for`` (not the terminal-turn default) keeps this empty body
# out of the run's terminal state so the stop settles it ``canceled``
diff --git a/tests/test_turn_terminal_reaction.py b/tests/test_turn_terminal_reaction.py
new file mode 100644
index 000000000..288cb8c9d
--- /dev/null
+++ b/tests/test_turn_terminal_reaction.py
@@ -0,0 +1,180 @@
+"""Terminal receipts (⏹️ stopped / ⚠️ interrupted) on the triggering message.
+
+A turn that emits a result needs no second receipt — the result IS the receipt,
+so finish() keeps its historical plain removal. A turn that ends WITHOUT one is
+ambiguous: a stop and a dead runtime both leave a message whose reaction simply
+vanished, which is also what a healthy silent completion looks like. These two
+emojis replace the running 👀 to say which happened. See
+core/processing_indicator.py.
+"""
+
+from __future__ import annotations
+
+import sys
+import unittest
+from pathlib import Path
+from types import SimpleNamespace
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+
+from core.processing_indicator import (
+ ACK_REACTION_EMOJI,
+ INTERRUPTED_REACTION_EMOJI,
+ STOPPED_REACTION_EMOJI,
+ ProcessingIndicatorHandle,
+ ProcessingIndicatorService,
+)
+from modules.im import MessageContext
+
+
+def _ctx(message_id="m1"):
+ return MessageContext(user_id="u1", channel_id="c1", message_id=message_id, platform="slack")
+
+
+class _FakeIM:
+ def __init__(self, *, remove_ok=True, remove_raises=False, rejected_emojis=()):
+ self.remove_ok = remove_ok
+ self.remove_raises = remove_raises
+ self.rejected_emojis = set(rejected_emojis)
+ self.calls: list[tuple[str, str, str]] = []
+
+ async def add_reaction(self, context, message_id, emoji):
+ self.calls.append(("add", message_id, emoji))
+ return emoji not in self.rejected_emojis
+
+ async def remove_reaction(self, context, message_id, emoji):
+ self.calls.append(("remove", message_id, emoji))
+ if self.remove_raises:
+ raise RuntimeError("platform rejected the removal")
+ return self.remove_ok
+
+ async def send_typing_indicator(self, context):
+ return True
+
+ async def clear_typing_indicator(self, context):
+ return True
+
+
+def _svc(im):
+ svc = ProcessingIndicatorService.__new__(ProcessingIndicatorService)
+ svc.controller = SimpleNamespace(get_im_client_for_context=lambda ctx: im, im_client=im)
+ svc.config = SimpleNamespace()
+ svc._indicators_by_turn_token = {}
+ return svc
+
+
+async def _running(svc, im):
+ handle = ProcessingIndicatorHandle(context=_ctx(), reaction_indicator_selected=True)
+ await svc.promote_reaction_to_running(handle)
+ im.calls.clear()
+ return handle
+
+
+class TerminalReactionOnFinishTests(unittest.IsolatedAsyncioTestCase):
+ async def test_stop_replaces_running_reaction_with_receipt(self):
+ im = _FakeIM()
+ svc = _svc(im)
+ handle = await _running(svc, im)
+
+ await svc.finish(handle, terminal_emoji=STOPPED_REACTION_EMOJI)
+
+ self.assertEqual(
+ im.calls,
+ [
+ ("remove", "m1", ACK_REACTION_EMOJI),
+ ("add", "m1", STOPPED_REACTION_EMOJI),
+ ],
+ )
+ # The handle is cleared either way — the receipt is not tracked state.
+ self.assertIsNone(handle.ack_reaction_emoji)
+ self.assertIsNone(handle.ack_reaction_message_id)
+
+ async def test_finish_without_terminal_emoji_only_removes(self):
+ # Regression guard: a turn that produced a result must not gain a receipt.
+ im = _FakeIM()
+ svc = _svc(im)
+ handle = await _running(svc, im)
+
+ await svc.finish(handle)
+
+ self.assertEqual(im.calls, [("remove", "m1", ACK_REACTION_EMOJI)])
+
+ async def test_receipt_is_skipped_when_removal_fails(self):
+ # Stacking ⏹️ on a 👀 that is still there would read as "running AND
+ # stopped". If the 👀 could not be retired, leave the message alone.
+ im = _FakeIM(remove_raises=True)
+ svc = _svc(im)
+ handle = await _running(svc, im)
+
+ await svc.finish(handle, terminal_emoji=STOPPED_REACTION_EMOJI)
+
+ self.assertEqual(im.calls, [("remove", "m1", ACK_REACTION_EMOJI)])
+ self.assertIsNone(handle.ack_reaction_emoji)
+
+ async def test_receipt_rejected_by_platform_still_clears_cleanly(self):
+ # WeChat-like: the terminal emoji is unsupported. The removal is what the
+ # bookkeeping is keyed on, so the indicator still ends cleared.
+ im = _FakeIM(rejected_emojis={STOPPED_REACTION_EMOJI})
+ svc = _svc(im)
+ handle = await _running(svc, im)
+
+ await svc.finish(handle, terminal_emoji=STOPPED_REACTION_EMOJI)
+
+ self.assertEqual(
+ im.calls,
+ [
+ ("remove", "m1", ACK_REACTION_EMOJI),
+ ("add", "m1", STOPPED_REACTION_EMOJI),
+ ],
+ )
+ self.assertIsNone(handle.ack_reaction_emoji)
+
+
+class OrphanedTerminalReactionTests(unittest.IsolatedAsyncioTestCase):
+ """Restart recovery has no handle — only the durable Delivery's message id."""
+
+ async def test_stamps_interrupted_over_stale_running_reaction(self):
+ im = _FakeIM()
+ svc = _svc(im)
+
+ stamped = await svc.stamp_orphaned_terminal_reaction(
+ _ctx(), "m1", INTERRUPTED_REACTION_EMOJI
+ )
+
+ self.assertTrue(stamped)
+ self.assertEqual(
+ im.calls,
+ [
+ ("remove", "m1", ACK_REACTION_EMOJI),
+ ("add", "m1", INTERRUPTED_REACTION_EMOJI),
+ ],
+ )
+
+ async def test_receipt_still_stamped_when_stale_reaction_is_gone(self):
+ # Unlike finish(), the two halves are independent here: recovery cannot
+ # know whether the 👀 ever landed, so a failed removal must not veto the
+ # notice-bearing receipt.
+ im = _FakeIM(remove_raises=True)
+ svc = _svc(im)
+
+ stamped = await svc.stamp_orphaned_terminal_reaction(
+ _ctx(), "m1", INTERRUPTED_REACTION_EMOJI
+ )
+
+ self.assertTrue(stamped)
+ self.assertEqual(im.calls[-1], ("add", "m1", INTERRUPTED_REACTION_EMOJI))
+
+ async def test_noop_without_a_message_id(self):
+ im = _FakeIM()
+ svc = _svc(im)
+
+ stamped = await svc.stamp_orphaned_terminal_reaction(
+ _ctx(), "", INTERRUPTED_REACTION_EMOJI
+ )
+
+ self.assertFalse(stamped)
+ self.assertEqual(im.calls, [])
+
+
+if __name__ == "__main__":
+ unittest.main()