Session: skip binding lookup for system events

This commit is contained in:
Gustavo Madeira Santana
2026-04-18 01:50:56 -04:00
parent c2fb4007c2
commit 18c4fd5678

View File

@@ -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<SessionInitResult> {
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)