Authority Model
Single-writer event store with explicit concurrency rules.
The One-Writer Rule
b1e55ed uses an append-only event store backed by SQLite. The hash chain — where each event’s hash includes its predecessor — requires exactly one writer at any time. Violation of this rule forks the chain. Two processes appending concurrently will produce events with the sameprev_hash, creating an irrecoverable fork.
How It’s Enforced
SQLite WAL Mode
The database runs in WAL (Write-Ahead Logging) mode:Application-Level Lock
Database uses a threading.RLock around all write operations. This prevents concurrent writes within a single process. It does not protect across processes.
Transaction-Local Hash Read
Theprev_hash for each new event is read from the database inside the transaction, not from a cached value. This means:
- If another writer somehow appended between transactions, the next write will see the updated hash.
- The cached
_last_hashis synchronized after each read.
Concurrent Writer Detection
b1e55ed integrity checks for concurrent writers by attempting an IMMEDIATE transaction. If another process holds a write lock, it fails fast.
Operator Rules
- One brain process. Do not run multiple
b1e55ed braininstances against the same database. - One API server. The API server writes events (signal submission). Do not run multiple API instances without a write proxy.
- Cron jobs are safe if they use the CLI (which opens/closes the DB per invocation) — but they must not overlap with brain cycles.
- Read replicas are fine. SQLite WAL mode supports concurrent readers. Dashboard, queries, and monitoring can read freely.
Fork Detection
If the one-writer rule is violated,b1e55ed integrity will detect it:
- Identify the fork point (last valid hash).
- Discard events after the fork.
- Re-append from the correct chain.
Producer Trust Boundaries
Producers submit signals via authenticated API endpoints. They are trusted to provide data but not trusted to be correct. The trust model:| Layer | Trust Level | Enforcement |
|---|---|---|
| Authentication | High | API token + hmac.compare_digest |
| Signal format | Medium | Schema validation on ingestion |
| Signal quality | Low | Scoring, rate limiting, anti-spam |
| Signal correctness | None | Brain evaluates; karma settles |
- Write events directly (only via API signal submission).
- Modify existing events (append-only store).
- Affect other producers’ signals (isolated contributor IDs).
- Bypass rate limits or role permissions.
- Submit misleading signals (mitigated by scoring + karma).
- Flood the system (mitigated by rate limiting).
- Coordinate with other producers (mitigated by correlation detection, planned).
Future: Multi-Node
If b1e55ed ever supports multiple writers (e.g., distributed deployment):- Replace SQLite with a consensus-based store.
- Or use a single writer with replicated reads (current architecture scales to this).
- Hash chain becomes a Merkle tree with merge semantics.