mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 06:28:12 +00:00
fix(feishu): fetch quoted content before empty-message guard (#90192)
* fix(feishu): fetch quoted content before empty-message guard Moves the quoted/replied message content fetching before the empty-message early return so a reply with only @bot mention (no text, no media) is not dropped when it quotes a message with meaningful content. The guard now also checks that quoted text is empty before skipping. Note: because the fetch is now unconditional on parentId after passing the group admission/mention gate, an empty-text reply that quotes a parent in an open group (requireMention: false) without mentioning the bot will now be dispatched, where before it was dropped. This is the intended behavior for open groups — any non-empty turn (including one where context comes from a quote) should reach the agent. For requireMention:true groups, unmentioned messages still exit at the mention gate before the fetch, so no over-fetch occurs. Adds group-based regression tests for the #90177 scenario: - Positive: mention-only reply in requireMention:true group with quoted parent — dispatches with [Replying to: "..."] in the body. - Negative: empty reply with no bot mention in requireMention:true group — getMessageFeishu is never called and nothing is dispatched. * fix(feishu): fetch quoted content before empty-message guard (#90192) (thanks @bladin) --------- Co-authored-by: 黑承亮0668000844 <bladin@users.noreply.github.com> Co-authored-by: sliverp <870080352@qq.com>
This commit is contained in:
@@ -26,6 +26,7 @@ Docs: https://docs.openclaw.ai
|
||||
|
||||
- Channels and delivery: preserve account-scoped DM channel send policy, intentional rich-message line breaks in Telegram and status output, rich Telegram final replies, rich Telegram tables and lists, Telegram thread-create CLI remapping, Feishu dynamic-agent routes after persisted binding reuse, Slack outbound `message_sent` hooks, contributed message-tool schema optionality, same-channel generated media completions, and channel chunking around surrogate pairs and Infinity limits. (#92788, #93164, #92679, #89421, #89943, #42837, #92814, #91137, #91246, #92735) Thanks @yetval, @obviyus, @spacegeologist, @rishitamrakar, @liuhao1024, @lundog, @TurboTheTurtle, and @yhterrance.
|
||||
- Gemini CLI: use the selected OpenClaw OAuth/API-key auth profile in an isolated Gemini CLI runtime home, preventing ambient Google machine credentials from overriding the chosen profile. (#88748) Thanks @jason-allen-oneal and @shakkernerd.
|
||||
- Feishu: fetch quoted/replied message content before the empty-message guard so a mention-only reply that quotes a message with meaningful content is no longer dropped. (#90192) Thanks @bladin.
|
||||
- Discord: give generated auto-thread titles a 60-second timeout and 4,096-token reasoning-model output budget, clamped to the selected model output cap. (#64734) Thanks @hanamizuki.
|
||||
- Agent, cron, and Gateway runtime: mark active main sessions before restart shutdown aborts, pause yielded subagent runs whose terminal also signals abort, clamp trusted subagent thinking overrides through provider/model fallback, preserve yielded media completions, deliver channel message-tool final replies through auto-reply while hiding internal delivery hints, restore reset archive fallback reads when active async transcripts are missing, de-duplicate main-session heartbeat events, expose session identity in runtime prompts, reject unknown OpenAI agent selectors, keep generated media completions, slash-command block replies, and trajectory export commands in WebChat, and require admin privileges for HTTP session/model override surfaces. (#91357, #92631, #92412, #92146, #92879, #91287, #92468, #92510, #91246, #92651, #92646) Thanks @ooiuuii, @openperf, @IWhatsskill, @masatohoshino, @CadanHu, @ZengWen-DT, @zhangguiping-xydt, and @TurboTheTurtle.
|
||||
- Providers and model replay: preserve storeless OpenAI Responses replay compatibility, recover invalid OpenAI reasoning signatures and genericized Anthropic thinking-signature replay errors, route OAuth image defaults through Codex for eligible OpenAI profiles, avoid eager tool streaming for Claude 4.5 in Copilot, quarantine unreadable and post-hook OpenAI/Anthropic-family tool schemas without broadening allowed tool choices, deliver explicit thinking-off requests to LM Studio binary-thinking models, honor profile auth for SecretRef model entries, bound model browsing, strip provider prefixes where runtimes need bare IDs, and surface nested embedding fetch failures. (#90706, #92941, #92201, #92916, #92824, #75393, #92908, #92921, #92928, #92002, #90686, #92247, #92627, #91218, #92628) Thanks @snowzlm, @mmyzwl, @CarlCapital, @bek91, @Kailigithub, @vincentkoc, @rohitjavvadi, @samson910022, @nxmxbbd, @liuhao1024, @bymle, and @mushuiyu886.
|
||||
|
||||
@@ -424,6 +424,7 @@ async function dispatchMessage(params: {
|
||||
currentCfg?: ClawdbotConfig;
|
||||
event: FeishuMessageEvent;
|
||||
channelRuntime?: PluginRuntime["channel"];
|
||||
botOpenId?: string;
|
||||
}) {
|
||||
const runtime = createRuntimeEnv();
|
||||
const feishuConfig = params.cfg.channels?.feishu;
|
||||
@@ -444,6 +445,7 @@ async function dispatchMessage(params: {
|
||||
await handleFeishuMessage({
|
||||
cfg,
|
||||
event: params.event,
|
||||
botOpenId: params.botOpenId,
|
||||
runtime,
|
||||
channelRuntime: params.channelRuntime,
|
||||
});
|
||||
@@ -4164,6 +4166,150 @@ describe("handleFeishuMessage command authorization", () => {
|
||||
// No reply should be dispatched: empty message is silently skipped
|
||||
expect(mockDispatchReplyFromConfig).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not drop empty-text message when it quotes a parent message (#90177)", async () => {
|
||||
// A Feishu reply containing only @bot (no additional text) was being
|
||||
// dropped before the quoted message content was fetched. The handler
|
||||
// should fetch quoted content first and only skip if all of current
|
||||
// text, media, and quoted content are empty.
|
||||
mockShouldComputeCommandAuthorized.mockReturnValue(false);
|
||||
mockGetMessageFeishu.mockResolvedValueOnce({
|
||||
messageId: "om_quoted_001",
|
||||
chatId: "oc-dm",
|
||||
content: "quoted message content from parent",
|
||||
contentType: "text",
|
||||
});
|
||||
|
||||
const cfg: ClawdbotConfig = {
|
||||
channels: {
|
||||
feishu: {
|
||||
dmPolicy: "open",
|
||||
allowFrom: ["*"],
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
|
||||
const event: FeishuMessageEvent = {
|
||||
sender: {
|
||||
sender_id: {
|
||||
open_id: "ou-reply-only-bot",
|
||||
},
|
||||
},
|
||||
message: {
|
||||
message_id: "msg-empty-with-quote",
|
||||
parent_id: "om_quoted_001",
|
||||
chat_id: "oc-dm",
|
||||
chat_type: "p2p",
|
||||
message_type: "text",
|
||||
// Empty text — only @bot mention, no additional content
|
||||
content: JSON.stringify({ text: "" }),
|
||||
},
|
||||
};
|
||||
|
||||
await dispatchMessage({ cfg, event });
|
||||
|
||||
// A reply should be dispatched because quoted content provides context
|
||||
expect(mockDispatchReplyFromConfig).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("dispatches mention-only group reply with quoted content in requireMention:true group (#90177)", async () => {
|
||||
// #90177 is specifically about group chats. The empty-message drop happens
|
||||
// after the group admission/mention gate, so the fix must also work when
|
||||
// the sender mentions the bot in a requireMention:true group and quotes a
|
||||
// parent message with meaningful content — the reply should dispatch with
|
||||
// the quoted text in the body.
|
||||
mockShouldComputeCommandAuthorized.mockReturnValue(false);
|
||||
mockGetMessageFeishu.mockResolvedValueOnce({
|
||||
messageId: "om_group_quoted_001",
|
||||
chatId: "oc-group-90177",
|
||||
content: "parent message with context",
|
||||
contentType: "text",
|
||||
});
|
||||
|
||||
const cfg: ClawdbotConfig = {
|
||||
channels: {
|
||||
feishu: {
|
||||
groupPolicy: "open",
|
||||
groups: {
|
||||
"oc-group-90177": {
|
||||
requireMention: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
|
||||
const event: FeishuMessageEvent = {
|
||||
sender: {
|
||||
sender_id: {
|
||||
open_id: "ou-group-sender",
|
||||
},
|
||||
},
|
||||
message: {
|
||||
message_id: "msg-group-empty-with-quote",
|
||||
parent_id: "om_group_quoted_001",
|
||||
chat_id: "oc-group-90177",
|
||||
chat_type: "group",
|
||||
message_type: "text",
|
||||
// Empty text — only @bot mention, no additional content
|
||||
content: JSON.stringify({ text: "" }),
|
||||
// Bot mention so the message passes the requireMention gate
|
||||
mentions: [
|
||||
{ key: "@_bot_1", id: { open_id: "ou-bot-90177" }, name: "Bot", tenant_key: "" },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
await dispatchMessage({ cfg, event, botOpenId: "ou-bot-90177" });
|
||||
|
||||
expect(mockDispatchReplyFromConfig).toHaveBeenCalledTimes(1);
|
||||
const context = mockCallArg<{ Body?: string }>(mockFinalizeInboundContext, 0, 0);
|
||||
expect(context.Body).toContain("[Replying to:");
|
||||
expect(context.Body).toContain("parent message with context");
|
||||
});
|
||||
|
||||
it("does not over-fetch quoted message for unmentioned empty reply in requireMention:true group (#90177)", async () => {
|
||||
// An empty-text reply that quotes a parent but does NOT mention the bot
|
||||
// in a requireMention:true group should be rejected at the mention gate
|
||||
// before the quoted message is fetched, so getMessageFeishu is never
|
||||
// called and nothing is dispatched.
|
||||
mockShouldComputeCommandAuthorized.mockReturnValue(false);
|
||||
|
||||
const cfg: ClawdbotConfig = {
|
||||
channels: {
|
||||
feishu: {
|
||||
groupPolicy: "open",
|
||||
groups: {
|
||||
"oc-group-90177-neg": {
|
||||
requireMention: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
|
||||
const event: FeishuMessageEvent = {
|
||||
sender: {
|
||||
sender_id: {
|
||||
open_id: "ou-group-sender-neg",
|
||||
},
|
||||
},
|
||||
message: {
|
||||
message_id: "msg-group-unmentioned-empty-quote",
|
||||
parent_id: "om_group_quoted_neg",
|
||||
chat_id: "oc-group-90177-neg",
|
||||
chat_type: "group",
|
||||
message_type: "text",
|
||||
// Empty text with no bot mention
|
||||
content: JSON.stringify({ text: "" }),
|
||||
},
|
||||
};
|
||||
|
||||
await dispatchMessage({ cfg, event, botOpenId: "ou-bot-90177-neg" });
|
||||
|
||||
expect(mockGetMessageFeishu).not.toHaveBeenCalled();
|
||||
expect(mockDispatchReplyFromConfig).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("createFeishuMessageReceiveHandler media dedupe", () => {
|
||||
|
||||
@@ -1026,15 +1026,57 @@ export async function handleFeishuMessage(params: {
|
||||
log,
|
||||
accountId: account.accountId,
|
||||
});
|
||||
// Skip messages with no text content and no media attachments. Feishu can
|
||||
// deliver empty-text events (e.g. `{"text":""}`) when a user sends a blank
|
||||
// message or when media parsing produces an empty string. Writing a blank
|
||||
// user turn to the session causes downstream LLM providers (e.g. MiniMax)
|
||||
// to reject the request with "messages must not be empty" errors. Logging
|
||||
// the skip avoids silent loss without polluting the agent session.
|
||||
if (!ctx.content.trim() && mediaList.length === 0) {
|
||||
// Fetch quoted/replied message content before the empty-message guard
|
||||
// so a reply with only @bot (no text, no media) is not dropped when
|
||||
// the quoted message carries meaningful content.
|
||||
let quotedMessageInfo: Awaited<ReturnType<typeof getMessageFeishu>> = null;
|
||||
let quotedContent: string | undefined;
|
||||
if (ctx.parentId) {
|
||||
try {
|
||||
quotedMessageInfo = await getMessageFeishu({
|
||||
cfg,
|
||||
messageId: ctx.parentId,
|
||||
accountId: account.accountId,
|
||||
});
|
||||
if (
|
||||
quotedMessageInfo &&
|
||||
(await shouldIncludeFetchedGroupContextMessage({
|
||||
cfg,
|
||||
accountId: account.accountId,
|
||||
chatId: ctx.chatId,
|
||||
isGroup,
|
||||
allowFrom: effectiveGroupSenderAllowFrom,
|
||||
mode: contextVisibilityMode,
|
||||
kind: "quote",
|
||||
senderId: quotedMessageInfo.senderId,
|
||||
senderType: quotedMessageInfo.senderType,
|
||||
}))
|
||||
) {
|
||||
quotedContent = quotedMessageInfo.content;
|
||||
log(
|
||||
`feishu[${account.accountId}]: fetched quoted message: ${quotedContent?.slice(0, 100)}`,
|
||||
);
|
||||
} else if (quotedMessageInfo) {
|
||||
log(
|
||||
`feishu[${account.accountId}]: skipped quoted message from sender ${quotedMessageInfo.senderId ?? "unknown"} (mode=${contextVisibilityMode})`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
log(`feishu[${account.accountId}]: failed to fetch quoted message: ${String(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip messages with no text content, no media attachments, and no quoted
|
||||
// content. Feishu can deliver empty-text events (e.g. `{"text":""}`) when
|
||||
// a user sends a blank message or when media parsing produces an empty
|
||||
// string. Writing a blank user turn to the session causes downstream LLM
|
||||
// providers (e.g. MiniMax) to reject the request with "messages must not
|
||||
// be empty" errors. Logging the skip avoids silent loss without polluting
|
||||
// the agent session. Quoted content is checked too so a reply-only @bot
|
||||
// with quoted context is not dropped.
|
||||
if (!ctx.content.trim() && mediaList.length === 0 && !quotedContent?.trim()) {
|
||||
log(
|
||||
`feishu[${account.accountId}]: skipping empty message (no text, no media) from ${ctx.senderOpenId}`,
|
||||
`feishu[${account.accountId}]: skipping empty message (no text, no media, no quoted) from ${ctx.senderOpenId}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -1107,44 +1149,6 @@ export async function handleFeishuMessage(params: {
|
||||
).commandAccess.authorized
|
||||
: undefined;
|
||||
|
||||
// Fetch quoted/replied message content if parentId exists
|
||||
let quotedMessageInfo: Awaited<ReturnType<typeof getMessageFeishu>> = null;
|
||||
let quotedContent: string | undefined;
|
||||
if (ctx.parentId) {
|
||||
try {
|
||||
quotedMessageInfo = await getMessageFeishu({
|
||||
cfg,
|
||||
messageId: ctx.parentId,
|
||||
accountId: account.accountId,
|
||||
});
|
||||
if (
|
||||
quotedMessageInfo &&
|
||||
(await shouldIncludeFetchedGroupContextMessage({
|
||||
cfg,
|
||||
accountId: account.accountId,
|
||||
chatId: ctx.chatId,
|
||||
isGroup,
|
||||
allowFrom: effectiveGroupSenderAllowFrom,
|
||||
mode: contextVisibilityMode,
|
||||
kind: "quote",
|
||||
senderId: quotedMessageInfo.senderId,
|
||||
senderType: quotedMessageInfo.senderType,
|
||||
}))
|
||||
) {
|
||||
quotedContent = quotedMessageInfo.content;
|
||||
log(
|
||||
`feishu[${account.accountId}]: fetched quoted message: ${quotedContent?.slice(0, 100)}`,
|
||||
);
|
||||
} else if (quotedMessageInfo) {
|
||||
log(
|
||||
`feishu[${account.accountId}]: skipped quoted message from sender ${quotedMessageInfo.senderId ?? "unknown"} (mode=${contextVisibilityMode})`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
log(`feishu[${account.accountId}]: failed to fetch quoted message: ${String(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
const isTopicSessionForThread =
|
||||
isGroup &&
|
||||
(groupSession?.groupSessionScope === "group_topic" ||
|
||||
|
||||
Reference in New Issue
Block a user