docs · reference

Governance vectors#

Unreleased: after 0.11.0. The governance vectors and hekma agent governance-vectors are on Hekma's main branch and ship in the next release; Hekma 0.11.0 does not have them.

Hekma decides budget and cost breaches by a small set of fixed rules. If you enforce spend at your own choke point, outside Hekma, for example in a gateway or a scheduler, you need proof that your guard follows exactly the same rules, not an approximation of them. The governance conformance vectors are that proof, as data: one JSON document of worked cases, generated from the engine's own decision code, with a SHA-256 checksum. Re-run every case against your guard and compare the results byte for byte; if they all match, your guard decides as Hekma does.

The rules the vectors pin:

  • A ceiling is breached at or above its limit.
  • Each (dimension, scope) pair fires once per Run.
  • Token ceilings are checked before dollar caps.
  • Money is integer micro-dollars, and each token-times-rate division rounds half up.
  • Arithmetic saturates at the integer maximum instead of wrapping.
  • Each ledger row is priced at the rate stored with it, so a later rate change never reprices past usage.
  • Each limit resolves on its own, from the Run, the agent, the most specific matching Policy and the default Policy, in that order (from 1.3.0).
  • A limit changed on a live Run re-arms what its new value allows and fires what it now breaches, whatever moved it (from 1.4.0).
  • A Caller's limit applies only where it is tighter than the Operator's, the Host's or a Policy's, and its action never loosens what those set (from 1.4.0's policy-caller cases).
FactValue
Artifact idhekma-governance-vectors
In the repositorycrates/hekma-engine/governance/vectors-v1.json, with its checksum in vectors-v1.json.sha256 beside it
Current version1.4.0, schema version 1, 69 cases

Get the artifact#

hekma agent governance-vectors prints a summary. It only reads, so it needs no registered agent and starts no host:

hekma agent governance-vectors
✓ governance conformance vectors 1.4.0 — artifact `hekma-governance-vectors`, schema v1
  checksum  sha256:0818e4c2e5560c9360ab46bc2a959f8427db73c3cb0a488dea520faff61f2629
  cases     69 (20 decision, 11 derivation, 5 fence, 5 chain, 18 policy, 10 rearm)
  artifact  crates/hekma-engine/governance/vectors-v1.json
  pin       vectors_version + sha256 — re-run every case against your guard on any upgrade

With --json it prints the artifact itself, byte for byte as released, so a checksum of the output is the published checksum:

hekma agent governance-vectors --json | sha256sum      # on macOS: shasum -a 256
0818e4c2e5560c9360ab46bc2a959f8427db73c3cb0a488dea520faff61f2629  -

From the next release, the two files also ship as release assets (vectors-v1.json and vectors-v1.json.sha256, and listed in the release's hekma-<version>-checksums.txt), so you can pin a release without running the CLI.

The document#

Every case is a concrete input with the exact expected output. The document's header names the artifact, its versions and the engine functions it was generated from; the first case looks like this (the full artifact has 69, all of the same shape):

{
  "artifact": "hekma-governance-vectors",
  "schema_version": 1,
  "vectors_version": "1.4.0",
  "provenance": {
    "generated_from": [
      "BudgetEvaluator",
      "CostEvaluator",
      "cost_micros",
      "cost_micros_with_cached",
      "governance::decide",
      "governance::fence_refusal",
      "governance::decide_chain",
      "runs::policy::resolve",
      "governance::rearm"
    ]
  },
  "cases": [
    {
      "kind": "decision",
      "id": "decision-threshold-ge-exact-at-ceiling",
      "covers": ["threshold-ge"],
      "input": {
        "token": {
          "run_total": 0,
          "cumulative_total": 100,
          "budget": { "per_run": null, "cumulative": 100 },
          "action": "pause"
        },
        "latched": []
      },
      "expected": {
        "decisions": [
          {
            "dimension": "tokens",
            "scope": "cumulative",
            "action": "pause",
            "limit": 100,
            "observed": 100
          }
        ],
        "latched_after": [{ "dimension": "tokens", "scope": "cumulative" }]
      }
    }
  ]
}

Case kinds#

KindCasesWhat it checks
decision20One full budget evaluation. In: each armed dimension with its committed totals, ceilings and breach action, and which (dimension, scope) pairs have already fired this Run. Out: the breaches that fire, in order (tokens before dollars), and the fired pairs afterwards.
derivation11One cost calculation. In: token counts and rates. Out: the cost in integer micro-dollars (expected_micros). The derivation field names which one: cost-micros (per-direction prices), cost-micros-with-cached (with the cached-token split) or two-row-own-rate-sum (two ledger rows, each priced at its own stored rate).
fence5The block wire fence. In: the raised fence reasons, one per (dimension, scope) whose breach fired block. Out: the refusal, with status 402, error_type hekma_budget_block, the code and the reported reason, or null when no reason is raised. The response itself is described under the refusal. Since 1.1.0.
chain5Ceilings across a Run's ancestors. In: one decision-shaped input per level, from the Run the usage is attributed to up to the Run that owns the process, each with its own subtree totals and its own fired pairs. Out: one outcome per level, in the same order. Every level decides on its own, so a child Run's breach never hides its parent's, and a parent's ceiling binds its children's usage. A one-level chain is exactly a decision. Since 1.2.0.
policy18Policy resolution. In: the Run's depth, wire path and bound labels, its explicit limits, the policy set and the model. Out: the exact resolution, with the effective ceilings and action and each limit's source, the depth fallback, and the unpriced-cap signal. Since 1.3.0. Two more decision-policy-* cases, counted under decision, check a resolved Policy limit in a full evaluation. Six policy-caller-* cases, appended at 1.4.0, pin the resolver's Caller layer: a Run's own limits, applied only where tighter.
rearm10The within-Run re-arm after a limit changes. In: the level's ceilings after the change (arms, with arms_before as context only), its effective action, whether a Rate resolves, its committed totals (the Run's own for the per-run scopes, the agent's lifetime totals for the cumulative ones) and its latches before the change. Out: the latches released (unlatched), the block fence reasons lifted (fence_cleared), the breaches the change fires at once (fired), the latches and fence reasons after, and whether the Run's breach Anomaly holds. Since 1.4.0.

trigger on a rearm case names what moved the ceiling: a Policy change (policy-change), a limit set on the Run (run-limits) or an agent configuration write (config-write). It is context, not an input: the rule never reads it, so the expected outcome never depends on it, and three cases carry the same input under all three so a consumer that branched on it would fail. These cases pin the rule, not the engine's three paths to it; that each path hands the rule the same input is the engine's own tested contract.

A later minor version may add a case kind, as 1.1.0 added fence, 1.2.0 chain, 1.3.0 policy and 1.4.0 rearm; versioning says what that means for a pinned consumer.

Rule tags#

Every case lists the rules it pins in covers, and every rule has at least one case:

TagRule
threshold-geA ceiling breaches at or above the limit: exactly at the limit breaches, one below does not, and a zero ceiling breaches on zero.
latch-per-scopeA (dimension, scope) pair that already fired never fires again; tokens and dollars of the same scope are independent.
latch-re-armAt a new Run the fired pairs reset, so the same totals fire again.
token-before-dollarWhen both dimensions are armed and both trip, the token breach comes first.
integer-microsMoney is integer micro-dollars throughout: per-direction rates, the cached-token split, no floating point, no wrapping.
round-half-upA token-times-rate division rounds half up, each direction on its own. One case puts both directions exactly at the tie, where rounding the sum instead gives 3 rather than 4.
saturationA runaway product stops at the integer maximum and never wraps, so a cost can never quietly fall back under its cap.
no-retro-repricingEach ledger row is priced at the rate stored with it; repricing history at the latest rate gives a different, wrong total.
block-fenceA block breach fires under the same threshold, once-per-Run and ordering rules as any other action. A fenced Run refuses with status 402 and the hekma_budget_block type, reporting the first raised reason: tokens before dollars, per-run before cumulative. Since 1.1.0.
ancestor-ceilingsAcross a Run's ancestor chain, each level decides on its own subtree totals and its own fired pairs; outcomes come deepest level first, tokens before dollars within a level. Since 1.2.0.
policy-resolutionEach limit resolves on its own: explicit limits on the Run, then on the agent, outrank every Policy. Per limit, the most specific Selector (a strict term-set superset) wins, incomparable Selectors tie to the tightest value, and the default Policy fills what is unset. A malformed action fails closed to pause, an action the depth cannot execute acts as warn, and a Cost Cap with no Rate is loud, never silently inert. Since 1.3.0.
re-armAfter a limit change, a latch whose ceiling is now above its total, or no longer set, re-arms, and its block fence reason lifts per reason; a fence holding another latched block reason stays up. A ceiling at or below its total keeps its latch, and one lowered to at or below the total fires at once. A latch is keyed by the action that recorded it, so a kept pair fires once more under a new action. The outcome is the same whatever moved the ceiling. Since 1.4.0.

Pin it in your Host#

  1. Record the version and the checksum. Keep the vectors_version you verified against and the SHA-256 of the artifact: the published .sha256 file, or hekma agent governance-vectors --json | sha256sum.
  2. Re-run every case. For a decision case, feed input to your guard and compare the breaches it fires, in order, and the fired pairs afterwards with expected. For a derivation case, run the named calculation and compare the micro-dollars with expected_micros. For a chain case, run every level and compare the outcomes level by level. For a fence case, compare your refusal with expected. For a policy case, resolve the input with your own resolution and compare every field of the expected resolution. For a rearm case, release the latches whose ceiling is now above the total (or unset), lift their block reasons, then run your guard over the new ceilings with the kept latches under the current action, and compare every field of expected.
  3. Fail on any difference. A mismatch means your guard disagrees with Hekma on a pinned rule. Fix the guard, or open an issue if you think the case is wrong; never skip it.
  4. Re-run on every upgrade. A new minor version only adds cases after the ones you already pass, so your existing results stay valid and the new cases extend the proof.

A Rust Host can skip the re-implementation: the engine exposes the same decision code (governance::decide, decide_chain, fence_refusal, rearm and the cost derivations) in its public API. See Embed the engine.

Parse integers without loss#

Every number in the artifact is a JSON integer, and the saturation cases carry values above 2^53, more than a JavaScript Number holds exactly. Parse them through a float and the case is silently corrupted, so it can pass or fail for the wrong reason. In JavaScript, use a BigInt-aware JSON parser, or JSON.parse with a reviver for the numeric fields. The fields that carry the extremes:

  • input_tokens and output_tokens: the largest 64-bit unsigned integer in the saturation cases (derivation-saturation-max-tokens-max-rate and derivation-saturation-cached-derivation-saturates).
  • cached_tokens: the same value, in the second of those cases.
  • rate.input_micros_per_1m and rate.output_micros_per_1m: the same value, in both cases; rate.cached_micros_per_1m, in the second.
  • expected_micros: the largest 64-bit signed integer, the saturation result itself.

Versioning#

vectors_version is a semantic version of the case set:

  • Added cases are a minor version. New cases may test the same rules or new ones, and may use a new case kind or a new value of an existing field. They are always appended: every case an earlier version shipped keeps its bytes and its position. A consumer pinned to an earlier version re-runs that version's cases, the leading part of the list, and stays green; adopting the new cases is recommended but not required.

    VersionCasesAdded
    1.0.01 to 26The first decision and derivation cases.
    1.1.027 to 34The decision-block-* cases and the fence-* cases, with the block action and the block-fence tag.
    1.2.035 to 39The chain-* cases, with the ancestor-ceilings tag.
    1.3.040 to 53The policy-* cases and two decision-policy-* cases, with the policy-resolution tag.
    1.4.054 to 69The rearm-* cases, with the re-arm tag, then the six policy-caller-* cases for the resolver's Caller layer (a Run's own limits, applied only where tighter).

    The provenance list grows with the functions the new cases come from: 1.1.0 added governance::fence_refusal, 1.2.0 governance::decide_chain, 1.3.0 runs::policy::resolve, 1.4.0 governance::rearm.

  • Changing a shipped case is a major version, as is changing its input or expected output, or the shape of the header or of an existing kind. A major version is announced in the release notes ahead of the release. It means you must verify again; it does not by itself mean enforcement changed, only that the proof did.

The checksum protects the bytes in transit: a match means you have exactly the artifact a release carried. The version tells you what its cases promise. Pin the version and the checksum together; the provenance list names the engine functions the cases were generated from, not a crate version, and is not a pin.

What the vectors are not#

They describe decisions, not enforcement. Hekma meters cooperatively and acts through the agent's lifecycle and its own metering listener; a Host using the vectors re-implements the decision rules at its own choke point. The artifact carries no sandbox, no process control and no cryptographic attestation. It is a public, deterministic record of the rules, and its checksum is for spotting tampering in transit, not for secrecy.

The behaviour the cases pin is the one Budgets and cost describes: the same thresholds, the same once-per-Run rule and the same tokens-before-dollars order. The vectors give it a portable, checkable form; they do not define a second behaviour.