Expand description
v0.7.0 QW-3 — context-offload substrate primitive.
Substrate plumbing for the offload+deref pattern absorbed from the Tencent comparison (2026-05-15). The FULL pattern (Mermaid canvas, auto-cadence, node_id integration) targets v0.8.0; this module ships the substrate so v0.8.0 has plumbing to call.
§Pipeline
- SHA-256 over the original bytes (decompressed) is the integrity commitment.
ref_idformat:ofl_<base32-of-sha256-first-8-bytes>. 13 chars of payload after theofl_prefix — short enough to keep in an agent’s working window, long enough that a 40-bit prefix collision is vanishingly rare for typical fleet scales.- Body compressed with zstd level 3 — matches
memory_transcripts(the existing sidechain transcripts pipeline) for cross-codebase parity. - Ed25519 signature is over the canonical bundle
{ ref_id, content_sha256, stored_at, namespace }encoded as deterministic CBOR (RFC 8949 §4.2.1). Same encoder family asidentity::sign::canonical_cbor(the H2 link signer). - A sibling row lands in
signed_eventswithevent_type = context_offloadedorcontext_dereferenced, binding the substrate write into the H5 audit chain.
§Tamper handling
deref recomputes the SHA-256 of the freshly-decompressed bytes
and refuses with OffloadError::IntegrityFailed when it disagrees
with the stored content_sha256. The signature is verified against
the storing agent’s public key when that key is provided to the
offloader at construction; absent the key, the integrity check
alone is the load-bearing tamper guard.
§Out of scope (v0.7.0)
- Mermaid canvas integration (v0.8.0).
- Auto-cadence trigger from the recall pipeline (v0.8.0).
node_idcross-link into thememoriestable (v0.8.0).
Structs§
- Context
Offloader - Substrate-level engine for offload+deref. Composed from the
caller’s keypair, the existing SQLite connection, and the
OffloadConfigdefaults. - Deref
Result - Outcome of
ContextOffloader::deref. Returns the original (decompressed) content alongside the metadata that committed it. - Offload
Config - Static configuration consumed by
ContextOffloader. - Offload
Result - Outcome of
ContextOffloader::offload. Callers persistref_idand discard the content payload — that is the whole point of offload+deref.
Enums§
- Offload
Error - Domain errors callers may want to discriminate on (size limits,
integrity failures, signature mismatches). All other failure modes
bubble through
anyhow::Error.Displayandstd::error::Errorare implemented by hand to avoid pulling the optionalthiserrorcrate into the default feature set.
Constants§
- DEFAULT_
MAX_ OFFLOAD_ BLOB_ BYTES - Default per-blob byte limit when no namespace policy override is set. 1 MiB — Tencent’s offload primitive uses ~256 KB chunks; 1 MiB gives headroom for batched tool outputs without crossing the hostile-bomb threshold above.
- MAX_
DECOMPRESSED_ BYTES - Hard cap on the decompressed size of a single offloaded blob. Same
16 MiB ceiling the transcripts module enforces — defends against
pathological zstd bombs landing through
deref. v0.8.0 may raise this for the Mermaid-canvas use case after threat-modelling.
Functions§
- sweep_
expired - Daily TTL sweep. Removes every blob whose
stored_at + ttl_seconds < now. Bounded tomax_per_runrows per call so a pathological backlog can’t monopolise the connection; callers (the daemon background loop) re-invoke at the configured cadence.