Skip to content

fix: ack Feishu messages before async processing#77

Open
xuli500177 wants to merge 1 commit into
NeverMore93:mainfrom
xuli500177:fix/ack-feishu-message-before-processing
Open

fix: ack Feishu messages before async processing#77
xuli500177 wants to merge 1 commit into
NeverMore93:mainfrom
xuli500177:fix/ack-feishu-message-before-processing

Conversation

@xuli500177
Copy link
Copy Markdown

@xuli500177 xuli500177 commented May 9, 2026

Summary

  • Decouple im.message.receive_v1 ACK from the long-running OpenCode message processing path.
  • Run onMessage(ctx) in the background and keep the existing fallback error reply behavior in the async catch handler.

Why

Feishu WebSocket callbacks should return quickly. Waiting for the full AI response before the handler resolves can make Feishu retry the same message event, which can produce duplicate replies for one user message.

Verification

  • npm run build
  • npm run typecheck

Summary by CodeRabbit

  • Performance Improvements

    • Messages are now processed asynchronously in the background, enabling faster system acknowledgment of incoming messages.
  • Bug Fixes

    • Improved error handling for message processing failures with fallback notifications when configured.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e34de883-d833-4459-a14e-aed9083a7137

📥 Commits

Reviewing files that changed from the base of the PR and between 55eb36f and 87ff677.

📒 Files selected for processing (1)
  • src/feishu/gateway.ts

📝 Walkthrough

Walkthrough

The PR refactors how the Feishu gateway handles incoming WebSocket messages. Instead of awaiting message processing inline, the handler now spawns a detached background task and returns its ACK immediately. Error handling moves into the background task's catch block, which logs errors and conditionally sends a fallback retry message.

Changes

WebSocket Handler Async Refactor

Layer / File(s) Summary
Handler Async Refactor
src/feishu/gateway.ts
im.message.receive_v1 event handler executes onMessage(ctx) in a detached async task (IIFE pattern) instead of awaiting inline. Error handling moves to .catch(), which logs errors and conditionally sends a fallback retry message using larkClient.im.message.create when both fallbackShouldReply and fallbackChatId are available.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A message arrives at the gateway's door,
No more waiting—ACK returns before!
Detached tasks work their magic in the night,
While errors catch themselves and set things right. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: ack Feishu messages before async processing' directly and clearly summarizes the main change: decoupling the ACK from async message processing to prevent timeouts and duplicate messages.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Feishu gateway to process messages asynchronously, ensuring that WebSocket callbacks can return an ACK promptly to avoid message re-delivery during long-running AI tasks. The feedback suggests enhancing the error logs within this background process by including messageId and chatId to improve observability and simplify troubleshooting.

Comment thread src/feishu/gateway.ts
Comment on lines +303 to +305
log("error", "消息处理错误", {
error: err instanceof Error ? err.message : String(err),
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Including the messageId and chatId in the error log for the background task would significantly improve observability. Since the processing is now asynchronous and decoupled from the main request-response cycle, having these identifiers in the log makes it much easier to trace which specific message caused the error without having to manually correlate timestamps.

          log("error", "消息处理错误", {
            error: err instanceof Error ? err.message : String(err),
            messageId: ctx.messageId,
            chatId: ctx.chatId,
          })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant