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(delivery): render admission receipts on Lark and replace them instead of stacking (#1234)

Qi Qifb329ea40505
diff --git a/core/processing_indicator.py b/core/processing_indicator.py
index 362f4c31c..23d8549f8 100644
--- a/core/processing_indicator.py
+++ b/core/processing_indicator.py
@@ -47,16 +47,10 @@ _ADMISSION_ACK_REACTIONS: dict[str, str] = {
"reconciling_steer": UNCONFIRMED_REACTION_EMOJI,
"retired": NOT_DELIVERED_REACTION_EMOJI,
}
-# Receipts that can still be replaced or cleared later, and are therefore worth
-# remembering. The rest are final: the Delivery they describe never starts a turn
-# of its own, so nothing would ever read the entry back and keeping it would grow
-# the registry by one key per mid-turn message for the life of the process.
-_REPLACEABLE_ADMISSION_STATES = frozenset(
- {"queued", "pending_steer", "reconciling_steer"}
-)
-# Backstop for receipts whose Delivery never reaches a turn (a queue drained by a
-# Stop, a session archived mid-wait). Bounded FIFO eviction: dropping the oldest
-# key only forfeits a later replace/clear, never the reaction itself.
+# Backstop for receipts nothing ever reads back (a queue drained by a Stop, a
+# session archived mid-wait, a terminal ✍️/🤷 on a message no other Delivery
+# touches). Bounded FIFO eviction: dropping the oldest key only forfeits a later
+# replace/clear, never the reaction itself.
_ADMISSION_ACK_REGISTRY_LIMIT = 1024
# Registry marker for a message whose own turn has started. Kept so a receipt
# still in flight when the turn began cannot decorate it afterwards.
@@ -365,12 +359,14 @@ class ProcessingIndicatorService:
if not applied:
registry.pop(key, None)
return None
- if str(state or "").strip() in _REPLACEABLE_ADMISSION_STATES:
- self._remember_admission_ack(key, emoji)
- else:
- # Final receipt: the Delivery behind it never starts a turn, so
- # nothing will ever replace or clear this reaction.
- registry.pop(key, None)
+ # Every receipt is remembered, terminal ones included. A reaction
+ # target can be shared — a quick-reply callback reacts on its bot
+ # echo, so two Deliveries settle on one message — and a platform
+ # shows one reaction per (message, emoji, bot). The receipt therefore
+ # describes the message rather than any one Delivery: last writer
+ # wins, and the previous receipt is removed instead of stacked. The
+ # FIFO cap bounds what a terminal receipt leaves behind.
+ self._remember_admission_ack(key, emoji)
return emoji
async def clear_admission_ack(self, context: MessageContext) -> None:
diff --git a/docs/plans/im-delivery-admission-ack.md b/docs/plans/im-delivery-admission-ack.md
index d8258431a..871d46af2 100644
--- a/docs/plans/im-delivery-admission-ack.md
+++ b/docs/plans/im-delivery-admission-ack.md
@@ -74,10 +74,21 @@ before the turn's own indicator takes over — a promoted Delivery is
re-dispatched with its original native message id (`_hydrate_delivery_context`),
so 👌 and 👀 would otherwise land on the same message.
-Only *replaceable* states (`queued`, `pending_steer`, `reconciling_steer`) are
-remembered. A final receipt (✍️ / 🤷) is never cleared, so keeping its key would
-leak one entry per message for the life of the process; a FIFO cap
-(`_ADMISSION_ACK_REGISTRY_LIMIT`) backstops the replaceable ones.
+Every receipt is remembered, terminal ✍️ / 🤷 included. `accepted` and `retired`
+are terminal in the state matrix, so one Delivery never moves off its own final
+receipt — but the reaction *target* can be shared. A quick-reply callback reacts
+on its bot echo (§3.4), so a second click settles on a message the first already
+decorated, and a platform shows one reaction per (message, emoji, bot). The
+receipt therefore describes the message rather than any one Delivery: last writer
+wins, the previous receipt is removed instead of stacked, and `start()` can clear
+a stale one. Per-Delivery receipts were the alternative and buy nothing — two
+Deliveries wanting the same emoji on one message collapse to a single reaction
+anyway, and the display cannot represent two states at once.
+
+Nothing reads back a receipt on a message no other Delivery touches, so the FIFO
+cap (`_ADMISSION_ACK_REGISTRY_LIMIT`) is what keeps those entries from living for
+the life of the process. Evicting the oldest only forfeits a later replace or
+clear, never the reaction itself.
A receipt and the turn start it races are serialized per message key by a
refcounted `asyncio.Lock`, and `clear_admission_ack` writes an
@@ -117,10 +128,12 @@ keys.
- `slack.py`: `writing_hand`, `thinking_face`, `shrug` added.
- `telegram.py`: `✍️ → ✍` normalization; 👌/🤔/🤷 pass through.
- `discord.py`: raw unicode, no change.
-- `feishu.py`: 🤔 already maps to `THINKING`. ✍️ and 🤷 are deliberately left
- unmapped rather than guessed — `add_reaction` logs the exact "add it to
- `_EMOJI_MAP`" warning and returns `False`, so Lark degrades to no receipt for
- those two until the `emoji_type` keys are verified against the Lark table.
+- `feishu.py`: 🤔 already maps to `THINKING`; ✍️ → `Typing` and 🤷 → `Shrug`,
+ both verified against the Lark `emoji_type` table (Lark has no writing-hand
+ glyph, so `Typing` — the pen/being-written-into icon — carries the steered
+ receipt). Both `✍️` and `✍` are listed because `_normalize_emoji` does not
+ strip U+FE0F. `emoji_type` keys are case-sensitive: an unmapped emoji stays
+ non-ASCII, so `add_reaction` logs the "add it to `_EMOJI_MAP`" warning.
### 3.5 Reporting outcomes that settle away from ingress
@@ -146,8 +159,14 @@ react is logged and never blocks the Delivery.
- Receipts are best-effort and in-memory: after a restart a stale 👌 is not
cleared by `start()`. On Telegram the reaction is replaced anyway; on Slack it
can linger until the next turn on that message.
-- The ✍️ receipt is intentionally permanent. It records which turn absorbed the
- message, which stays useful after the reply arrives.
+- The ✍️ receipt outlives its own Delivery — nothing clears it, because a steered
+ input never dispatches a turn of its own — so it keeps recording which turn
+ absorbed the message. It is not *permanent*: another Delivery settling on the
+ same reaction target replaces it (§3.2).
+- Removing a receipt is precise on Slack and Lark, but Telegram's
+ `remove_reaction` clears every reaction on the message
+ (`telegram_api.clear_message_reaction` ignores the emoji), so replacing a
+ receipt there also drops a coexisting 🤖.
## 5. Evidence
@@ -157,5 +176,8 @@ react is logged and never blocks the Delivery.
(MESSAGE-DELIVERY-303, 306, 307, 308, 309)
- regression: `tests/test_processing_indicator_reaction.py`,
`tests/test_session_delivery_fsm.py`, `tests/scenarios/message_delivery/`
+- platform mappings: `tests/test_feishu_reaction_emoji.py` pins each Lark
+ `emoji_type` against the published table and asserts every receipt the agent
+ sends has one
- manual: send a second and third message on Telegram/Slack while a turn runs;
confirm ✍️ for a steered input, 👌 → 👀 for a queued one.
diff --git a/modules/im/feishu.py b/modules/im/feishu.py
index cf76567ff..3e5e62975 100644
--- a/modules/im/feishu.py
+++ b/modules/im/feishu.py
@@ -48,6 +48,14 @@ _EMOJI_MAP: Dict[str, str] = {
"🤖": "SMART",
"ok_hand": "OK",
"👌": "OK",
+ # Admission receipts: ✍️ steered, 🤷 not delivered. Lark has no writing-hand
+ # glyph — ``Typing`` (emoji_typing) is its "being written into" equivalent.
+ # Both forms of ✍️ are listed: _normalize_emoji does not strip U+FE0F.
+ "writing_hand": "Typing",
+ "✍️": "Typing",
+ "✍": "Typing",
+ "shrug": "Shrug",
+ "🤷": "Shrug",
"thumbsup": "THUMBSUP",
"👍": "THUMBSUP",
"+1": "THUMBSUP",
@@ -58,14 +66,15 @@ _EMOJI_MAP: Dict[str, str] = {
"check": "OK",
"white_check_mark": "OK",
"✅": "OK",
- "x": "CROSSMARK",
- "❌": "CROSSMARK",
- "rocket": "ROCKET",
- "🚀": "ROCKET",
+ "x": "CrossMark",
+ "❌": "CrossMark",
+ # Lark has no rocket reaction; ``GoGoGo`` carries the same "ship it" intent.
+ "rocket": "GoGoGo",
+ "🚀": "GoGoGo",
"smile": "SMILE",
"😄": "SMILE",
- "fire": "FIRE",
- "🔥": "FIRE",
+ "fire": "Fire",
+ "🔥": "Fire",
"clap": "APPLAUSE",
"👏": "APPLAUSE",
"muscle": "MUSCLE",
diff --git a/tests/test_delivery_ack_reaction.py b/tests/test_delivery_ack_reaction.py
index 992c2b053..c83f3c7ec 100644
--- a/tests/test_delivery_ack_reaction.py
+++ b/tests/test_delivery_ack_reaction.py
@@ -315,30 +315,61 @@ class AdmissionAckTests(unittest.IsolatedAsyncioTestCase):
self.assertIsNone(applied)
self.assertEqual(im.calls, [])
- async def test_final_receipts_do_not_accumulate_registry_entries(self):
- # accepted/retired deliveries never start a turn, so nothing would ever
- # read these entries back; keeping them grows the registry by one key
- # per mid-turn message for the life of the process.
+ async def test_terminal_receipt_is_replaced_rather_than_stacked(self):
+ # Two Deliveries can share one reaction target: a quick-reply callback
+ # reacts on its bot echo, so a second click settles on the message a
+ # first one already decorated. A platform shows one reaction per
+ # (message, emoji, bot), so the receipt describes the message — the
+ # terminal ✍️ is removed rather than left next to the new 👌.
im = _FakeIM()
svc = _svc(im)
+ context = _ctx(message_id="echo-7")
- for index in range(5):
- await svc.ack_delivery_state(
- _ctx(message_id=f"steered-{index}"),
- state="accepted",
- admission="steered",
- )
- await svc.ack_delivery_state(_ctx(message_id=f"retired-{index}"), state="retired")
+ await svc.ack_delivery_state(context, state="accepted", admission="steered")
+ await svc.ack_delivery_state(context, state="queued")
+
+ self.assertEqual(
+ im.calls,
+ [
+ ("add", "echo-7", STEERED_REACTION_EMOJI),
+ ("remove", "echo-7", STEERED_REACTION_EMOJI),
+ ("add", "echo-7", QUEUED_REACTION_EMOJI),
+ ],
+ )
+
+ async def test_terminal_receipt_is_cleared_when_a_turn_takes_the_message(self):
+ # Same shared-target case, other ordering: the second Delivery is the one
+ # that dispatches, so its turn's own indicator replaces the stale ✍️.
+ im = _FakeIM()
+ svc = _svc(im)
+ context = _ctx(message_id="echo-7")
+
+ await svc.ack_delivery_state(context, state="retired")
+ await svc.clear_admission_ack(context)
- self.assertEqual(svc._admission_acks, {})
- self.assertEqual(len(im.calls), 10)
+ self.assertEqual(
+ im.calls,
+ [
+ ("add", "echo-7", NOT_DELIVERED_REACTION_EMOJI),
+ ("remove", "echo-7", NOT_DELIVERED_REACTION_EMOJI),
+ ],
+ )
- async def test_replaceable_receipts_are_bounded(self):
+ async def test_receipts_are_bounded(self):
+ # Terminal receipts are remembered too, so the FIFO cap is the only thing
+ # keeping one entry per mid-turn message from living for the life of the
+ # process. Evicting the oldest only forfeits a later replace or clear.
im = _FakeIM()
svc = _svc(im)
for index in range(_ADMISSION_ACK_REGISTRY_LIMIT + 10):
await svc.ack_delivery_state(_ctx(message_id=f"q-{index}"), state="queued")
+ for index in range(_ADMISSION_ACK_REGISTRY_LIMIT + 10):
+ await svc.ack_delivery_state(
+ _ctx(message_id=f"s-{index}"),
+ state="accepted",
+ admission="steered",
+ )
self.assertLessEqual(len(svc._admission_acks), _ADMISSION_ACK_REGISTRY_LIMIT)
diff --git a/tests/test_feishu_reaction_emoji.py b/tests/test_feishu_reaction_emoji.py
new file mode 100644
index 000000000..d3113695c
--- /dev/null
+++ b/tests/test_feishu_reaction_emoji.py
@@ -0,0 +1,86 @@
+"""Lark reaction ``emoji_type`` mappings.
+
+Lark rejects an unknown ``emoji_type`` with a parameter error, and the keys are
+**case-sensitive**: a plausible-looking ``FIRE`` or ``CROSSMARK`` fails exactly
+like a typo, silently, because ``add_reaction`` only warns when the normalized
+value is non-ASCII. Every expectation below was read off the published table
+(https://open.feishu.cn/document/server-docs/im-v1/message-reaction/emojis-introduce)
+rather than guessed from the unicode name.
+"""
+
+import sys
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT))
+
+from core.processing_indicator import ( # noqa: E402
+ ACK_REACTION_EMOJI,
+ NOT_DELIVERED_REACTION_EMOJI,
+ QUEUED_REACTION_EMOJI,
+ STEERED_REACTION_EMOJI,
+ UNCONFIRMED_REACTION_EMOJI,
+)
+from core.handlers.message_handler import SUBAGENT_REACTION_EMOJI # noqa: E402
+from modules.im.feishu import _EMOJI_MAP, _normalize_emoji # noqa: E402
+
+# unicode emoji -> the exact emoji_type Lark publishes for it.
+VERIFIED_EMOJI_TYPES = {
+ "👀": "OnIt",
+ "🤖": "SMART",
+ "👌": "OK",
+ "✍️": "Typing",
+ "✍": "Typing",
+ "🤷": "Shrug",
+ "🤔": "THINKING",
+ "👍": "THUMBSUP",
+ "👎": "ThumbsDown",
+ "❤️": "HEART",
+ "✅": "OK",
+ "❌": "CrossMark",
+ "🚀": "GoGoGo",
+ "😄": "SMILE",
+ "🔥": "Fire",
+ "👏": "APPLAUSE",
+ "💪": "MUSCLE",
+ "🎉": "PARTY",
+}
+
+
+class FeishuReactionEmojiTests(unittest.TestCase):
+ def test_normalizes_to_published_emoji_types(self):
+ for emoji, emoji_type in VERIFIED_EMOJI_TYPES.items():
+ with self.subTest(emoji=emoji):
+ self.assertEqual(_normalize_emoji(emoji), emoji_type)
+
+ def test_every_reaction_the_agent_sends_is_mapped(self):
+ """An unmapped receipt degrades to no reaction at all on Lark.
+
+ ``_normalize_emoji`` falls through to ``.upper()``, so a missing entry
+ ships the raw codepoint as the ``emoji_type`` and the user simply never
+ sees the receipt. Pin the set the agent actually sends.
+ """
+
+ for emoji in (
+ ACK_REACTION_EMOJI,
+ QUEUED_REACTION_EMOJI,
+ STEERED_REACTION_EMOJI,
+ UNCONFIRMED_REACTION_EMOJI,
+ NOT_DELIVERED_REACTION_EMOJI,
+ SUBAGENT_REACTION_EMOJI,
+ ):
+ with self.subTest(emoji=emoji):
+ self.assertIn(emoji, _EMOJI_MAP)
+ self.assertTrue(_normalize_emoji(emoji).isascii())
+
+ def test_variation_selector_forms_share_one_mapping(self):
+ """``_normalize_emoji`` strips colons and whitespace, not U+FE0F."""
+
+ self.assertEqual(_normalize_emoji("✍️"), _normalize_emoji("✍"))
+ self.assertEqual(_normalize_emoji(":writing_hand:"), "Typing")
+ self.assertEqual(_normalize_emoji(":shrug:"), "Shrug")
+
+
+if __name__ == "__main__":
+ unittest.main()