Data Model: Rules Engine
Overview
The rules engine stores JDM (JSON Decision Model) rule sets and a full audit trail of every evaluation.
Rule sets are cached in memory at startup; at runtime the cache converges on the database through
identity-aware conditional applies keyed on the trigger-enforced (id, revision) pair (#1188 / the
ADR-006 #1188 amendment) — driven by RabbitMQ rules.cache_invalidated events from peers AND a
periodic reconcile sweep (CRAIG_RULES__DECISION_REFRESH_SECONDS) that bounds staleness when an
event is lost.
The fleet-standard platform tables also live in this schema and are documented
centrally: event_outbox / event_inbox / event_inbox_collisions
(ADR-022 and the ADR-062 §A
attempt machine), request_claims
(ADR-062 §B), and
schema_compat_floor (ADR-063).
A claim’s actor is the ADR-085 D3 column pair (#2740): request_claims.created_by_sub holds a worker’s UUID
and created_by_sub_service a service’s service:<name> encoding, with a CHECK that exactly one is set.
Recorders name the acting worker (#2321). No craig-rules recorder (a who-acted column or an event’s actor key)
names the request token’s own sub / preferred_username: under a BFF-lifted token that token is craig-web’s
service principal, so a staff write names claims.acting_worker() or the claim’s effective actor (ADR-028, ADR-062),
the lifted worker, or the token’s own subject when nothing is lifted. That covers rule_sets.created_by /
created_by_name / updated_by / updated_by_name (a soft delete restamps both halves, #2320),
rule_set_snapshots.actor_sub / actor_display, and the rules.ruleset_promoted / rules.ruleset_rolled_back
user_id, beside rule_evaluations.evaluated_by (#1060). Each name column is the acting worker’s username.
Since #2522 the Claims fields are private and crates/craig-test-lib/tests/acting_identity_census.rs pins it: the
token’s own identity is read only through a bearer() accessor, each such read under services/craig-rules/src
is pinned with its reason, and a recorded worker is claims.worker_subject(), which reads the
claims.acting_worker() view, never the bare claims (#2740 removed parse_sub / parse_actor_sub).
Tables
| Table | Purpose |
|---|---|
|
JDM rule set definitions — content stored as JSONB, soft-deleted via |
|
Audit trail — every evaluation recorded with input, output, context, and evaluator ( |
|
#1129 (ADR-058 D8): rules' OWN durable archive ledger — one row per archived batch (object keys, sha256, D9 store identity, the [min, max] id range per D17), written inside the prune transaction; the authority orphan GC consults (the event to security is secondary bookkeeping) |
|
#1556 (D2): insert-only content history — one row per API-path mutation, same-tx, keyed
|
|
#1556 (D2): the promote two-step’s DB-backed evidence — candidate hash + from_revision binding, corpus fingerprint, thin-corpus flag, the categorical diff report. Never burned (a successful execute bumps the live revision, so replays 409 on the CAS). Audit-class, keep-forever-hot. |