From fb2cbaa5b3999454bf88f80ea6cbcc7572a6dda5 Mon Sep 17 00:00:00 2001 From: zhi Date: Mon, 2 Mar 2026 11:20:39 +0000 Subject: [PATCH] fix: only process assistant messages in before_message_write before_message_write fires for both user (incoming) and assistant (outgoing) messages. Without a role check, end symbols from other agents' incoming messages incorrectly trigger turn advances. Add role check to skip non-assistant messages early. --- dist/whispergate/index.ts | 8 ++++++++ plugin/index.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/dist/whispergate/index.ts b/dist/whispergate/index.ts index a4b507d..d48243b 100644 --- a/dist/whispergate/index.ts +++ b/dist/whispergate/index.ts @@ -932,9 +932,17 @@ export default { } // Extract content from event.message (AgentMessage) + // IMPORTANT: Only process assistant messages — before_message_write fires for both + // user (incoming) and assistant (outgoing) messages. Processing user messages would + // incorrectly detect end symbols from OTHER agents' messages and advance the turn. let content = ""; const msg = (event as Record).message as Record | undefined; if (msg) { + const role = msg.role as string | undefined; + if (role && role !== "assistant") { + // Skip non-assistant messages (user messages, system messages, etc.) + return; + } // AgentMessage may have content as string or nested if (typeof msg.content === "string") { content = msg.content; diff --git a/plugin/index.ts b/plugin/index.ts index a4b507d..d48243b 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -932,9 +932,17 @@ export default { } // Extract content from event.message (AgentMessage) + // IMPORTANT: Only process assistant messages — before_message_write fires for both + // user (incoming) and assistant (outgoing) messages. Processing user messages would + // incorrectly detect end symbols from OTHER agents' messages and advance the turn. let content = ""; const msg = (event as Record).message as Record | undefined; if (msg) { + const role = msg.role as string | undefined; + if (role && role !== "assistant") { + // Skip non-assistant messages (user messages, system messages, etc.) + return; + } // AgentMessage may have content as string or nested if (typeof msg.content === "string") { content = msg.content;