Skip to content

fix(feishu): merge permission error notice into main dispatch instead of separate agent turn#27381

Merged
steipete merged 2 commits intoopenclaw:mainfrom
byungsker:fix/feishu-duplicate-dispatch-on-permission-error
Feb 26, 2026
Merged

fix(feishu): merge permission error notice into main dispatch instead of separate agent turn#27381
steipete merged 2 commits intoopenclaw:mainfrom
byungsker:fix/feishu-duplicate-dispatch-on-permission-error

Conversation

@byungsker
Copy link
Contributor

Problem

When sender-name lookup fails with a Feishu permission error (code 99991672), the bot dispatched two separate agent turns:

  1. A dedicated permission-error notification turn → bot responds once
  2. The regular inbound user message turn → bot responds again

This caused two bot replies for every single user message when the contact:contact scope is missing, wasting tokens and confusing users.

Root Cause

// BEFORE: two separate dispatches
if (permissionErrorForAgent) {
  // dispatch permission notification → agent replies (reply #1)
  await core.channel.reply.dispatchReplyFromConfig({ ctx: permissionCtx, ... });
}
// then dispatch normal message → agent replies again (reply #2)
await core.channel.reply.dispatchReplyFromConfig({ ctx: ctxPayload, ... });

Fix

Append the permission error notice directly to messageBody before the single main dispatch. The agent receives both the user's message and the system notice in one turn, and responds once.

// AFTER: permission notice appended to main body, single dispatch
if (permissionErrorForAgent) {
  messageBody += `\n\n[System: The bot encountered a Feishu API permission error...]`;
}
// one dispatch handles everything
await core.channel.reply.dispatchReplyFromConfig({ ctx: ctxPayload, ... });

Result: -52 lines, single coherent response per user message.

Fixes #27372

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

Fixed token-wasting double-reply bug in Feishu integration where permission errors triggered two separate agent turns. The fix consolidates both the permission error notification and the user message into a single agent turn by appending the error notice directly to messageBody before dispatch.

Key changes:

  • Removed separate permission error dispatch logic (52 lines)
  • Appended permission error notice to main message body using consistent [System: ...] format
  • Single dispatch now handles both user message and permission error notification
  • Preserved cooldown mechanism to prevent error notification spam

Code quality:

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is simple, focused, and well-documented. It removes 52 lines of duplicate logic, follows existing code patterns, and directly addresses the reported issue without introducing side effects or breaking changes. The fix maintains all existing functionality while eliminating wasteful double-dispatch behavior.
  • No files require special attention

Last reviewed commit: 2a6a2ee

byungsker and others added 2 commits February 26, 2026 13:02
… of separate agent turn

When the sender-name lookup fails with a Feishu permission error (code
99991672), the bot was dispatching two separate agent turns:

  1. A dedicated permission-error notification turn
  2. The regular inbound user message turn

This caused two bot replies for a single user message, degrading UX and
wasting tokens.

Fix: instead of a separate dispatch, append the permission error notice
directly to the main messageBody. The agent receives both the user's
message and the system notice in a single turn, and responds once.

Fixes openclaw#27372
@steipete steipete force-pushed the fix/feishu-duplicate-dispatch-on-permission-error branch from 2a6a2ee to 6a54fc9 Compare February 26, 2026 12:03
@steipete steipete merged commit cf4853e into openclaw:main Feb 26, 2026
@steipete
Copy link
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm test extensions/feishu/src/bot.test.ts (pass)
  • Full gate: blocked by unrelated existing failure in pnpm check (src/telegram/bot-message-context.test-harness.ts missing sendChatActionHandler)
  • Land commit: 6a54fc9
  • Merge commit: cf4853e

Thanks @byungsker!

execute008 pushed a commit to execute008/openclaw that referenced this pull request Feb 27, 2026
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
vincentkoc pushed a commit to Sid-Qin/openclaw that referenced this pull request Feb 28, 2026
vincentkoc pushed a commit to rylena/rylen-openclaw that referenced this pull request Feb 28, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…aw#27381) (thanks @byungsker)

(cherry picked from commit cf4853e)

# Conflicts:
#	extensions/feishu/src/bot.test.ts
steipete added a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…aw#27381) (thanks @byungsker)

(cherry picked from commit cf4853e)

# Conflicts:
#	extensions/feishu/src/bot.test.ts
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
thebenjaminlee pushed a commit to escape-velocity-ventures/openclaw that referenced this pull request Mar 7, 2026
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: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu channel may send duplicate replies when sender-name permission lookup fails (99991672)

2 participants