Phase 1 delivers the complete durability and storage layer:
- WAL with crash recovery: Append-only journal with BLAKE3 checksums,
fsync guarantees, and proper seek-to-EOF on reopen
- Storage engine: sled-backed KVStore with scan_prefix for range queries
- Content-addressed storage: H:{hash}, V:{hash}, E:{hash} key patterns
- Ingestor: Background worker tailing WAL, writing to KV with 8-byte
aligned record headers for rkyv zero-copy deserialization
- Comprehensive tests: 31 tests covering crash recovery, round-trips,
and multi-cycle durability
New crates: stemedb-wal, stemedb-storage, stemedb-ingest
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.0 KiB
2.0 KiB
Lens
Last Updated: 2026-01-31 Confidence: High
Summary
A Lens resolves conflicting assertions into a deterministic answer at read time. Multiple truths coexist; the Lens chooses which to return.
Key Facts:
- Stateless compute (no side effects)
- Deterministic (same input = same output)
- Fast (runs on every read, avoid allocations)
- Pluggable (implement
Lenstrait)
File Pointer: crates/stemedb-lens/src/lib.rs (planned)
The Trait
pub trait Lens {
fn resolve(&self, candidates: &[Assertion], context: &QueryContext) -> LensResult;
}
Standard Lenses
| Lens | Strategy | Use Case |
|---|---|---|
| Recency | Latest timestamp wins | News, real-time |
| Consensus | Highest vote count | Democratic truth |
| Authority | Weighted by agent reputation | Expert truth |
| Skeptic | Returns variance/conflict | Finding controversy |
| EpochAware | Filters superseded epochs first | Paradigm-safe queries |
| Constraints | Returns must_use/forbidden predicates |
Pre-flight checks |
Lens::Constraints (Pre-Flight Check)
Special lens for agent safety. Returns rules, not facts.
GET /query?context=python_http&lens=constraints
-> Returns:
{
"constraints": [
{ "must_use": "axios", "forbidden": "requests", "reason": "User correction" }
]
}
Origin: Solves the "Optimization Conflict" where agents forget corrections. Acts as a compiler error for agent intent.
See agile-agent-team.md for full explanation.
Query Flow
- Client:
GET(Subject="Tesla", Predicate="Revenue", Lens="Consensus") - Index lookup:
SP:Tesla:Revenue->[Hash1, Hash2, Hash3] - Hydrate: Load assertions from hashes
- Resolve:
ConsensusLens.resolve(assertions, context) - Return: Single deterministic answer with confidence