Expand description
Typed continuous-memory context domain model (task A1).
Implements the closed domain types from the continuous-memory spec:
- §6.1
MemoryContextModewith exact automatic-recall / turn-capture / lifetime semantics, - §6.2
MemoryContextLease— host-private construction, noDeserialize, - §6.3
UserIntentProof, - §19
AuthorizedMemoryAction/apply_memory_context_actionand the exhaustiveSessionMemoryStatetransition table.
Authority pattern: like crate::orchestration::validate_user_authorizable_model,
untrusted callers (plugins, models, extension JSON) can never mint authority.
A MemoryContextLease can only be produced by crate-internal host code via
the pub(crate) MemoryContextLease::grant gate, and the struct is
#[non_exhaustive] with no Deserialize impl, so neither struct-literal
construction nor wire deserialization can forge one outside this crate.
Style (spec §19): typed boundaries and exhaustive enums — no enabled: bool
flags, no serde_json::Value past the boundary, no model-created lease IDs,
no content-bearing errors.
Structs§
- Bounded
User Query - Bounded recall query (spec §6.4). Host-derived from the current user
prompt and byte-bounded at construction through the workspace-standard
BoundedTextbudgeting utility — truncation is safe here (the host is shrinking its OWN outbound query, not repairing untrusted input) and is recorded, never silent. No rawStringescapes the boundary. - Confirmation
Id - Identity of a host-driven confirmation exchange (spec §6.3
ConfirmedPrompt). - Context
Digest - Fixed-size digest of the recent context window (spec §6.4) — proves what the host summarized without shipping the transcript. Host-computed only.
- Context
Provider Id - Manifest-declared context-provider identity (spec §7.1).
- Contribution
Accounting - Provider-reported recall accounting (spec §6.5, §10.4): bounded counters only — never content.
- Contribution
Schema Version - Version of the contribution schema a provider produced (spec §6.5). Parse-at-the-boundary: empty/oversized/control input fails closed, so a constructed value is never empty.
- Disclosure
Grant Set - Bounded set of
DisclosureClassvalues the host is willing to accept back in a contribution (spec §6.4permitted_classes). Deduplicated at construction; bounded by the closed six-variant vocabulary itself. A provider record whose class is outside this set is rejected byvalidate_contribution— a plugin cannot volunteer classes the host never authorized. - Memory
Context Capability - Session-scoped memory-context capability handed to tool contexts (task
A4), mirroring the shape of
crate::mcp::McpLeaseCapabilityandcrate::extensions::lease::ExtensionLeaseCapability: a smallClonehandle over the shared per-sessionSessionMemoryStatethat thememory_contextbuiltin uses to read and mutate memory-context state. - Memory
Context Contribution - A provider’s recall contribution for one turn (spec §6.5, verbatim
shape). The host accepts one only through
validate_contribution— project identity, schema, and bounds are checked before it may influence budgeting or (in task B4) request assembly. - Memory
Context Lease - A host-granted continuous-memory lease (spec §6.2).
- Memory
Context Status - Typed, content-free status of a session’s memory context.
- Memory
Contribution Record - One record inside a recall contribution (spec §6.5, verbatim shape).
Content fields are
BoundedText— byte-bounded at construction, exact truncation accounting preserved. - Memory
Id - Identity of one stored memory record (spec §6.5).
- Memory
Lease Id - Host-minted lease identity (spec §6.2). Model-created lease IDs are an
explicitly unsafe pattern (spec §19); only
MemoryContextLease::grantcallers mint these. - Memory
Observability Event - One spec §15 metadata-only observability event. Every field is drawn from the §15 ALLOWED list — session/turn correlation IDs, the host-derived project digest identity (never a raw project path), provider ID, mode, record counts, byte/token accounting, duration buckets, disclosure/withholding counts, and a typed outcome code. The struct has no field that could carry user messages, memory bodies, raw tool results, credentials, or provider error text, so the §15 DISALLOWED list is excluded by construction, not by discipline.
- Message
Digest - Digest of the exact current user message proving it directly names the
requested memory transition (spec §6.3
ExactCurrentRequest). - Project
Id - Project isolation boundary (spec §5.2).
- Recall
Budget - Engine-authored recall budget (spec §6.4, §10.3). Parse-constructed from
the ENGINE’S own
memory_budget_tokensoutput — a provider never chooses its budget, and a value outside the §10.3 floor/ceiling fails closed at construction. - Recall
Request - One recall request the host sends a context provider (spec §6.4, verbatim shape). Every field is a bounded, parse-constructed type with a crate-private constructor, so the request can only be assembled by host code: it carries no credentials, no unrelated project paths, no hidden system instructions, and no unbounded transcript.
- Recall
Schema Version - Version of the recall-request schema the host produced (spec §6.4).
- Recall
Turn Metadata - Spec §10.4 explainability metadata retained for the current turn’s
accepted recall. Counters, identities, and durations only — bounded by
the §10.3 record limits; never memory content. Rendered for
/memory whybyRecallTurnMetadata::render(task B5). - Request
Id - Identity of the exact frontend command request that authorized a
transition (spec §6.3
ExplicitCommand). - Session
Id - Chat-session identity a lease is scoped to.
- Session
Memory State - Per-session memory-context state machine. All transitions are exhaustive over (current slot state, action); there are no boolean mode flags and no raw JSON past this boundary (spec §19).
- TurnId
- Identity of the chat turn a recall request targets (spec §6.4).
Enums§
- Authorized
Memory Action - A fully authorized memory transition (spec §19). Because every
lease-bearing variant embeds a
MemoryContextLease— which only host code can mint — anAuthorizedMemoryActioncarrying authority cannot be forged outside this crate. - Automatic
Recall - Automatic-recall column of the spec §6.1 semantics table.
- Capture
Policy - Capture policy carried by a lease (spec §6.2). Placeholder shape until the capture flow lands.
- Context
Segment - Typed context segment admitted to provider request assembly (spec §10.1):
accepted memory enters as
ContextSegment::Memory(...), never as raw text, never appended to the user message, and never as system policy. Deliberately a single-variant enum today — it exists to make the “typed segment, not raw text” boundary explicit and extensible. Per-provider wire translation of the segment is task B4; in Phase A the segment only feeds the T29 context-budget lane. - Durable
Status - Durable-slot component of
MemoryContextStatus. - Memory
Context Error - Typed memory-context failure. Deliberately content-free (spec §19: no content-bearing errors): only host-minted identities and static field names appear.
- Memory
Context Mode - Continuous-memory context mode (spec §6.1).
- Memory
Source - Source class of a recalled record (spec §6.5). Minimal closed set for the Phase A typed boundary; the retrieval pipeline (task B1) extends it to the full spec §9 vocabulary.
- Mode
Lifetime - Lifetime column of the spec §6.1 semantics table.
- OneShot
Status - One-shot-slot component of
MemoryContextStatus. - Rank
Reason - Why the provider ranked a record into the contribution (spec §6.5, §10.4 explainability). Minimal closed set until task B1.
- Recall
Policy - Recall policy carried by a lease (spec §6.2). Placeholder shape until the recall flow lands.
- Retention
Class - Retention class of a recalled record (spec §6.5). Placeholder single variant until the consolidation/retention flow lands (spec §11, Phase B).
- Turn
Capture - Turn-capture column of the spec §6.1 semantics table.
- User
Intent Proof - Proof of exact user intent behind a memory transition (spec §6.3).
Constants§
- MEMORY_
BUDGET_ CAPACITY_ PERCENT - Spec §10.3: memory may use at most this percentage of the effective provider input capacity.
- MEMORY_
BUDGET_ MAX_ TOKENS - Spec §10.3 hard ceiling on the memory recall budget, in estimated tokens.
- MEMORY_
BUDGET_ MIN_ TOKENS - Spec §10.3 minimum useful recall budget in estimated tokens. Below this, recall is skipped entirely — core safety/output/tool-result reserves are NEVER reduced to make room for memory.
- MEMORY_
MAX_ RENDERED_ RECORD_ BYTES - Spec §10.3: maximum rendered bytes for one individual record (2 KiB).
- MEMORY_
MAX_ SELECTED_ RECORDS - Spec §10.3: maximum selected records per contribution.
- MEMORY_
QUERY_ MAX_ BYTES - Byte ceiling for the recall query derived from the current user prompt (spec §6.4: the request never carries an unbounded transcript).
- RECALL_
HARD_ TIMEOUT - Spec §16.2 hard recall dispatch timeout: a slow provider can never delay the turn beyond this bound (the recall path fails open past it).
Functions§
- apply_
memory_ context_ action - Apply one fully authorized memory transition to a session’s state — the single engine transition every frontend shares (spec §19, verbatim shape).
- memory_
budget_ tokens - The memory recall budget for a request, per spec §10.3 exactly:
min(4096, 10% of effective_provider_input_capacity)estimated tokens, orNone(skip recall) when the computed value falls below theMEMORY_BUDGET_MIN_TOKENSfloor. Pure — no engine state is read. - render_
context_ segment - Task B4 (spec §10.2, §5.3): build the synthetic wire message carrying one validated recall contribution. Pure — no engine state is read.
- render_
recall_ why - The ONE
/memory whytext entry point (task B5, spec §10.4): renders the retained metadata when a recall was accepted this turn, and a clear, NON-error explanation when none is available (memory off, no eligible prompt yet, or the last recall was skipped). - validate_
contribution - Host-side contribution acceptance gate — the FULL spec §6.5 rejection matrix (task B1): “The host validates project ID, record count, record sizes, total size, disclosure classes, and schema version”.