EncryptingLongTermStore

org.llm4s.agent.encryption.EncryptingLongTermStore
See theEncryptingLongTermStore companion object
@Experimental

A LongTermStore that encrypts the values inner stores, with keys from keys (#2449, #2453; spec docs/superpowers/specs/2026-11-22-checkpoint-encryption-design.md, "The long-term store"). The long-term store is a separate SPI, so wrapping the checkpointer with EncryptingCheckpointer does not cover it. It works over any store - it is LongTermStoreContract that checks it - so give it, over the same keys, to everything that takes the store, on every instance:

val memories = EncryptingLongTermStore(postgres.longTermStore(), keys)
StoreFileBackend(memories)   // its files are encrypted with no more wiring

'''What is encrypted''': each item's value, and the outcome the store records with a change until C4's guard forgets it. Each is sealed on its own with AES-256-GCM under a subkey of its namespace, bound to its key id, its tenant, its namespace and its item key - an outcome to its effect key too - so one moved to another item, namespace or tenant does not open. The key is the namespace's tenant's (EncryptionKeySource.current).

'''What stays in plain''', because the store looks items up, lists and bounds by it: item keys, namespaces and their tenants, updated timestamps, effect keys and fencing tokens, the id of the key that sealed a value, and the size of every value.

'''Reads.''' A value that cannot be opened is a Left (EncryptionError) of the whole call - a list or a search never leaves the item out, and never returns what is stored in its place. An item stored in plain is refused (EncryptionError.NotEncrypted) unless EncryptionSettings.plaintextReads is on.

'''search''' cannot be the store's own, which would match ciphertext: this store reads the namespace through inner.list, opens each value in key order and matches it as the shipped stores do - the query, case-insensitively, as a substring of the key or of any string in the value - stopping one hit past limit. Its results are those of an unencrypted InMemoryLongTermStore or Postgres store over the same items; the cost is the whole namespace read into memory, which the store's limits bound, and a decryption per item reached. A store with another search of its own loses it under this wrapper.

'''modify''' runs in inner's transaction, fenced and made idempotent by inner exactly as without encryption: an applied key is answered with its recorded outcome, opened, and the change is not run. Otherwise the change sees the plaintext of its namespace, and what it decides is checked against limits, sealed and handed to inner. The item being changed is opened before the change is asked, so an item that cannot be opened cannot be overwritten or deleted through this store, only through inner.

'''Limits.''' limits are in the caller's terms - bytes of what was written, as inner counts them unencrypted - and are checked here, in the transaction, with the store's own messages: they are the largest that always fit inner's once sealed, so inner never refuses first. To offer exactly some limits, open inner with EncryptingLongTermStore.storageLimits of them. Counting a namespace's bytes reads its items' sizes, so a write reads its namespace once more than inner does.

Attributes

Companion
object
Source
EncryptingLongTermStore.scala
Graph
Supertypes
trait AppliedKeys
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def forget(key: EffectKey, token: FencingToken): Result[Unit]

Passed to the store unchanged: an applied key and a token are stored in plain.

Passed to the store unchanged: an applied key and a token are stored in plain.

Attributes

Source
EncryptingLongTermStore.scala

The item at key, its value opened.

The item at key, its value opened.

Attributes

Source
EncryptingLongTermStore.scala
def list(ns: Namespace, prefix: String, limit: Int): Result[Listing[StoreEntry]]

The entries inner lists, each value opened.

The entries inner lists, each value opened.

Attributes

Source
EncryptingLongTermStore.scala
def modify[A : ReadWriter](ns: Namespace, key: String, effect: EffectKey, token: FencingToken)(change: StoreView => Result[StoreChange[A]]): Result[A]

inner's transaction, its change deciding over plaintext, and what it decides stored sealed.

inner's transaction, its change deciding over plaintext, and what it decides stored sealed.

Attributes

Source
EncryptingLongTermStore.scala
def search(ns: Namespace, query: String, limit: Int): Result[Listing[StoreEntry]]

The entries of ns whose key or opened value matches query, as the shipped stores match, in key order.

The entries of ns whose key or opened value matches query, as the shipped stores match, in key order.

Attributes

Source
EncryptingLongTermStore.scala

Inherited methods

final def delete(ns: Namespace, key: String, ctx: FileContext): Result[Boolean]

Deletes key, guarded under store.delete: true when it existed.

Deletes key, guarded under store.delete: true when it existed.

Attributes

Inherited from:
LongTermStore
Source
LongTermStore.scala
final def put(ns: Namespace, key: String, value: Value, ctx: FileContext): Result[Boolean]

Writes value at key, guarded under store.put: true when the key was new.

Writes value at key, guarded under store.put: true when the key was new.

Attributes

Inherited from:
LongTermStore
Source
LongTermStore.scala

Concrete fields

The bounds of what callers write: the largest whose items always fit inner's limits once sealed. An item is counted as its key plus the JSON that is sealed - the bytes an unencrypted store counts, except for a value holding an unpaired surrogate, which is sealed with its characters past ASCII escaped and counted so.

The bounds of what callers write: the largest whose items always fit inner's limits once sealed. An item is counted as its key plus the JSON that is sealed - the bytes an unencrypted store counts, except for a value holding an unpaired surrogate, which is sealed with its characters past ASCII escaped and counted so.

Attributes

Source
EncryptingLongTermStore.scala

Inherited fields

C4's class for this target.

C4's class for this target.

Attributes

Inherited from:
LongTermStore
Source
LongTermStore.scala