Skip to content

DATA LOSS: No State Persistence #24

@devfire

Description

@devfire

Severity: HIGH

Issue

All application state is stored in-memory. Power loss or crash results in complete data loss:

  • All groups lost
  • All key packages lost
  • All conversation history lost
  • Cannot rejoin groups

Impact

For a chat application, this makes it unusable for any serious purpose. Users expect:

  • Persistent conversation history
  • Ability to restart without losing groups
  • Recovery from crashes
  • Migration between devices

Current State

pub struct StateActor {
    groups: HashMap<String, MlsGroup>,           // In memory
    key_packages: HashMap<String, KeyPackageIn>, // In memory
    active_group: Option<String>,                // In memory
}

What Needs Persistence

  1. MLS Groups: Group state, epochs, member list
  2. Key Packages: Cached KeyPackages from other users
  3. Credentials: Long-term identity (already persisted via SSH keys)
  4. Messages: Conversation history
  5. Configuration: Active group, preferences

Proposed Solution

Phase 1: Basic persistence

pub trait Storage {
    async fn save_group(&self, name: &str, group: &MlsGroup) -> Result<()>;
    async fn load_group(&self, name: &str) -> Result<Option<MlsGroup>>;
    async fn save_key_package(&self, key: &str, kp: &KeyPackageIn) -> Result<()>;
    async fn load_key_packages(&self) -> Result<HashMap<String, KeyPackageIn>>;
}

Phase 2: Implement with SQLite

pub struct SqliteStorage {
    pool: SqlitePool,
}

// Tables:
// - groups (name, mls_state, epoch, created_at)
// - key_packages (composite_key, package_data, cached_at)
// - messages (id, group_name, sender, content, timestamp)

Phase 3: Migration and backups

  • Schema versioning
  • Automatic backups
  • Import/export functionality

Alternative: Serialize to files

Simpler but less robust:

// groups.json, key_packages.json
std::fs::write("data/groups.json", serde_json::to_string(&groups)?)?;

Related Issues

  • No graceful shutdown (no chance to save state)
  • No error recovery
  • Makes testing harder (can't inspect persisted state)

Labels

enhancement, data-persistence, reliability

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions