Raxol.Agent.PolicyApplier (Raxol Agent v2.6.0)

Copy Markdown View Source

Runtime that wraps an operation in a list of Raxol.Agent.Policy structs.

Policies are evaluated outermost-first. The order documented in Raxol.Agent.Policy:

  1. Cache (short-circuit on hit)
  2. RateLimit (deferred; not yet implemented)
  3. Timeout (wrap in a Task, abort on wall-clock)
  4. Retry (loop on retriable errors)
  5. The wrapped operation runs

Telemetry

Emits events under [:raxol, :agent, :policy, :*]:

EventMetadata
:cache_hitpolicy_kind: :cache, key, params
:cache_misspolicy_kind: :cache, key, params
:retry_attemptpolicy_kind: :retry, attempt, reason, backoff_ms
:retry_exhaustedpolicy_kind: :retry, attempt, reason
:timeoutpolicy_kind: :timeout, wall_ms

| :applied | the final outcome with :ok | :error tag |

Telemetry is fire-and-forget; consumers attach Raxol.Agent.PolicyApplier.ThreadLogHandler (a separate follow-up) to append :policy_result ThreadLog entries from the events.

Summary

Types

The wrapped operation. Receives params and returns a result().

Either an ok-or-error tuple or :ok.

Functions

Apply a list of policies to fun, threading params through.

Types

op()

@type op() :: (term() -> result())

The wrapped operation. Receives params and returns a result().

result()

@type result() :: {:ok, term()} | {:error, term()}

Either an ok-or-error tuple or :ok.

Functions

apply(policies, fun, params)

@spec apply([Raxol.Agent.Policy.t()], op(), term()) :: result()

Apply a list of policies to fun, threading params through.

Returns the unwrapped result tuple. On success, the value comes from the cache (if a cache policy hit), from a successful invocation, or from a retry's final attempt. On error, the most recent reason is returned.

An empty policies list invokes fun.(params) directly.