From 75bb14cc4d09e8eca3cc724b128e9837017bc940 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 1 Dec 2025 11:56:40 +0100 Subject: [PATCH] fix(mom): include triggering message in context Fix race condition where app_mention event fires before message event logs to log.jsonl, causing the user's triggering message to be missing from the agent's context. Now append the current message directly from ctx.message to recentMessages. --- packages/mom/src/agent.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/mom/src/agent.ts b/packages/mom/src/agent.ts index 5f0e667a..ba3fd762 100644 --- a/packages/mom/src/agent.ts +++ b/packages/mom/src/agent.ts @@ -364,7 +364,16 @@ export function createAgentRunner(sandboxConfig: SandboxConfig): AgentRunner { const channelId = ctx.message.channel; const workspacePath = executor.getWorkspacePath(channelDir.replace(`/${channelId}`, "")); - const recentMessages = getRecentMessages(channelDir, 50); + const recentMessagesFromLog = getRecentMessages(channelDir, 50); + + // Append the current message (may not be in log yet due to race condition + // between app_mention and message events) + const currentMsgDate = new Date(parseFloat(ctx.message.ts) * 1000).toISOString().substring(0, 19); + const currentMsgUser = ctx.message.userName || ctx.message.user; + const currentMsgAttachments = ctx.message.attachments.map((a) => a.local).join(","); + const currentMsgLine = `${currentMsgDate}\t${currentMsgUser}\t${ctx.message.rawText}\t${currentMsgAttachments}`; + const recentMessages = recentMessagesFromLog + "\n" + currentMsgLine; + const memory = getMemory(channelDir); const systemPrompt = buildSystemPrompt( workspacePath,