fix(feishu): stop automatic mention cascades (#71396)

Fix Feishu inbound mention targets being carried into outbound replies, with regression coverage for text, card, and streaming-card paths.\n\nThanks @MonkeyLeeT and @AxelHu.
This commit is contained in:
Ted Li
2026-05-09 02:16:14 -07:00
committed by GitHub
parent 4672c3eed3
commit 43ea5c3e6f
5 changed files with 91 additions and 23 deletions

View File

@@ -292,6 +292,21 @@ export function parseFeishuMessageEvent(
return ctx;
}
const MAX_MENTION_CONTEXT_NAME_LENGTH = 80;
function formatMentionNameForAgentContext(name: string): string {
const stripped = Array.from(name, (char) => {
const code = char.charCodeAt(0);
return code < 0x20 || char === "[" || char === "]" ? " " : char;
}).join("");
const normalized = stripped.replace(/\s+/g, " ").trim();
const bounded =
normalized.length > MAX_MENTION_CONTEXT_NAME_LENGTH
? `${normalized.slice(0, MAX_MENTION_CONTEXT_NAME_LENGTH - 3)}...`
: normalized;
return JSON.stringify(bounded || "unknown");
}
export function buildFeishuAgentBody(params: {
ctx: Pick<
FeishuMessageContext,
@@ -322,8 +337,10 @@ export function buildFeishuAgentBody(params: {
}
if (ctx.mentionTargets && ctx.mentionTargets.length > 0) {
const targetNames = ctx.mentionTargets.map((t) => t.name).join(", ");
messageBody += `\n\n[System: Your reply will automatically @mention: ${targetNames}. Do not write @xxx yourself.]`;
const targetNames = ctx.mentionTargets
.map((t) => formatMentionNameForAgentContext(t.name))
.join(", ");
messageBody += `\n\n[System: Feishu users mentioned in the incoming message, for context only: ${targetNames}. Do not notify or mention these users solely because they are listed here.]`;
}
// Keep message_id on its own line so shared message-id hint stripping can parse it reliably.
@@ -1383,7 +1400,6 @@ export async function handleFeishuMessage(params: {
replyInThread,
rootId: ctx.rootId,
threadReply,
mentionTargets: ctx.mentionTargets,
accountId: account.accountId,
identity,
messageCreateTimeMs,
@@ -1550,7 +1566,6 @@ export async function handleFeishuMessage(params: {
replyInThread,
rootId: ctx.rootId,
threadReply,
mentionTargets: ctx.mentionTargets,
accountId: account.accountId,
identity,
messageCreateTimeMs,