title: Event Sourcing + CQRS Architecture

content: All state changes are captured as events in an append-only log (Event Bus using Redis Stream + PostgreSQL), with a separate read model (Session DNA) optimized for fast boot. This separates write concerns (capturing every detail) from read concerns (fast context loading), enabling state reconstruction, time-travel queries, and zero information loss.


title: Session DNA Compact Snapshot

content: Session state is compressed into a YAML file under 2K tokens (vs 80K current boot tax) containing only essential information: session_id, active_mission, state_summary, next_actions, blockers, conversation_state, and context_pointers. This single file is the ONLY file loaded on respawn, reducing boot tax from 40% to <5%.


title: Decoupled Agent Lifecycle

content: Agents run as persistent worker processes in a Redis Queue, completely decoupled from the Claude session lifecycle. When a session respawns, agents continue running in the background and write results to an Agent Mailbox (Redis + PostgreSQL). The new session picks up completed results seamlessly, achieving 100% agent survival vs 0% currently.


title: Tiered Memory Architecture

content: Three-tier memory system: Hot (Session DNA <2K tokens, always loaded), Warm (Last 3-5 sessions in PostgreSQL, query on-demand), Cold (Full history in Qdrant, Supermemory, S3). This enables lazy loading—most conversations don't need full history, so don't pay the token cost upfront.


title: 15-Phase Implementation Roadmap

content: Full phased rollout from database schema to full Tapestry mode: Phase 1-2 (Event Bus + schema), Phase 3-5 (Session DNA generator + hooks), Phase 6-10 (Agent Mailbox + workers + testing), Phase 11-15 (MEMORY.md auto-curation + tiered queries + MCP server + user acceptance).

steps: Phase 1: Implement database schema (create 5 tables)

steps: Phase 2: Implement Event Bus (Redis Stream + PostgreSQL logger)

steps: Phase 3: Implement Session DNA generator

steps: Phase 4: Update PreCompact hook (flush events before compaction)

steps: Phase 5: Create SessionStart hook (load DNA, greet user)

steps: Phase 6: Implement Agent Mailbox (Redis + PostgreSQL sync)

steps: Phase 7: Implement Agent Execution Engine (Redis queue workers)

steps: Phase 8: Implement Session DNA Projector (event → DNA updater)

steps: Phase 11: Implement MEMORY.md auto-curation

steps: Phase 12: Implement tiered memory queries

steps: Phase 13: Implement MCP server for session state

steps: Phase 15: Deprecate old handoff files, full Tapestry mode


title: Boot Tax Reduction Metrics

content: Current state: 80K tokens (~40% of context) boot tax, ~30 seconds load time. Target state: <10K tokens (<5%), with actual target of 3K tokens (1.5%). Reduction: 140K → 3K tokens (97% reduction). User re-orientation moments reduced from ~3/session to 0.


title: Infrastructure Cost Analysis

content: Total infrastructure cost: ~$1/month. PostgreSQL: $0 (already on Elestio). Redis: $0 (already on Elestio). Qdrant: $0 (already on Elestio). Supermemory: $0 (free tier). FalkorDB: $0 (self-hosted). S3 storage (snapshots): ~$1/mo for 1GB at $0.02/GB. Compute (background workers): $0 (same Elestio VPS). Well under $5/mo constraint.


title: Database Schema (5 Tables)

content: PostgreSQL schema includes: session_events (event sourcing log with event_id, session_id, event_type, payload JSONB, metadata, created_at), session_dna (read model snapshots with dna_id, session_id, dna_content YAML, version), agent_manifest (central registry with agent_id, task_description, status, story_id, heartbeat, result_summary JSONB), agent_results (durable outputs with result_id, agent_id FK, status, payload JSONB), workflow_sagas (multi-session workflows with workflow_id, workflow_type, current_step, state JSONB, status).


title: Session DNA YAML Structure

