feat(gateway): feishu multibot-mentions mode#746
feat(gateway): feishu multibot-mentions mode#746wangyuyan-agent wants to merge 6 commits intoopenabdev:mainfrom
Conversation
Once the bot replies in a thread, subsequent messages in that thread bypass @mention gating — matching Discord's default 'involved' mode. - Add participated_threads cache (HashMap<thread_id, Instant>) - Bypass mention gating when message is in a participated thread - Record participation on successful reply to a thread - TTL controlled by FEISHU_SESSION_TTL_HOURS (default 24h) - Cache eviction at 1000 entries (oldest-half strategy) - 3 new tests for participation logic
be3af5d to
7f99f4c
Compare
- Extract check_thread_participated() helper to reduce duplication - Add comments explaining intentional poisoned-mutex recovery - Improve eviction: drop TTL-expired entries first, then oldest half
7f99f4c to
764515f
Compare
OpenAB PR ScreeningThis is auto-generated by the OpenAB project-screening flow for context collection and reviewer handoff.
Screening report## IntentPR #746 adds a Feishu gateway mode that prevents multiple OpenAB bots from auto-responding in the same Feishu thread after another bot is mentioned. The operator-visible problem is Feishu’s weaker bot identity signals: unlike Discord, Feishu does not reliably expose bot messages or bot sender metadata to other apps, so the gateway needs a Feishu-specific way to avoid multi-bot response collisions. FeatFeature: gateway behavior change for Feishu. It introduces It also documents the new mode and adds tests around parsing and multibot detection behavior. Who It ServesPrimary beneficiaries: Feishu deployers and agent runtime operators running multiple OpenAB bots in the same workspace. Secondary beneficiaries: Feishu end users, because threads should no longer get duplicate or competing bot replies after multiple bots become involved. Rewritten PromptImplement Feishu Add support for
For Feishu only, mark a participated thread as multibot when an incoming user message contains an Persist behavior only in gateway memory unless existing Feishu thread state already has a durable storage pattern. Add focused tests for env parsing, detection precedence, participated-thread gating, and same-message enforcement. Update Merge PitchThis is worth advancing because it addresses a real multi-bot Feishu deployment failure mode with a gateway-local change and no new Feishu permissions. The feature aligns Feishu behavior more closely with Discord’s Risk profile: moderate. The core concern is false-positive multibot detection when non-bot users are mentioned but not listed in Best-Practice ComparisonRelevant OpenClaw principles:
Relevant Hermes Agent principles:
The proposed direction fits the reference systems where they emphasize gateway-owned coordination. It does not yet match OpenClaw’s stronger durability and isolation model, but that may be acceptable for a Feishu-specific heuristic mode. Implementation OptionsConservative option: merge only explicit-ID detection. Support Balanced option: merge the fallback-chain heuristic as proposed. Use explicit trusted IDs when available, then infer from Ambitious option: introduce durable Feishu thread coordination state. Persist participated and multibot thread state across gateway restarts, with atomic writes or existing storage primitives if available. Add operational logs for when a thread is marked multibot and why. This improves reliability and debuggability but broadens the PR beyond the immediate feature. Comparison Table
RecommendationAdvance the balanced option. The proposed fallback-chain approach is the right next merge discussion because it solves the practical Feishu deployment problem without requiring new permissions or a larger gateway persistence design. The main merge condition should be clear documentation of the heuristic and focused tests showing that multibot marking only happens in participated threads and applies to the same incoming message. If reviewers are uncomfortable with inference risk, split the work: first merge |
|
LGTM ✅ — Well-designed multi-bot collision avoidance for Feishu. The inference-based detection is pragmatic given Feishu's per-app open_id limitation. Ready to merge once #744 lands. 📋 Review — Four Questions1. What problem does this solve?In multi-bot Feishu deployments using "involved" mode (#744), all bots that have participated in a thread respond to every message — causing duplicate/conflicting replies. This PR adds 2. How does it solve it?
3. What alternatives were considered?PR description documents three approaches:
Also documents why Discord's 4. Is this the best approach?Yes, with minor observations: 🟢 INFO — Excellent design decisions:
🟡 NIT — Non-blocking suggestions:
🔍 Baseline Check (Step 0)
|
|
to fix the NITs |
- Add comment clarifying session_ttl_secs=0 disables participation tracking - Update bot_turns comment: remove TODO, note existing eviction pattern
Add AllowUsers enum (Involved/Mentions/MultibotMentions) controlled by FEISHU_ALLOW_USER_MESSAGES env var. In multibot-mentions mode, once another bot is @mentioned in a participated thread, require @mention for all bots — prevents multiple bots from responding simultaneously. Multibot detection strategy: - If FEISHU_TRUSTED_BOT_IDS configured: exact match - Otherwise: infer from allowed_users (mention not self and not in allowed_users → assumed to be another bot) - Only triggers in threads where bot has already participated This avoids requiring users to discover per-app open_ids for other bots.
764515f to
e612e25
Compare
|
All three nits addressed in e612e25:
|
chaodu-agent
left a comment
There was a problem hiding this comment.
All three NITs addressed ✅ — eviction, double-lock, and webhook parity. CI green. Ready to merge after #744 lands.
Deduplicate the multibot detection block (~30 lines) that was repeated in both handle_ws_message and webhook(). Both now call a shared detect_and_mark_multibot() helper that handles: - Thread participation check - @mention-based other-bot detection (trusted IDs or inference) - Multibot cache marking with eviction - Computing is_thread_participated based on allow_user_messages mode Also update PARTICIPATION_CACHE_MAX comment to note it is intentionally shared between participated_threads and multibot_threads caches.
obrutjack
left a comment
There was a problem hiding this comment.
PR Review (Stage 2 — Second Review): #746
Summary
- Problem: Multi-bot Feishu deployments using "involved" mode cause all participated bots to respond simultaneously
- Approach: Fallback-chain heuristic detecting other bots via @mentions, with in-memory thread state
- Risk level: Low-Medium
Core Assessment
- Problem clearly stated: ✅
- Approach appropriate: ✅
- Alternatives considered: ✅
- Best approach for now: ✅
Verification of chaodu-agent's Review (e612e25)
- ✅ multibot_threads eviction — TTL-based eviction with PARTICIPATION_CACHE_MAX
- ✅ Double mutex lock — self_participated computed once, reused
- ✅ Webhook path parity — Now shares detect_and_mark_multibot() helper
Additional Findings
🟢 INFO
- parse_message_event is now a pure function — good testability
- Poisoned-mutex recovery correct for a cache
- 7 new tests cover key paths
- detect_and_mark_multibot() helper (6bca9e1) eliminates WS/webhook duplication
- PARTICIPATION_CACHE_MAX comment explains shared usage
🟡 NIT
- Race window on gateway restart — caches empty after restart; previously-multibot thread temporarily allows responses until re-detected. Documented and acceptable for v1.
🔴 SUGGESTED CHANGES
- None.
Dependency Note
Must merge #744 first.
Verdict
APPROVE — No blockers. Ready to merge after #744 lands.
🟡 Review: feat(gateway): feishu multibot-mentions modeVerdict: Good design, but has a blocking dependency issue. What this PR doesAdds 🔴 SUGGESTED CHANGES1. Dependency PR #744 is NOT merged PR #744 ("feishu thread participation tracking") is still OPEN. This PR targets
2. The eviction path in 🟡 NIT
🟢 INFO — Done well
Baseline verificationVerified against
Reviewed by 超渡法師 🪬 |
🟡 Solid design — minor items before mergeVerdict: Well-designed multibot detection for Feishu's unique constraints. The @mention-based inference is a pragmatic solution given the platform's lack of bot identity flags. Blocked on #744 merge. 四問框架 Review1. What problem does it solve?In multi-bot Feishu threads, all participated bots respond simultaneously when a user sends a message (since "involved" mode bypasses @mention). Discord solves this with 2. How does it solve it?
3. What was considered?
4. Is this the best approach?🟢 INFO — What's done well
🟡 NIT — Non-blocking suggestions
🔴 SUGGESTED — Consider addressing
/// Whether the bot should bypass @mention gating for this message.
/// This is the final computed result from `detect_and_mark_multibot()`,
/// already accounting for the configured `allow_user_messages` mode.
/// Do NOT pass raw participation status here.
fn parse_message_event(
...
is_thread_participated: bool, // ← rename to `bypass_mention_gating`?
) -> ...Blocked on: #744 (thread participation tracking) — must merge first. Review by 超渡法師 · 四法師 collaborative review in progress |
1. session_ttl_secs doc comment: clarify conversion from FEISHU_SESSION_TTL_HOURS 2. Rename is_thread_participated → bypass_mention_gating in parse_message_event with doc comment explaining the parameter semantics
|
NITs and suggested change addressed in 2ab7577:
|
✅ Review Complete — Approved (pending #744 merge)Verdict: LGTM — All previous review items addressed. Ready to merge once dependency #744 lands. 📋 Four-Question Framework1. What problem does it solve?In multi-bot Feishu deployments, all participated bots respond simultaneously to every message in a thread. Unlike Discord (which has 2. How does it solve it?
3. What was considered?
4. Is this the best approach?Yes. The fallback chain is pragmatic — most deployments already have Traffic Light🟢 INFO — Done well:
🟡 NIT — Non-blocking (acknowledged, acceptable for v1):
🔴 SUGGESTED CHANGES — None remaining. All previous items addressed. DependencyReviewed by 超渡法師 🪬 · Final review after 3 rounds of feedback |
PR Draft: feat(gateway): feishu multibot-mentions mode
Title
Summary
Follow-up to #744. Adds
multibot-mentionsmode: once another bot is @mentioned in a participated thread, all bots revert to requiring @mention — preventing multiple bots from responding simultaneously.Multibot detection (how "is thread multibot?" is determined):
"Other bot" identification:
Prior Art
allow_user_messages: multibot-mentionsmsg.author.botflag — Discord explicitly marks bot messagesKey difference from Discord
Discord can detect other bots trivially via
msg.author.botflag. Feishu has two problems:sender_typeis always"user"for other botsSo we cannot use Discord's approach. We detect via @mentions in user messages instead.
Feishu API Fact-Check
Per-App open_id problem
Feishu assigns different open_ids to the same entity depending on which app is observing:
FEISHU_TRUSTED_BOT_IDSimpractical — users would need to discover cross-app open_ids from debug logsVerified by testing: Bot2's self-reported open_id is
ou_228fbf2af502d0ba3203778f16162cdd, but Bot1 sees Bot2 asou_f15beb3b9d1af4e9dbf6983880325a2bin @mention events.No new permissions needed
The feature is purely gateway-side logic operating on data already available in message events.
Design Decisions
Why inference mode (zero-config) as default
FEISHU_TRUSTED_BOT_IDSonlyallowed_usersWe chose the fallback chain: explicit IDs take priority, inference as fallback. In practice, most deployments have
FEISHU_ALLOWED_USERSset (it's the standard access control), so inference works out of the box.Why only detect in participated threads
Without this guard, Bot2 would see
@bot1in a thread it hasn't joined and prematurely mark it as multibot — blocking itself from ever responding when later @mentioned. The rule: you can't have an opinion about a conversation you haven't joined.Why detection happens before participation check
The @mention that triggers multibot detection must take effect on the same message — otherwise the bot would respond one extra time before going silent. We extract mentions from the raw envelope before
parse_message_eventruns.Changes
gateway/src/adapters/feishu.rsAllowUsersenum,FEISHU_ALLOW_USER_MESSAGESparsing,multibot_threadscache, inference-based detection, 3 new testsdocs/feishu.mdFEISHU_ALLOW_USER_MESSAGESenv var, multibot-mentions behavior docsTesting (two-bot setup, both running this code)
cargo test— 102 passedNew Environment Variable
FEISHU_ALLOW_USER_MESSAGESinvolvedinvolved/mentions/multibot-mentionsDepends On
Discord Discussion URL
https://discord.com/channels/1491295327620169908/1500160821567684660