From a378fac081e4c49376508fe5c32b5a0f52748be8 Mon Sep 17 00:00:00 2001 From: Vignesh Natarajan Date: Sat, 14 Feb 2026 19:40:21 -0800 Subject: [PATCH] fix (webchat): omit direct conversation labels from inbound metadata context --- src/auto-reply/reply/inbound-meta.test.ts | 24 +++++++++++++++++++++++ src/auto-reply/reply/inbound-meta.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/auto-reply/reply/inbound-meta.test.ts diff --git a/src/auto-reply/reply/inbound-meta.test.ts b/src/auto-reply/reply/inbound-meta.test.ts new file mode 100644 index 00000000000..f358aebc794 --- /dev/null +++ b/src/auto-reply/reply/inbound-meta.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import type { TemplateContext } from "../templating.js"; +import { buildInboundUserContextPrefix } from "./inbound-meta.js"; + +describe("buildInboundUserContextPrefix", () => { + it("omits conversation label block for direct chats", () => { + const text = buildInboundUserContextPrefix({ + ChatType: "direct", + ConversationLabel: "openclaw-tui", + } as TemplateContext); + + expect(text).toBe(""); + }); + + it("keeps conversation label for group chats", () => { + const text = buildInboundUserContextPrefix({ + ChatType: "group", + ConversationLabel: "ops-room", + } as TemplateContext); + + expect(text).toContain("Conversation info (untrusted metadata):"); + expect(text).toContain('"conversation_label": "ops-room"'); + }); +}); diff --git a/src/auto-reply/reply/inbound-meta.ts b/src/auto-reply/reply/inbound-meta.ts index 83da8ebd046..83676810238 100644 --- a/src/auto-reply/reply/inbound-meta.ts +++ b/src/auto-reply/reply/inbound-meta.ts @@ -52,7 +52,7 @@ export function buildInboundUserContextPrefix(ctx: TemplateContext): string { const isDirect = !chatType || chatType === "direct"; const conversationInfo = { - conversation_label: safeTrim(ctx.ConversationLabel), + conversation_label: isDirect ? undefined : safeTrim(ctx.ConversationLabel), group_subject: safeTrim(ctx.GroupSubject), group_channel: safeTrim(ctx.GroupChannel), group_space: safeTrim(ctx.GroupSpace),