fix(feishu): support bot-to-bot group mentions - #29662
Conversation
dce4c9a to
2127c4f
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Feishu reliability work. The underlying outbound-mention and bare-ID issues are still present on current main, but this needs a careful port.
Problems
- The alias regex at
gateway/platforms/feishu.py:647only checks the character after an alias.user@MOSS.comtherefore matches@MOSSbecause.is allowed, despite the stated email-safety goal. - The new p2p return at
gateway/platforms/feishu.py:4110must preserve main's current p2p pairing/allowlist checks atplugins/platforms/feishu/adapter.py:4256-4268when salvaged. - The live adapter moved to
plugins/platforms/feishu/adapter.pyin5600105478ffde29d7566b45421b100eaa29c4ef.
Suggested changes
- Port the implementation to the bundled plugin, add a left-boundary email regression, and layer DM disabling ahead of the existing p2p authorization path.
Automated hermes-sweeper review.
| if not names: | ||
| return [{"tag": text_tag, "text": text}] | ||
| pattern = re.compile( | ||
| r"@(" + "|".join(re.escape(name) for name in names) + r")(?=$|[\s\t\n\r.,;:!?、,。;:!?()\[\]{}<>\"'`])" |
There was a problem hiding this comment.
This only checks the trailing boundary. With alias MOSS, user@MOSS.com matches because . is allowed here, so an email address is converted into an at entity despite the email-safety claim. Add a preceding boundary check and a regression test.
| @@ -3965,6 +4108,8 @@ def _admit(self, sender: Any, message: Any) -> Optional[RejectReason]: | |||
| return "bot_not_mentioned" | |||
|
|
|||
| if not is_group: | |||
There was a problem hiding this comment.
When salvaging this onto current main, keep the existing p2p pairing/allowlist checks after this policy rejection. Current main performs those checks in plugins/platforms/feishu/adapter.py:4256-4268; returning unconditionally here after the disabled check would bypass them.
2127c4f to
b99c6c1
Compare
|
Ported and force-pushed this PR onto current Addressed the sweeper/admin feedback:
Validation on the rebased branch: The PR is now mergeable from GitHub's perspective. |
|
Adding a code map for maintainers/admins so the test files in this PR are easier to orient around. Why the
|
|
For maintainers reviewing the code changes, here is the shortest file-by-file map of the implementation.
|
b99c6c1 to
65e9c5a
Compare
|
Rebased and force-pushed this branch onto current Current head: GitHub now reports:
I rechecked the admin/sweeper requirements after the rebase:
Validation on the rebased branch: |
Summary
Adds the missing Feishu/Lark gateway pieces needed for trusted Hermes bot-to-bot collaboration in group chats:
FEISHU_MENTION_ALIASES/FEISHU_OUTBOUND_MENTION_ALIASES, converting configured@Namealiases into Feishupostatentities..envbeforesend_messageconstructs a Feishu adapter, so cron/tool-driven Feishu sends see the same mention-alias configuration as the gateway process.FEISHU_DM_POLICY=disabledfor agents that should participate only in groups and ignore direct Feishu DMs.ou_...oru_...string withoutid_type, so strict group mention admission can still recognize the receiving bot.Problem
Hermes Feishu bots can be placed together in shared collaboration groups, but the existing behavior made agent-to-agent handoff unreliable:
@MOSS please inspectwas sent as literal text, not a native Feishu mention, so the receiving bot was not necessarily notified or admitted by mention-gated group logic.send_messagecalls from non-gateway processes did not necessarily load profile-local Feishu mention aliases before building the adapter.FEISHU_REQUIRE_MENTION=true/ bot-to-bot mention gates to drop otherwise valid messages.Solution
{"tag": "at", "user_id": ..., "user_name": ...}for matching aliases.postpayloads when an outbound native mention is present; use plaintextelements inside that post where needed so table-shaped content does not force a downgrade.get_hermes_home() / ".env"in the Feishusend_messagepath before constructing the adapter.FEISHU_DM_POLICYparsing and admission handling (openby default,disabledto reject p2p messages)._extract_mention_ids()and reuse that logic in_message_mentions_bot()so bareou_.../u_...mention strings are recognized.Related issues
Refs #21366 — the bare-ID normalization addresses one concrete Feishu mention-shape case where the gateway mention gate can misclassify a valid bot mention.
Refs #25728 — this does not implement message buffering, but it improves the underlying Feishu group-mention reliability needed for mention-triggered group workflows.
Refs #29245 — this does not fully solve Markdown table rendering, but it prevents table-shaped content from forcing a plain-text downgrade when a native Feishu @mention must be preserved.
Refs #17847 — related multi-bot Feishu safety context; this PR keeps bot sender admission opt-in and improves diagnostics rather than broadly processing all bot-originated events.
Tests
Focused tests run locally:
python -m pytest tests/gateway/test_feishu.py::TestFeishuOutboundMentions tests/gateway/test_feishu_bot_admission.py -q -o 'addopts='Result:
The covered cases include:
atrich-text entities;FEISHU_DM_POLICYparsing, defaulting, and invalid-value warning behavior;ou_...andu_...mention IDs;allow_bots=mentionsand strict mention gating.