From 18c4fd5678a5bf5f28c5a18dd5ffc291d19a32c3 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Sat, 18 Apr 2026 01:50:56 -0400 Subject: [PATCH] Session: skip binding lookup for system events --- src/auto-reply/reply/session.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/auto-reply/reply/session.ts b/src/auto-reply/reply/session.ts index 86ff340a0dc..f542629c3e8 100644 --- a/src/auto-reply/reply/session.ts +++ b/src/auto-reply/reply/session.ts @@ -214,7 +214,9 @@ function resolveBoundConversationSessionKey(params: { } | null; }): string | undefined { const bindingContext = - params.bindingContext ?? resolveSessionConversationBindingContext(params.cfg, params.ctx); + params.bindingContext === undefined + ? resolveSessionConversationBindingContext(params.cfg, params.ctx) + : params.bindingContext; if (!bindingContext) { return undefined; } @@ -239,7 +241,15 @@ export async function initSessionState(params: { commandAuthorized: boolean; }): Promise { const { ctx, cfg, commandAuthorized } = params; - const conversationBindingContext = resolveSessionConversationBindingContext(cfg, ctx); + // Heartbeat, cron-event, and exec-event runs should NEVER trigger session + // resets or conversation binding retargeting. These are automated system + // events, not user interactions that should affect session continuity. + // See #58409 for details on silent session reset bug. + const isSystemEvent = + ctx.Provider === "heartbeat" || ctx.Provider === "cron-event" || ctx.Provider === "exec-event"; + const conversationBindingContext = isSystemEvent + ? null + : resolveSessionConversationBindingContext(cfg, ctx); // Native slash commands (Telegram/Discord/Slack) are delivered on a separate // "slash session" key, but should mutate the target chat session. const commandTargetSessionKey = @@ -422,12 +432,7 @@ export async function initSessionState(params: { resetType, resetOverride: channelReset, }); - // Heartbeat, cron-event, and exec-event runs should NEVER trigger session resets. - // These are automated system events, not user interactions that should affect - // session continuity. Forcing freshEntry=true prevents accidental data loss. - // See #58409 for details on silent session reset bug. - const isSystemEvent = - ctx.Provider === "heartbeat" || ctx.Provider === "cron-event" || ctx.Provider === "exec-event"; + // Forcing freshEntry=true prevents accidental data loss on automated system events. const entryFreshness = entry ? isSystemEvent ? ({ fresh: true } satisfies SessionFreshness)