Skip to content

fix(feishu): serialize message handling per chat to prevent skipped messages#31807

Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom
Sid-Qin:fix/31727-feishu-message-queue
Mar 2, 2026
Merged

fix(feishu): serialize message handling per chat to prevent skipped messages#31807
Takhoffman merged 2 commits intoopenclaw:mainfrom
Sid-Qin:fix/31727-feishu-message-queue

Conversation

@Sid-Qin
Copy link
Contributor

@Sid-Qin Sid-Qin commented Mar 2, 2026

Summary

  • Problem: When multiple Feishu messages arrive rapidly in the same group chat, the agent may only process the latest message and silently skip earlier ones. This happens because fireAndForget: true dispatches all messages concurrently — when message B arrives while message A is still being processed, they race through handleFeishuMessage and the agent may only respond to B.
  • Why it matters: Users in group chats lose messages without any indication. The agent appears to randomly ignore questions.
  • What changed: extensions/feishu/src/monitor.account.ts — added a createChatQueue() utility that creates a per-chat serial queue. Messages from the same chat_id are now processed in FIFO order (each waits for the previous one to complete). Messages from different chats still run concurrently for performance.
  • What did NOT change: Reaction handling, card action handling, bot-added events, and the dedup logic in bot.ts are all untouched. The fireAndForget pattern is preserved — the queue just serializes within a chat.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Feishu group chat messages are now processed in order per chat — no more silently skipped messages when users send rapidly

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Any
  • Runtime: Node.js
  • Integration/channel: Feishu (group chat)

Steps

  1. Send message A in a Feishu group chat at 17:14
  2. Immediately send message B at 17:14 (within seconds)
  3. Wait for agent to finish processing

Expected

  • Both messages A and B are processed in order

Actual

  • Before fix: Agent only processes message B, message A is silently skipped
  • After fix: Agent processes message A first, then message B (FIFO per chat)

Evidence

// Before: all messages dispatched concurrently
const promise = handleFeishuMessage({ event, ... });
if (fireAndForget) {
  promise.catch(...); // fire and forget — no ordering guarantee
}

// After: per-chat serial queue
const chatId = event.message?.chat_id ?? "unknown";
const task = () => handleFeishuMessage({ event, ... });
if (fireAndForget) {
  enqueue(chatId, task).catch(...); // serialized within same chat
}

The queue cleans up automatically when the chain for a chat_id completes.

Human Verification (required)

  • Verified scenarios: TypeScript compilation passes (npx tsc --noEmit)
  • Edge cases checked: Unknown chat_id defaults to "unknown" (serialized as a single queue), queue map cleanup on chain completion prevents memory leaks, error in one task does not block the next (.then(task, task) pattern)
  • What I did not verify: End-to-end Feishu group chat test with rapid messages

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert: Revert the single commit. Messages will go back to concurrent processing.
  • Files/config to restore: extensions/feishu/src/monitor.account.ts
  • Known bad symptoms: If the queue serialization causes a slow message to block subsequent ones — but this is the correct behavior (processing in order)

Risks and Mitigations

  • Risk: A slow-processing message blocks subsequent messages in the same chat. Mitigation: This is the intended behavior — messages should be processed in order. Cross-chat concurrency is preserved.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Fixed Feishu group chat message skipping by adding per-chat serial queue - messages from the same chat_id now process in FIFO order while different chats remain concurrent.

Implementation:

  • Added createChatQueue() utility that chains promises per chat_id using Map<string, Promise<void>>
  • Queue cleanup prevents memory leaks - removes completed chains automatically
  • Error handling preserves queue progress - failed tasks don't block subsequent messages (.then(task, task) pattern)
  • Fallback chat_id: "unknown" for edge cases ensures serialization even without chat ID

Scope:

  • Only changed im.message.receive_v1 handler per design
  • Reactions, card actions, and bot-added events unchanged (process concurrently as before)

Correctness verified:

  • Promise chaining logic correctly serializes per-chat while preserving cross-chat concurrency
  • Race condition in cleanup handled correctly - only deletes if still the latest promise
  • TypeScript types align - handleFeishuMessage returns Promise<void> matching queue signature

Confidence Score: 5/5

  • This PR is safe to merge - well-contained bug fix with sound implementation
  • Queue implementation is correct (proper promise chaining, cleanup logic prevents memory leaks, error handling preserves progress). Change is minimal and focused (single file, 20 lines). No security concerns (no new permissions, tokens, or network calls). Backward compatible (preserves fireAndForget pattern). Clear correctness: serializes same-chat messages while preserving cross-chat concurrency as designed.
  • No files require special attention

Last reviewed commit: 58b2127

SidQin-cyber and others added 2 commits March 2, 2026 17:12
…essages

With fireAndForget=true, all incoming Feishu messages are dispatched
concurrently.  When multiple messages arrive rapidly in the same group
chat, they race through handleFeishuMessage and the agent may only
process the latest one, silently dropping earlier messages.

Add a per-chat serial queue (createChatQueue) that ensures messages
from the same chat_id are processed in FIFO order.  Messages from
different chats still run concurrently for performance.

Closes openclaw#31727
@Takhoffman Takhoffman force-pushed the fix/31727-feishu-message-queue branch from 58b2127 to d922b38 Compare March 2, 2026 23:13
@Takhoffman Takhoffman merged commit 350d041 into openclaw:main Mar 2, 2026
9 checks passed
@Takhoffman
Copy link
Contributor

PR #31807 - fix(feishu): serialize message handling per chat to prevent skipped messages (#31807)

Merged after verification.

  • Merge commit: 350d041
  • Verified: pnpm install --frozen-lockfile, pnpm build, pnpm check (with unrelated pre-existing TypeScript failure in src/browser/chrome.ts)
  • Autoland updates:
    M\textensions/feishu/src/monitor.account.ts
    M\tCHANGELOG.md
  • Rationale:
    Rebased onto current main and resolved monitor.account conflict by composing per-chat queue serialization with the already-landed inbound debounce path.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
…essages (openclaw#31807) thanks @Sid-Qin

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check (fails on unrelated pre-existing TypeScript error in src/browser/chrome.ts)

Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
…essages (openclaw#31807) thanks @Sid-Qin

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check (fails on unrelated pre-existing TypeScript error in src/browser/chrome.ts)

Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…essages (openclaw#31807) thanks @Sid-Qin

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check (fails on unrelated pre-existing TypeScript error in src/browser/chrome.ts)

Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu群聊中多条消息快速进入时,旧消息可能被跳过不处理

2 participants