My Setup:
- AI Agent node with Simple Memory
- Session key based on user’s WhatsApp ID:
{{ $wa_id }} - Context window: 10 messages
- Google Sheets for customer data storage
The Problem:
I want conversation memory to automatically expire after 2 hours of inactivity for each user. Currently, the memory persists indefinitely, which causes:
- Users returning after days still get old conversation context
- Memory bloat - old sessions accumulate in n8n’s database forever
- No built-in way to clear stale sessions
My Current Workaround:
I’m tracking last_order_date in Google Sheets and generating dynamic session IDs that change after 2 hours:
// If > 2 hours inactive
sessionId = `${wa_id}_${timeBucket}`; // New session = old memory abandoned
// If < 2 hours inactive
sessionId = wa_id; // Same session = memory continues
This works but leaves orphaned sessions in the database.
My Questions:
-
Is there a built-in way to set TTL (Time-To-Live) on memory sessions? I didn’t see this option in the Simple Memory node parameters.
-
How does n8n handle memory cleanup internally? Do old sessions ever get deleted automatically, or do they persist indefinitely?
-
What’s the recommended approach for session expiration?
- Should I use an external Redis with TTL?
- Is there a way to programmatically clear specific sessions?
- Should I create a separate cleanup workflow?
-
Does changing the session key abandon old memory, or does it get garbage collected? For example, if a user had session ID “123456” yesterday and “123456_new” today, does the old “123456” session data ever get deleted?
-
Is this a common need? Should I open a feature request for TTL support in the memory node?
What I’ve Tried:
- Using dynamic session IDs (current solution)
- Searching documentation for TTL/expiration settings
- Looking for cleanup workflows in the community
Environment:
- n8n version: 1.118.2
- Self-hosted on Ubuntu with Docker
- ~500 users, ~300 messages/day
Any guidance would be greatly appreciated! Is there a best practice I’m missing, or is this something that should be a feature request?
Thanks! ![]()