Syntropy.Retention (syntropy v0.2.0)

Copy Markdown

Data retention policy for replay read models.

The policy decides how long replay data (run envelopes, runtime events, lattice snapshots, structural recommendations, task runs) is kept when persistence is enabled:

  • "infinite" — never purge (default)
  • "days7" — purge rows older than seven days, on boot and hourly
  • "session" — purge all replay data when the runtime boots

Config-like tables (webhooks, API tokens, knowledge, runtime settings) and billing data (usage records) are never purged.

The applied policy is persisted in runtime_settings and survives restarts. Without persistence there is nothing to purge, so the policy is informational only.

Summary

Functions

Validates and applies a retention policy.

Effective retention policy: the persisted setting when present, otherwise the environment-seeded default (SYNTROPY_RETENTION_POLICY).

Purges replay data according to the given policy and returns per-table deletion counts. Purge failures never raise; they are observed through PersistenceHealth and reported as an empty count map.

Retention posture for the API and the platform cockpit.

Types

policy()

@type policy() :: String.t()

purge_counts()

@type purge_counts() :: %{required(String.t()) => non_neg_integer()}

Functions

apply_policy(policy)

@spec apply_policy(term()) :: {:ok, map()} | {:error, String.t()}

Validates and applies a retention policy.

The policy is written through to runtime_settings (best effort) and also applied to the Application environment so persistence-disabled runtimes keep the value for the life of the node.

policies()

@spec policies() :: [policy()]

policy()

@spec policy() :: policy()

Effective retention policy: the persisted setting when present, otherwise the environment-seeded default (SYNTROPY_RETENTION_POLICY).

purge(policy, announce \\ :recorder)

@spec purge(policy(), :recorder | :direct) :: purge_counts()

Purges replay data according to the given policy and returns per-table deletion counts. Purge failures never raise; they are observed through PersistenceHealth and reported as an empty count map.

announce controls how the retention_purged event is emitted: :recorder goes through the running EventRecorder; :direct persists the event row directly, for boot-time purges that run before the recorder hydrates.

purge_after_days()

@spec purge_after_days() :: pos_integer()

report()

@spec report() :: map()

Retention posture for the API and the platform cockpit.