diff --git a/src/auto-reply/reply/session.ts b/src/auto-reply/reply/session.ts index 0a0594ddd9..4d08ddb061 100644 --- a/src/auto-reply/reply/session.ts +++ b/src/auto-reply/reply/session.ts @@ -126,7 +126,11 @@ export async function initSessionState(params: { const sessionScope = sessionCfg?.scope ?? "per-sender"; const storePath = resolveStorePath(sessionCfg?.store, { agentId }); - const sessionStore: Record = loadSessionStore(storePath); + // CRITICAL: Skip cache to ensure fresh data when resolving session identity. + // Stale cache (especially with multiple gateway processes or on Windows where + // mtime granularity may miss rapid writes) can cause incorrect sessionId + // generation, leading to orphaned transcript files. See #17971. + const sessionStore: Record = loadSessionStore(storePath, { skipCache: true }); let sessionKey: string | undefined; let sessionEntry: SessionEntry;