storage-sync
Storage Sync
Synchronize memories between Turso (durable) and redb (cache) storage layers.
When to Sync
- On startup - After system initialization
- Periodic - Scheduled background sync
- Cache staleness - When redb appears outdated
- Recovery - After storage failures
- Manual trigger - When explicitly requested
Sync Process
-
Check connection health:
turso_client.ping().await?; redb_env.check_integrity()?; -
Fetch latest from Turso:
let episodes = turso_client .query("SELECT * FROM episodes ORDER BY timestamp DESC LIMIT ?") .bind(max_episodes_cache) .await?; -
Update redb cache:
tokio::task::spawn_blocking(move || { let write_txn = redb.begin_write()?; let mut table = write_txn.open_table(EPISODES_TABLE)?; for episode in episodes { table.insert(episode.id.as_bytes(), episode.to_bytes())?; } write_txn.commit()?; }); -
Sync patterns and embeddings if enabled
Configuration
pub struct SyncConfig {
pub max_episodes_cache: usize, // Default: 1000
pub batch_size: usize, // Default: 100
pub sync_patterns: bool, // Default: true
pub sync_embeddings: bool, // Default: true
}
Error Handling
| Error | Handling |
|---|---|
| Turso unavailable | Skip sync, log warning, retry later |
| redb corruption | Attempt repair, rebuild from Turso |
| Partial sync | Track progress, resume from last point |
Performance Tips
- Batch small operations
- Incremental sync (only changes)
- Parallel fetch with Tokio
- Write-ahead preparation
Validation
After sync, verify:
- Episode count matches
- Latest episodes present
- Pattern counts consistent
- No orphaned embeddings
Troubleshooting
| Issue | Solution |
|---|---|
| Slow syncs | Reduce cache size, increase batch |
| redb lock errors | Use dedicated write task |
| Memory pressure | Stream large results, smaller batches |
More from d-o-hub/rust-self-learning-memory
loop-agent
Execute workflow agents iteratively for refinement and progressive improvement until quality criteria are met. Use when tasks require repetitive refinement, multi-iteration improvements, progressive optimization, or feedback loops until convergence.
51web-search-researcher
Research topics using web search and content fetching to find accurate, current information. Use when you need modern information, official documentation, best practices, technical solutions, or comparisons beyond your training data.
46perplexity-researcher-reasoning-pro
Highest level of research and reasoning capabilities for complex decision-making with significant consequences, strategic planning, technical architecture decisions, multi-stakeholder problems, or high-complexity troubleshooting requiring expert-level judgment and sophisticated reasoning chains. Prioritizes actively maintained repositories and validates website sources for 2025 relevance.
44context-retrieval
Retrieve relevant episodic context from memory for informed decision-making. Use when you need past episodes, patterns, or solutions to similar tasks.
44rust-code-quality
Perform comprehensive Rust code quality reviews against best practices for async Rust, error handling, testing, and project structure
43codebase-analyzer
Analyze implementation details, trace data flow, explain technical workings, locate files, and consolidate codebases. Use when you need to understand HOW code works, find file locations, or assess technical debt.
40