Mimir.DecisionRecord (Mimir v0.5.0)

Copy Markdown View Source

Typed routing-decision record. build/5 returns a %DecisionRecord{}; to_event/1 renders the binary-keyed audit map suitable for appending as a turn event. No Repo, no clock beyond accepting the snapshot's snapshot_at.

Key conventions

  • to_event/1 map keys are strings (binary), never atoms.
  • Grant id is the caller-supplied grant key's UUID string. The plaintext bearer token is NEVER included.
  • Snapshot summary: only snapshot_at + a list of degraded lanes — the full pricing table is NOT copied in (it can be large and is not decision-relevant at audit time; the embedder has the full table if needed).
  • decision_id: "rd_" prefix + 26-char lowercase base32 of 16 random bytes.

Summary

Functions

Build a %DecisionRecord{} carrying the source data for a routing decision.

Render a %DecisionRecord{} as the binary-keyed audit map ready to append as a routing_decision turn event.

Types

t()

@type t() :: %Mimir.DecisionRecord{
  decision_id: String.t(),
  descriptor: Mimir.Descriptor.t(),
  grant_id: String.t() | nil,
  snapshot: Mimir.Snapshot.t(),
  step_id: String.t() | nil,
  verdict: verdict(),
  workflow_id: String.t() | nil
}

verdict()

@type verdict() ::
  {:decision, Mimir.Oracle.Decision.t()}
  | {:no_candidate, [term()], [Mimir.Candidate.t()]}

Functions

build(descriptor, verdict, grant_or_nil, ids, snapshot)

@spec build(
  Mimir.Descriptor.t(),
  verdict(),
  String.t() | nil,
  %{workflow_id: String.t() | nil, step_id: String.t() | nil},
  Mimir.Snapshot.t()
) :: t()

Build a %DecisionRecord{} carrying the source data for a routing decision.

Arguments:

  • descriptor — the %Descriptor{} the oracle was called with.
  • verdict{:decision, %Decision{}} or {:no_candidate, reasons, candidates}.
  • grant_id — the minted grant key's UUID string (never the plaintext bearer token), or nil.
  • ids%{workflow_id: string, step_id: string} (the correlation ids).
  • snapshot — the %Snapshot{} used for the decision.

Render with to_event/1 to get the binary-keyed map ready to append as a routing_decision turn event.

to_event(rec)

@spec to_event(t()) :: map()

Render a %DecisionRecord{} as the binary-keyed audit map ready to append as a routing_decision turn event.