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.
This commit is contained in:
Mario Zechner 2025-12-01 11:56:40 +01:00
parent dd9decb9e1
commit 75bb14cc4d

View file

@ -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,