Skip to content

Commit 3d75c27

Browse files
steipeteampagent
andauthored
1 parent 47484dc commit 3d75c27

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎extensions/discord/src/monitor/message-handler.preflight.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,44 @@ describe("preflightDiscordMessage", () => {
928928
expect(expectPreflightResult(result).boundSessionKey).toBe(threadBinding.targetSessionKey);
929929
});
930930

931+
it("looks up thread bindings once for an accepted ordinary guild message", async () => {
932+
const channelId = "channel-binding-lookup-once";
933+
const manager = createThreadBindingManager({
934+
cfg: DEFAULT_PREFLIGHT_CFG,
935+
accountId: "default",
936+
persist: false,
937+
enableSweeper: false,
938+
});
939+
onTestFinished(() => manager.stop());
940+
const getByThreadId = vi.spyOn(manager, "getByThreadId");
941+
const message = createDiscordMessage({
942+
id: "m-binding-lookup-once",
943+
channelId,
944+
content: "ordinary human message <@openclaw-bot>",
945+
author: { id: "user-1", bot: false, username: "alice" },
946+
mentionedUsers: [{ id: "openclaw-bot" }],
947+
});
948+
949+
const result = await preflightDiscordMessage({
950+
...createPreflightArgs({
951+
cfg: DEFAULT_PREFLIGHT_CFG,
952+
discordConfig: {} as DiscordConfig,
953+
data: createGuildEvent({
954+
channelId,
955+
guildId: "guild-1",
956+
author: message.author,
957+
message,
958+
}),
959+
client: createGuildTextClient(channelId),
960+
}),
961+
threadBindings: manager,
962+
});
963+
964+
expect(expectPreflightResult(result).message.id).toBe(message.id);
965+
expect(getByThreadId).toHaveBeenCalledTimes(1);
966+
expect(getByThreadId).toHaveBeenCalledWith(channelId);
967+
});
968+
931969
it("drops hydrated bound-thread webhook copies after fetching an empty payload", async () => {
932970
const threadBinding = createThreadBinding({
933971
targetKind: "session",

‎extensions/discord/src/monitor/message-handler.preflight.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ export async function preflightDiscordMessage(
278278
const messageText = resolveDiscordMessageText(message, {
279279
includeForwarded: true,
280280
});
281+
// Only bot/webhook traffic can be rejected before canonical routing; ordinary
282+
// messages should reach the single authoritative binding lookup below.
281283
const injectedBoundThreadBinding =
282-
!isDirectMessage && !isGroupDm
284+
!isDirectMessage && !isGroupDm && (webhookId || author.bot)
283285
? resolveInjectedBoundThreadLookupRecord({
284286
threadBindings: params.threadBindings,
285287
threadId: messageChannelId,

0 commit comments

Comments
 (0)