content: YAML structure under 2K tokens: session_id, previous_session, active_mission, state_summary (status, agents running/completed/failed, progress_percent), next_actions (array), blockers (type, item, status), conversation_state (tone, rapport_level, active_threads, interrupted_exchange), context_pointers (agent_manifest, session_history, knowledge_graph, full_handoff_log), version, timestamp, dna_hash.


title: pre_compact_hook() Function

content: Pseudocode: Before context compaction, analyze conversation transcript, extract decisions, blockers, agent dispatches, interrupted exchanges. Publish events to Event Bus (STRATEGIC_DECISION_LOCKED, BLOCKER_ENCOUNTERED, etc.). Force Session DNA update. Snapshot full conversation to cold storage. Result: Zero state loss despite compaction.


title: session_start_hook() Function

content: Pseudocode: On new session start, load data/session_dna.yml ONLY (2K tokens). Check Agent Mailbox for completed agents. Update DNA in-memory with completed agents. Synthesize greeting from DNA: 'Resuming session 24. Awaiting user input on 6 blockers.' Inject DNA YAML into context. Result: <5% boot tax, seamless continuity.


title: update_session_dna() Background Projector

content: Pseudocode: Subscribe to Event Bus. For each event, load latest DNA. Apply event to DNA (e.g., BLOCKER_ENCOUNTERED → append to blockers list). Save updated DNA. Result: Session DNA is always up-to-date snapshot reflecting latest events.


title: Information Density Through Event Sourcing

content: Event sourcing provides a defensibility mechanism: by storing every state change as an event (not just snapshots), the system can replay to rebuild state at any point, debug exactly what happened, support time-travel queries ('what was state at 14:30?'), and never lose information. This creates a complete audit trail that's difficult for competitors to replicate without similar infrastructure.


title: Invisible Session Respawns

content: The system makes session boundaries invisible to the user—Kinan experiences ONE continuous conversation regardless of respawns. This creates a superior user experience (95%+ continuity perception vs ~50% currently) that would be difficult for competitors to match without similar architectural investment in Session DNA and decoupled agent execution.


title: Event Bus Integration (Redis + PostgreSQL)

content: Event Bus uses Redis Stream for real-time event processing and PostgreSQL for durability. All state changes = events (AGENT_DISPATCHED, DECISION_MADE, BLOCKER_ENCOUNTERED, AGENT_COMPLETED). Redis handles real-time consumption, PostgreSQL provides append-only log for reconstruction.


title: Agent Mailbox Integration

content: Completed agent results written to Redis (fast access) and archived to PostgreSQL (durability). New session picks up results by polling the Agent Mailbox, updating its in-memory DNA with completed agent information. This bridges the gap between persistent agent workers and ephemeral session lifecycles.


title: Context Pointer System

content: Session DNA contains context_pointers linking to external systems: agent_manifest (mcp://genesis-session/agents/manifest), session_history (mcp://genesis-session/query_session_history), knowledge_graph (falkordb://query), full_handoff_log (file://hive/progress/session_23_handoff.md). These enable lazy-loading of deeper context when needed.


title: Session Continuity Tapestry System

content: A system designed to make Genesis session respawns invisible to the user, reduce boot tax from 40% to <5%, and preserve 100% of agent and conversational state across session boundaries. Core innovation: Event Sourcing + CQRS + Tiered Memory + Decoupled Agent Execution. Targets: <10K tokens boot tax, <5 seconds boot time, 100% agent survival, >95% session continuity perception.


title: Seamless Respawn Experience

content: By synthesizing greetings from Session DNA ('Resuming session 24. Awaiting user input on 6 blockers.') and tracking interrupted_exchange state, the system eliminates user re-orientation moments (~3 per session currently). Users experience zero friction from respawns, maintaining psychological flow and trust in the AI assistant.


title: Mid-Sentence Continuity Tracking

content: Session DNA tracks interrupted_exchange state (user_spoke, agent_was_replying), enabling the system to resume conversations from exactly where they were interrupted. This preserves conversational context that would otherwise be lost, making respawns truly invisible.