ExAgent.Retention (ExAgent v3.0.0)

View Source

Subject erasure and inventory in an authorized Store namespace.

Stability — Stable.

Summary

Types

Ordered outcomes of subject erasure. The :follow_ups field is candidate.

Functions

Erase one logical subject in the given ExAgent.Store.scoped/2 descriptor. Use :kind to select :agent (default), :session, :composition or :flow. For durable workflows, use the ID from their continuation configuration. The host authorizes the operation and maps IDs to their associated stores.

Read a page of IDs and references still available for the authorized subject. Pass :id, optional :kind (as in erase/3), :limit (1–100, default 50) and the previous page's opaque :after cursor. The cursor is scoped to the query and expires when the projected inventory changes.

Types

inventory_entry()

@type inventory_entry() ::
  {:run | :job | :conversation, String.t()}
  | {:result, %{run_id: String.t(), id: String.t()}}
  | {:continuation,
     %{namespace: String.t(), id: String.t(), run_id: String.t() | nil}}
  | {:provider_copy, provider_copy()}
  | {:deferral,
     %{
       :id => String.t(),
       :run_id => String.t(),
       :kind => :external | :input | :timer,
       optional(:wake_at) => non_neg_integer()
     }}

outcome()

@type outcome() :: :deleted | :unsupported | {:retained, atom()}

provider_copy()

@type provider_copy() :: %{
  kind: :file | :response,
  provider: String.t(),
  id: String.t()
}

receipt()

@type receipt() :: [
  snapshot: outcome(),
  journal: outcome(),
  admission_receipts: outcome(),
  event_buffer: outcome(),
  jobs: [outcome()],
  follow_ups: [String.t()] | :unsupported | {:retained, atom()},
  memory: [outcome()],
  result_store: [outcome()],
  eval: [outcome()],
  provider_copies: [
    {{:retained, :provider_copy}, provider_copy()} | {:retained, atom()}
  ],
  tombstone: :closing | :sealed | :unsupported | {:retained, atom()}
]

Ordered outcomes of subject erasure. The :follow_ups field is candidate.

subject_kind()

@type subject_kind() :: :agent | :session | :composition | :flow

Functions

erase(store, id, opts)

@spec erase(ExAgent.Store.scoped(), String.t(), keyword()) :: {:ok, receipt()}

Erase one logical subject in the given ExAgent.Store.scoped/2 descriptor. Use :kind to select :agent (default), :session, :composition or :flow. For durable workflows, use the ID from their continuation configuration. The host authorizes the operation and maps IDs to their associated stores.

The Store fences new admissions before draining matching local Servers or Sessions. Pass known remote owner PIDs in :owners. A Server finishes the current turn, cancels queued turns and frees its event buffer on exit. Use :timeout (default 5000 ms) to bound the drain wait. Retry after a timeout or after reconciling retained C7 evidence.

Each of :result_store, :memory, :jobs and :eval takes a list of {descriptor, key} pairs. Keys are run IDs, memory scopes, job IDs and evaluated run IDs respectively. Jobs descriptors use {:volatile, server} or {ExAgent.Jobs.Durable, handle}. The candidate :eval option accepts {ExAgent.Eval.Online.Durable, {jobs_handle, evaluator_name, evaluator_version}}. Use dedicated scopes and quiesce other writers, including evaluation collectors, before erasing. Read retained IDs with inventory/2.

The primary Store erases the snapshot, C7 journal (including its segments) and persisted turn receipts together. Uncertain effects, active claims and open external deferrals keep their evidence ({:retained, :open_external_deferral}). The sealed tombstone permits supplying a result or closing and reconciling the deferral. Dependent stores wait while primary data is retained. An open input or timer wait is deleted with the journal. Fencing an agent subject also removes pending scheduled follow-ups for every member of its conversation family. Memory and offloaded results also wait for associated Jobs and evaluations. A conversation created by ExAgent.Conversations.fork/3 or ExAgent.Server.regenerate/2 shares this boundary with the original. Pass any member ID to drain and erase the family. Open evidence in one branch retains the whole primary family until it can be settled.

The receipt is a keyword list in the order of receipt/0. Each store appears once. Dependent outcomes follow the input order. An absent key counts as deleted and a missing callback reports :unsupported. Backend or drain failures can leave a partial receipt.

:jobs reports only the job associations supplied by the host. The candidate :follow_ups entry lists the sorted IDs deleted by this invocation's fence, even if the journal still has retained evidence. A repeated call reports only deletions it performs. It reports :unsupported if the Store cannot report the IDs, or {:retained, reason} if erasure could not confirm the fence.

Provider copies report {{:retained, :provider_copy}, %{kind: kind, provider: provider, id: id}}. The host can supply additional known references in :provider_copies. Keep those IDs for authorized deletion after relevant work has settled. :provider_inventory_unconfirmed marks a failed read of provider references.

The default :tombstone_ttl is :infinity. A finite TTL in milliseconds starts when local deletion is confirmed. It never shortens an existing seal and cannot expire while C7 evidence is retained. Use it only if old deliveries have a known bounded lifetime. Allocate a fresh opaque ID for new work whenever old deliveries can still arrive. Generated PostgreSQL hosts remove the physical marker after expiry.

inventory(store, opts)

@spec inventory(ExAgent.Store.scoped(), keyword()) ::
  {:ok, %{items: [inventory_entry()], cursor: String.t() | nil}}
  | {:error, term()}

Read a page of IDs and references still available for the authorized subject. Pass :id, optional :kind (as in erase/3), :limit (1–100, default 50) and the previous page's opaque :after cursor. The cursor is scoped to the query and expires when the projected inventory changes.

The inventory reads a bounded journal or snapshot per family member. It includes retained run and Job IDs, open deferrals, visible offloaded result references and provider copies. Candidate inventory variants include pending follow-up Job IDs, input and timer deferrals, and a fork family's retained conversation IDs. Timer entries include their UTC millisecond wake time. Session bindings identify separately owned continuations. History pruning, compaction and host-owned data limit the available references. Job and result IDs owned by the host must be mapped to their authorized backends before erasure.