fix(discord): preserve DM lastRoute user target

This commit is contained in:
Shakker
2026-02-17 13:47:16 +00:00
parent 7884d65687
commit b0d4c9b721
2 changed files with 89 additions and 3 deletions

View File

@@ -503,6 +503,8 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
runtime.error?.(danger("discord: missing reply target"));
return;
}
// Keep DM routes user-addressed so follow-up sends resolve direct session keys.
const lastRouteTo = isDirectMessage ? `user:${author.id}` : effectiveTo;
const inboundHistory =
shouldIncludeChannelHistory && historyLimit > 0
@@ -553,15 +555,16 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
OriginatingChannel: "discord" as const,
OriginatingTo: autoThreadContext?.OriginatingTo ?? replyTarget,
});
const persistedSessionKey = ctxPayload.SessionKey ?? route.sessionKey;
await recordInboundSession({
storePath,
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
sessionKey: persistedSessionKey,
ctx: ctxPayload,
updateLastRoute: {
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
sessionKey: persistedSessionKey,
channel: "discord",
to: effectiveTo,
to: lastRouteTo,
accountId: route.accountId,
},
onRecordError: (err) => {