ExAgent.Store.ETS (ExAgent v3.0.0)

View Source

In-process, ETS-backed ExAgent.Store implementation (dev/test default).

Stability — Stable.

A supervised ExAgent.Store.ETS GenServer owns a public, named ETS table (default name ExAgent.Store.ETS, started by the application supervisor), so the table outlives any single ExAgent.Server crash and snapshots survive a restart. Mutations are serialized by the owner, including legacy writes; record deadlines are checked after waiting in that owner's mailbox. Reads use ETS. The owner is registered locally under the table name. Connected nodes keep independent owners and data; this store does not replicate snapshots.

Portability (the important bit)

Even though ETS can hold arbitrary Erlang terms, this implementation round-trips snapshots through JSON (Snapshot.serialize/1), never term_to_binary. That enforces two things ExAgent.Store.Postgres relies on too:

  1. the stored shape is portable (JSON, not opaque binaries), and
  2. non-serializable values (pids, function captures) are refused at write time — Jason.encode! raises rather than persisting junk.

Use it as store: :ets on ExAgent.Server / ExAgent.AgentSupervisor. JSON does not redact secret strings. Data survives a conversation owner restart while the ETS table owner lives, not table-owner or VM loss.

Summary

Functions

Build a child specification with ID {ExAgent.Store.ETS, name}.

Rebuild continuation run headers from validated journals in the owned table. Run after importing legacy rows. Each row is processed by the table owner. The operation can be retried. It leaves journal bytes unchanged.

Start a linked owner and its snapshot table. The only option, :name, names both the local process and table, and defaults to this module. Supervise each instance as {ExAgent.Store.ETS, name: MyApp.Snapshots}.

Verify continuation run headers against the journals without writing. Inspect one scoped agent row at a time and stop at the first failure. A journal without a header returns {:error, {:run_header_missing, %{namespace: namespace, id: id}}}. The identity comes from the validated journal key.

Functions

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Build a child specification with ID {ExAgent.Store.ETS, name}.

rebuild_run_headers(table)

@spec rebuild_run_headers(atom() | :ets.tid()) :: :ok | {:error, term()}

Rebuild continuation run headers from validated journals in the owned table. Run after importing legacy rows. Each row is processed by the table owner. The operation can be retried. It leaves journal bytes unchanged.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start a linked owner and its snapshot table. The only option, :name, names both the local process and table, and defaults to this module. Supervise each instance as {ExAgent.Store.ETS, name: MyApp.Snapshots}.

verify_run_headers(table)

@spec verify_run_headers(atom() | :ets.tid()) :: :ok | {:error, term()}

Verify continuation run headers against the journals without writing. Inspect one scoped agent row at a time and stop at the first failure. A journal without a header returns {:error, {:run_header_missing, %{namespace: namespace, id: id}}}. The identity comes from the validated journal key.