title: Event Sourcing & CQRS for Session State

content: The architecture uses Event Sourcing and CQRS to decouple agent execution from the session lifecycle. All state-changing actions are published as events to a Redis Stream for real-time processing and logged to PostgreSQL for durability, creating a reliable 'Write Model' that can be projected into various 'Read Models' like the Session DNA.


title: Tiered Memory Model (Hot/Warm/Cold)

content: The system implements a tiered memory model: Hot (Session DNA injected into context), Warm (recent events in PostgreSQL), and Cold (full archives in Qdrant, Supermemory, S3). This optimizes context usage by keeping only the most critical state in the active context.


title: Agent Execution via Redis Queue

content: Agents are dispatched as tasks to a Redis queue and executed by independent, persistent worker processes. This ensures agents survive session termination and can complete long-running tasks even if the user disconnects.


title: Session DNA Specification

content: The Session DNA is a compact (<2K token) YAML file acting as the 'Hot Memory'. It contains session_id, active_mission, state_summary (status, agents running/completed), next_actions, blockers, conversation_state (tone, rapport, interrupted_exchange), and context_pointers to warm/cold storage.


title: Database Schema for Session Continuity

content: PostgreSQL schema includes: session_events (event sourcing log), session_dna (read model snapshots), agent_manifest (registry of agents/status), agent_results (durable storage for agent outputs), and workflow_sagas (multi-session workflow state).


title: Pre-Compact Hook Logic

content: The pre_compact_hook() analyzes the conversation transcript to extract decisions, blockers, and agent commands, publishes them as events to the Event Bus, forces a Session DNA update, and snapshots the full conversation to cold storage before context compaction.


title: Session Start Hook Logic

content: The session_start_hook() loads the Session DNA (the only major context-loading step), checks the Agent Mailbox for completed agents, synthesizes a greeting from the DNA, and injects the summary into the LLM context to achieve low boot tax.


title: Session Respawn Data Flow

content: The sequence for session respawn involves: 1. SessionStart Hook triggers, 2. Load Session DNA (reducing boot tax), 3. Inject DNA into context, 4. Synthesize greeting from DNA, 5. Check Mailbox for completed agents, 6. Lazy load from Warm/Cold memory if needed.


title: Reduced Context Boot Tax

content: The architecture reduces the context 'boot tax' from 40% to under 5% by using a compact Session DNA YAML file instead of loading full conversation history, providing a significant performance and cost advantage.


title: 100% State Preservation

content: The Event Sourcing model ensures 100% of agent and conversational state is preserved across session terminations, allowing seamless resumption and long-running agent tasks.


title: Event Bus (Redis Stream & PostgreSQL)

content: The Event Bus integrates Redis Stream (for real-time processing) and PostgreSQL (for durability). All state-changing actions are published here and consumed by the Session DNA Projector to update the read model.


title: Agent Mailbox (Redis to PostgreSQL)

content: Completed agent results are written to a Redis Hash for fast retrieval and then archived to a PostgreSQL agent_results table, ensuring both speed and durability.


title: Session DNA Token Size

content: The Session DNA is designed to be compact, using less than 2K tokens, significantly reducing the context window usage and associated costs compared to loading full session history.


title: Synthesized Status Greeting

content: Instead of reading multiple large files, the agent synthesizes a status update greeting directly from the Session DNA. This provides a coherent entry point for the user and maintains narrative continuity.


title: Lazy Loading for Context

content: As the conversation progresses, if the user asks about something not in the Hot Memory (Session DNA), the agent queries the Warm (PostgreSQL) or Cold (Qdrant/Supermemory) memory tiers on-demand. This prevents overwhelming the context window while retaining access to full history.


title: Session Continuity Tapestry

content: A comprehensive architecture solution to the session continuity problem in the Genesis system. It is designed to make session respawns seamless, reduce context boot tax to under 5%, and ensure 100% of agent and conversational state is preserved using Event Sourcing and a tiered memory model.