Qualia Peer Runtime (QPR) · Kernel & Replication Engine · 0.0.41
A bounded, lease-governed peer runtime built to replace libp2p.
The Qualia Peer Runtime (QPR) (crates/qualia-core-db/src/net/peer/) is the application-facing execution and replication engine over the Qualia Decentralized Network Fabric (QDNF). Unlike libp2p stacks that rely on unbounded heap futures, ambient socket pools, and DNS/IP assumptions, QPR pre-reserves every byte of cell memory, enforces generation-checked buffer leases, and verifies 5-field NQuin XOR parity before committing replicated .q42 SuperBlocks.
Release 0.0.41 Verification Scope: On 0.0.41, QPR’s cell admission table (admit.rs), generation-checked lease ledger (ledger.rs, release_checked_bytes), non-wrapping cancellation epochs (cancel.rs), 3-class fair scheduler, connection manager, local CSCP/QSession streams, and ChunkToSuperBlockManifest replication (scan.rs, transfer.rs, receipts.rs) execute deterministically in tree. Public Internet relay and MASQUE flags remain false until multi-host public trials run.
Handle ≠ human.
QPR peer handles, session descriptors, and reservation tokens belong to the Handle and Instrument planes — never the Entity (NaturalAgent) plane. Furthermore, creating extra personas never multiplies a host’s physical memory budget (extra_identity_multiplies_host_budget() == false).
Layer 2 · Supervised Cell Admission (peer::cells)
Bounded Cell Table (admit.rs), Host Ownership & LLM Starvation Guards
QPR admits up to MAX_CELLS = 16 supervised cells per HostAdmission instance, enforcing strict memory isolation between interactive network control loops, bulk replication transfers, and local AI inference workloads.
Cell Admission
cells/admit.rs · descriptors.rs
CellTable & CellProfile
Admits caller-backed CellDescriptor slots up to MAX_ORDINARY_CELL (512 MiB) against the host’s MAX_HOST_BYTES ceiling. Over-budget admission requests fail closed before spawning any worker loop.
Starvation Guard
cells/isolation.rs
LLM vs. Network Isolation
admit_llm_cannot_starve_network and llm_shares_ordinary_network_reserve() == false guarantee that local GGUF/P64 model inference cannot draw from or exhaust the memory reserve dedicated to CSCP and QSession control cells.
Zero-Copy Handover
cells/spsc.rs · workers.rs
SpscQueue & WorkerFence
Cross-cell message passing uses a fixed-capacity SpscQueue (SPSC_CAP) that issues an explicit OwnershipReceipt per transfer. Worker lifecycles (start_worker, cancel_worker, drain_and_handover) synchronize via WorkerFence.
Layer 3 · Deterministic Resource Governance (peer::runtime & NET-20)
Generation-Checked Leases (ledger.rs) & Non-Wrapping Cancellation Epochs
To eliminate use-after-free, double-release, and ABA slot-reuse bugs without garbage collection, QPR pairs every resource reservation and asynchronous operation with a strictly monotonic generation counter.
NET-20 · Lease Accounting
runtime/ledger.rs · leases.rs
ReservationLedger & release_checked_bytes
Every buffer lease allocated in LeaseTable (LEASE_SLOTS) or byte reservation in ReservationLedger returns a ReservationHandle stamped with the slot’s current generation (bump_generation).
When reclaiming memory via release_checked_bytes, the ledger verifies that both the slot generation and exact byte count match the active lease. Stale handles or mismatched byte releases fail closed immediately without corrupting the ResourceBudget.
Cancellation & Scheduling
runtime/cancel.rs · scheduler.rs
Non-Wrapping CancelEpoch & FairScheduler
OperationTable tracks in-flight operations using a non-wrapping CancelEpoch. Advancing the cancellation epoch deterministically invalidates subordinate OperationHandle entries and drains their leased buffers before slot reuse.
The FairScheduler partitions work across WorkClass::Control (CONTROL_CAP), WorkClass::Interactive (INTERACTIVE_CAP), and WorkClass::Background (BACKGROUND_CAP) across up to MAX_SCOPES scopes so bulk sync never blocks control heartbeats.
Layer 4 · .q42 v4 Knowledge Replication (peer::replication & NET-20)
Bounded Scan (scan.rs), Range Transfer (transfer.rs) & Durability Receipts (receipts.rs)
QPR’s QSync replication pipeline synchronizes .q42 knowledge graphs across peers without materializing full datasets in RAM or mistaking a socket ACK for disk durability.
1. Bounded Page Scan
scan.rs & source.rs
Streams replica artifacts through caller-supplied 4 KiB (PAGE_BYTES) windows via ScanSource, computing ManifestPage digests and RangeWitness Merkle proofs without unbounded heap allocation.
2. SuperBlock Bridge (NET-20)
transfer.rs & commit_adapter.rs
ChunkToSuperBlockManifest bridges SHA-384 (StrongDigest) transport chunks to SHA-256 .q42 v4 SuperBlocks, verifying 5-field NQuin XOR parity (subject ^ predicate ^ object ^ context) before invoking commit_verified_block.
3. Custody & Receipts
receipts.rs & pair.rs
Enforces transport_ack_is_durable() == false and source_signature_reusable_after_redaction() == false. Durable state transitions require staged two-phase DurablePairing (stage_paired → commit_pair) and explicit CustodyState receipts.
| Replication Invariant |
Function / Guard |
Return Value |
Engineering Meaning |
| Transport ACK ≠ Disk Durability |
transport_ack_is_durable() |
false |
A network packet acknowledgement never marks an operation durable before verified SuperBlock commit. |
| LWW Never Overrides Revocation |
lww_overrides_revocation() |
false |
A higher Lamport timestamp cannot resurrect a revoked capability or deactivated Tombstone. |
| Cache Eviction ≠ Proof of Absence |
eviction_proves_absence() |
false |
Missing an entry in a bounded CacheTable yields CacheLookup::Incomplete, never a negative existence proof. |
| Projection Preserves Originals |
projection_replaces_original() |
false |
Derived .q42 projections never overwrite or masquerade as the raw source artifact envelope. |
Related QDNF Architecture & Status Guides
Return to the QDNF architecture overview, inspect the 0.0.41 implementation status matrix, or read the companion guides on protocol cells and side-by-side DIDs.