services/satori-bot/docs/PERSISTENCE.md
Date: March 6, 2026 (Refactored) Component: State Management Layer (Drizzle + PGlite)
The bot utilizes a Memory-First strategy for active chat sessions, while persisting critical queue and message data to disk.
Map<string, ChatContext> within the BotContext object (src/core/types.ts).ensureChatContext in src/core/session/context.ts upon receiving a message.handleLoopStep in src/core/loop/scheduler.ts.MAX_ACTIONS_IN_CONTEXT = 50, ACTIONS_KEEP_ON_TRIM = 20.The bot has migrated from lowdb (JSON) to PGlite (PostgreSQL in WASM/Node) with Drizzle ORM for robust state management and high-performance I/O.
data/ directory (configured via DB_PATH in .env.local).src/lib/schema.ts):
channels: Metadata for discovered channels (ID, name, platform, self_id).messages: Persistent message log with indexing on channel_id and timestamp.event_queue: Persistent queue for incoming Satori events awaiting processing.unread_events: Persistent store for events marked as unread for each channel.pushToEventQueue) and removed (removeFromEventQueue) by ID.pushToUnreadEvents) and cleared per channel (clearUnreadEventsForChannel).drizzle-kit. Migrations are automatically applied on startup in src/lib/db.ts.The gap between ephemeral memory and persistent disk state has been significantly narrowed.
eventQueue and unreadEvents are fully persisted. If the bot crashes, it resumes processing the queue from where it left off.messages table in the database, ensuring continuity across restarts.AbortController handles are still lost on restart, the core task queue and conversation context remain intact.Database settings are managed through src/config.ts:
DB_PATH: Path to the PGlite data directory (default: data/pglite-db).