Index
memory
¶
Memory as a Marianne primitive (GH #496): the backend contract.
This package defines memory-backend/1.1 — the :class:MemoryBackend
protocol, the per-call :class:RequestContext, the value types facts travel
in, and the errors/1 taxonomy. Contract modules are pure (no I/O); the
shipped backends live under :mod:marianne.memory.backends.
Classes¶
AccessRef
dataclass
¶
A parsed access: value: inherit or a (possibly pinned) grant.
GrantRecord
dataclass
¶
GrantRecord(name, version, principal, scope, permissions, revocation_state, created_at, revoked_at=None, parent_version=None)
One version of a named grant (grant-record/1).
Updating a grant writes version n+1 and marks n superseded with
parent_version linking the lineage. A pinned reference to a
superseded version keeps that version's permissions; a revoked version
never confers authority.
MemoryBackend
¶
Bases: Protocol
memory-backend/1.1: what every memory backend implements.
Every operation takes the gateway-built :class:RequestContext first.
Failures raise a typed :class:~marianne.memory.errors.MemoryBackendError
subclass; a backend never returns an error as a success-shaped dict.
Methods:¶
declare
¶
Remember fact with its evidence; idempotent per (claim, evidence).
Source code in src/marianne/memory/backend_protocol.py
recall
¶
Facts relevant to query, within the per-response byte cap.
cap_bytes is an optional per-call ceiling the gateway sets to
min(recall_cap_bytes, quota_remaining); the backend applies the
smaller of it and its own cap, stops reading at it and returns its
cursor. None keeps the backend's own cap (the 1.1 behaviour).
Source code in src/marianne/memory/backend_protocol.py
verify
¶
bind
¶
Bind a freshly verified fact to an action; re-checks disk first.
forget
¶
fetch
¶
stream_facts
¶
Export every live fact and tombstone as migration-facts/1 batches.
migration_ingest
¶
Staged import: begin -> batch... -> finalize | abort.
RequestContext
dataclass
¶
RequestContext(principal, scope, permissions, deadline_at, dispatch_id=None, job_id=None, session_id=None)
The immutable per-call envelope (memory-backend/1.1).
deadline_at is a POSIX timestamp. A conforming backend clamps every
lock wait to remaining_seconds and aborts with E10 before it mutates
anything once the deadline has passed. scope is canonicalised on
construction; permissions is the session's ceiling.
Attributes¶
Methods:¶
require
¶
Raise E2 naming permission when the ceiling lacks it.
Source code in src/marianne/memory/backend_protocol.py
require_any
¶
Raise E2 unless the ceiling holds at least one of permissions.
Source code in src/marianne/memory/backend_protocol.py
AuthorityRevoked
¶
Bases: MemoryBackendError
E8: the session's authority epoch is stale (grant revoked).
Source code in src/marianne/memory/errors.py
BackendUnreachable
¶
Bases: MemoryBackendError
E5: the backend cannot be reached or its storage cannot be opened.
Source code in src/marianne/memory/errors.py
DeadBackend
¶
Bases: MemoryBackendError
E6: reserved — the backend died mid-session.
Source code in src/marianne/memory/errors.py
DeadlineExceeded
¶
Bases: MemoryBackendError
E10: the call deadline passed before mutation began.
Source code in src/marianne/memory/errors.py
ErrorCode
¶
Bases: str, Enum
The eleven errors/1 codes. Member name is the wire code.
LockTimeout
¶
Bases: MemoryBackendError
E9: lock acquisition did not succeed within the call's budget.
Source code in src/marianne/memory/errors.py
MemoryBackendError
¶
Bases: Exception
Base of every typed memory failure.
Deliberately not derived from the builtin MemoryError (which means the
interpreter ran out of RAM). Construct a subclass, never this base.
Source code in src/marianne/memory/errors.py
NotFound
¶
Bases: MemoryBackendError
E11: the fact, unit or attachment does not exist in the bound store.
Source code in src/marianne/memory/errors.py
PermissionDenied
¶
Bases: MemoryBackendError
E2: the session lacks the permission the operation needs.
Source code in src/marianne/memory/errors.py
RecallCapExceeded
¶
Bases: MemoryBackendError
E4: the dispatch's cumulative recall quota is spent.
Source code in src/marianne/memory/errors.py
SchemaViolation
¶
Bases: MemoryBackendError
E7: an argument or configuration value fails the contract.
Source code in src/marianne/memory/errors.py
ScopeRefused
¶
Bases: MemoryBackendError
E3: scope expression malformed or outside the authorised scope.
Source code in src/marianne/memory/errors.py
Unauthenticated
¶
Bases: MemoryBackendError
E1: peer credentials missing or wrong for this endpoint.
Source code in src/marianne/memory/errors.py
FactRecord
¶
Bases: TypedDict
One fact with its evidence and its clocks, as it migrates.
MigrationBatch
¶
Bases: TypedDict
One migration-facts/1 record yielded by stream_facts.
Permission
¶
Bases: str, Enum
The seven memory permissions. They live in conductor access records, never in score YAML.
Provenance
¶
Bases: TypedDict
Evidence a musician supplies with a declaration.
evidence_locator names where the claim can be re-checked (a path, a
URL, snapshot:<sha256>); observed_at is the source observation
clock, distinct from the backend's asserted_at write clock.
RecallResult
¶
Bases: TypedDict
One recall page.
cursor is a page cut (resume with its token) or None when nothing
is left. Units too large for the page cap are never truncated: each is
listed in oversized with remedy: fetch, so a page cut and several
oversized markers can travel in one response.
ScopeKey
dataclass
¶
A canonical scope: one family and one identifier.
The canonical spelling is local:<id> for the local family and
<family>/<id> for every other, so one (family, id) pair has exactly
one string everywhere it is joined on.
Tombstone
¶
Bases: TypedDict
A generational erasure: revokes the claim at or before cutoff.
Functions:¶
parse_access
¶
Parse an access: expression or raise E7 schema_violation.
Source code in src/marianne/memory/access.py
content_hash
¶
derive_fact_id
¶
Deterministic 16-hex fact id over (scope, locator, content hash, claim digest).
Fields are NUL-separated so ("a", "bc") and ("ab", "c") differ.
Re-declaring the same claim with the same evidence yields the same id.
Source code in src/marianne/memory/model.py
memory_health
¶
Build a memory-health/1 record; failure_class follows status.
Source code in src/marianne/memory/model.py
oversized_unit_cursor
¶
A single unit larger than the page cap: page it with fetch.
Source code in src/marianne/memory/model.py
page_cursor
¶
A page cut: resume with cursor to receive the omitted sections.
parse_scope
¶
Parse and canonicalise a scope expression, or raise E3 scope_refused.
Grammar: <family>(:|/)<id> with <id> in [a-z0-9_.-]+; input is
stripped and lowercased. An id made only of dots is refused because the
files backend maps a scope onto a directory and .. would escape it.