Rules Engine API Reference
Manages the JSON Decision Model (JDM) rule sets behind CRAIG’s automated determinations and evaluates inputs against them via the GoRules Zen Engine.
Endpoints
Background Jobs
Poll a background job
GET /v1/rules/jobs/{id}
The generic read-only poll of a rules background job: the job as a LOGICAL resource — state (queued / running / succeeded / failed; the last two are terminal and immutable), the current attempt and the attempts[] ledger (an interrupted / crash attempt re-queues a convergent kind up to max_attempts), the typed progress document, result (the kind’s report — for promote_preview { preview_id, report }, the persisted canary evidence + the execute binding — present iff succeeded), error (a CLOSED token + a categorical detail — engine_failed with live-revision-moved when the live head moved between enqueue and start: re-preview — present iff failed), and resource when the kind links its own row. Authorized on the BackgroundJob resource type: admin realm-flat, the creator (human or service principal) by assigned_worker_sub; another actor is the fleet’s typed 403; an unknown id is 404 (no existence collapse — the row is looked up before the check). Cache-Control: no-store. Never writes.
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Job id — the last segment of the |
-
200: The job (
Cache-Control: no-store) -
401: Unauthorized
-
403: Forbidden — not the creator and not admin
-
404: No such job
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Evaluation
Evaluate input against a rule set
POST /v1/rules/evaluate
Runs the named rule set against the provided input and records an audit trail. With expect, it runs only if the active rule set is exactly that (rule_set_id, revision); otherwise it answers 409 ruleset-moved naming the active identity, and nothing is evaluated or recorded.
| Field | Type | Required | Description |
|---|---|---|---|
context_id |
UUID (optional) |
No |
Optional context entity ID for the audit trail. |
context_type |
string (optional) |
No |
Optional context type for the audit trail (e.g. "eligibility", "case").
A NUL (U+0000), which the column cannot store, is a 422
|
expect |
ExpectedRuleSet (optional) |
No |
Expect |
input |
object |
Yes |
Input data to feed into the rule set. It may nest at most 16 levels,
hold at most 5,000 values, and no string or key longer than 16,384
bytes. A document past a limit, or with a NUL (U+0000) in any string
or object key, is a 422 |
pin |
EvaluationPin (optional) |
No |
Pin |
rule_set |
string |
Yes |
Name of the rule set to evaluate against (resolved against the in-memory
cache on a live evaluation and advisory when |
-
200: Evaluation result
-
400: Bad request:
pinwithexpect(exclusive), or a pinned snapshot that no longer compiles (invalid-ruleset) -
401: Unauthorized
-
403: Forbidden
-
404: Rule set not found
-
409: ruleset-moved: the active rule set is not the `expect`ed (rule_set_id, revision); the detail names the active identity, and nothing ran or was recorded
-
422: validation-failed:
rule_setorcontext_typeover 64 bytes, or a NUL (U+0000) ininputorcontext_type -
500: Internal error
-
503: Evaluation exceeded the dispatch budget (CRAIG_RULES__EVAL_TIMEOUT_MS)
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
List evaluation audit records
GET /v1/rules/evaluations
Paginated and filterable list of past rule evaluations. Requires supervisor or admin role.
| Name | In | Required | Description |
|---|---|---|---|
page |
query |
No |
Page number (1-based). |
per_page |
query |
No |
Items per page (max 500). |
context_type |
query |
No |
Filter by context type. A NUL (U+0000), which the query’s |
context_id |
query |
No |
Filter by context entity ID. |
rule_set_name |
query |
No |
Filter by rule set name. A NUL (U+0000), which the query’s |
disposition |
query |
No |
Filter by disposition: |
-
200: Paginated list of evaluations
-
400: Unknown disposition filter or page depth past the cap; a malformed query parameter (e.g. a non-UUID
context_id) is the extractor’s value-freebad-requestproblem, before the handler -
401: Unauthorized
-
403: Forbidden — supervisor or admin role required; an assignment-scoped grant is refused rather than widened, since evaluations carry no per-worker ownership
-
422: A filter over its length cap:
context_type/rule_set_name64,disposition32 bytes; or a NUL (U+0000) incontext_typeorrule_set_name(validation-failednaming the parameter, value-free) -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
EventReplay
Replay outbox events in a time window
POST /v1/admin/events/replay
Re-stages the published outbox rows created in [from, to] (optionally one event_type) so the outbox worker republishes them. At most 100000 rows per call; when more is true, call again with the same window and resume_from. Rows already pending are left alone. dry_run=true only counts. A from older than the service’s outbox retention window is refused. Each batch commits on its own, so after a 5xx the committed batches stay re-staged and re-running the same window picks up the rest. Every admitted call, a dry run included, records an admin.events_replayed act naming the worker.
| Name | In | Required | Description |
|---|---|---|---|
from |
query |
Yes |
RFC 3339 inclusive lower bound on |
to |
query |
Yes |
RFC 3339 inclusive upper bound on |
event_type |
query |
No |
Optional |
dry_run |
query |
No |
If true, return the would-replay count without modifying rows. |
resume_from |
query |
No |
The |
-
200: The window’s count and what this call re-staged
-
400:
bad-request: a malformed or missingfrom/to, a non-booleandry_run,fromafterto,fromolder than the outbox retention window, or aresume_fromthat is not a replay cursor (fieldnames it) -
401: Missing or invalid bearer token
-
403: The acting identity is not an admin, or is a bare service principal (
worker-required): a replay is a worker’s act -
422:
validation-failed:event_typelonger than 255 bytes -
500: Internal error (the re-staged count overflowed, or an unclassified database error); batches already committed stay committed
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Rule Sets
List active rule sets
GET /v1/rules/sets
| Name | In | Required | Description |
|---|---|---|---|
page |
query |
No |
Page number (1-based). |
per_page |
query |
No |
Items per page (max 500). |
search |
query |
No |
Full-text search across name and description. A NUL (U+0000), which
the query’s |
prefix |
query |
No |
Prefix filter (e.g. |
sort_by |
query |
No |
Sort column: name, version (default: |
sort_dir |
query |
No |
Sort direction: asc or desc (default: desc). |
include |
query |
No |
|
-
200: Paginated list of active rule sets. Each row is a summary; its
content(the decision graph) is present only underinclude=content -
400: A page past the depth cap; a malformed query parameter (e.g. a non-integer
page) is the extractor’s value-freebad-requestproblem, before the handler -
401: Unauthorized
-
403: Forbidden — including a worker- or supervisor-scoped caller: these rows carry no per-worker ownership, so an assignment scope is refused rather than widened
-
422: A filter over its length cap:
search500,prefix64,sort_by/sort_dir32 bytes; or a NUL (U+0000) insearchorprefix(validation-failednaming the parameter, value-free) -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Create a new rule set
POST /v1/rules/sets
Validates that the JDM content compiles before persisting. Requires admin role.
| Field | Type | Required | Description |
|---|---|---|---|
client_request_id |
UUID |
Yes |
Client-minted idempotency id — REQUIRED.
Same id + identical intent replays the ORIGINAL rule set (the
row as the detail projection now serves it); a different intent
under the same id is a 409 idempotency-conflict. A same-name
create under a FRESH id stays the domain 409 (the retained
|
content |
object |
Yes |
JDM decision model content ( |
description |
string (optional) |
No |
Optional description. A NUL (U+0000), which the column cannot store, is
a 422 |
name |
string |
Yes |
Human-readable name (must be unique). Lowercase with interior
hyphens/underscores: |
version |
string |
Yes |
Semantic version string (at most 64 bytes, |
-
200: Rule set created (a replay returns the rule set as the detail projection now serves it — same client_request_id + intent)
-
400: Invalid JDM content
-
401: Unauthorized
-
403: Forbidden — admin role required
-
409: Name already exists, client_request_id claimed by a different operation, replayed entity gone, or
config-managed(this deployment’s rule sets come from its configuration source) -
422: Validation failure (
validation-failed): a missingclient_request_id, an invalidname,versionover 64 bytes, or a NUL (U+0000) inversion,description, orcontent -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Get an active rule set by name
GET /v1/rules/sets/by-name/{name}
| Name | In | Required | Description |
|---|---|---|---|
name |
path |
Yes |
Rule set name (unique) |
-
200: Rule set found
-
401: Unauthorized
-
403: Forbidden
-
404: Rule set not found
-
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Get a rule set by ID
GET /v1/rules/sets/{id}
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
-
200: Rule set found
-
401: Unauthorized
-
403: Forbidden
-
404: Rule set not found
-
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Update a rule set
PUT /v1/rules/sets/{id}
Partial update — only provided fields are changed. Validates JDM if content is updated. Requires admin role.
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
If-Match |
header |
Yes |
REQUIRED row REVISION from your last read, e.g. |
| Field | Type | Required | Description |
|---|---|---|---|
content |
object |
No |
New JDM content (optional, validated if provided). The same size
limits as on create apply; a document past one, or with a NUL (U+0000)
in any string or object key, is a 422 |
description |
string (optional) |
No |
New description (optional). A NUL (U+0000), which the column cannot
store, is a 422 |
name |
string (optional) |
No |
New name (optional). When present, same charset as create. |
version |
string (optional) |
No |
New version (optional; at most 64 bytes, |
-
200: Rule set updated
-
400: Invalid JDM content, or a missing/malformed If-Match
-
401: Unauthorized
-
403: Forbidden — admin role required
-
404: Rule set not found
-
409: Name already exists, the revision moved since your read (stale If-Match), or
config-managed(this deployment’s rule sets come from its configuration source) -
422: A body field whose value does not deserialize, e.g. a non-string
name(validation-failed; the field is named, the value never echoed), anamethat is not 1-64 lowercase letters, digits, hyphens or underscores,versionover 64 bytes, or a NUL (U+0000) inversion,description, orcontent(validation-failed) -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Delete a rule set
DELETE /v1/rules/sets/{id}
Soft-deletes by setting active = false. Requires admin role and a reason query parameter (recorded on the audit snapshot).
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
reason |
query |
Yes |
Why this rule set is being retired (mandatory; audit-visible on
the delete snapshot row). A NUL (U+0000), which the snapshot row
cannot store, is a 422 |
-
204: Rule set deleted
-
400: Missing
reasonquery parameter -
401: Unauthorized
-
403: Forbidden — admin role required
-
404: Rule set not found
-
409:
config-managed: this deployment’s rule sets come from its configuration source -
422: Empty/over-length
reason, or areasoncontaining a NUL (U+0000), which the delete snapshot cannot store (validation-failednamingreason, value-free) -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Export a rule set as a downloadable JSON file
GET /v1/rules/sets/{id}/export
Returns the JDM content as an attachment. Requires admin role.
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
-
200: JDM JSON file
-
401: Unauthorized
-
403: Forbidden — admin role required
-
404: Rule set not found
-
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Import JDM content into an existing rule set
POST /v1/rules/sets/{id}/import
Replaces the rule set content with the wrapper’s JDM content and auto-generates a timestamp version. The body is the {client_request_id, content} wrapper, not a bare JDM document. Requires admin role.
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
| Field | Type | Required | Description |
|---|---|---|---|
client_request_id |
UUID |
Yes |
Client-minted idempotency id — REQUIRED. Import is a command on the PATH rule set (the claim’s entity is the path id, not a fresh row): same id + identical intent replays without re-importing (the rule set is returned as it now stands — no second version mint, no revision bump); a different intent — including the same content aimed at a different rule set — is a 409 idempotency-conflict. |
content |
object |
Yes |
JDM decision model content ( |
-
200: Rule set content imported (a replay returns the rule set as it now stands — same client_request_id + intent; no second version mint or revision bump)
-
400: Invalid JDM content
-
401: Unauthorized
-
403: Forbidden — admin role required
-
404: Rule set not found (the claim rolls back — the request id is not burned)
-
409: client_request_id claimed by a different operation, replayed entity gone, or
config-managed(this deployment’s rule sets come from its configuration source) -
422: Malformed wrapper body (including a missing
client_request_id— a bare JDM document is one) or a NUL (U+0000) incontent(validation-failed) -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Execute a previewed promotion (the consent act)
POST /v1/rules/sets/{id}/promote
Re-binds the candidate content by canonical hash to the named preview, re-CASes the live revision against the preview’s from_revision INSIDE the flip transaction (409 promote-preview-stale; the preview is never burned), then flips content + version, writes the promote snapshot carrying the canary report as evidence, and stages the invalidation + audit events on the same transaction.
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
| Field | Type | Required | Description |
|---|---|---|---|
acknowledged_thin_corpus |
boolean |
No |
The thin-corpus consent: when the preview’s corpus was below the evidence floor, the flip refuses unless this names the gap explicitly (an empty diff over an empty corpus is NOT evidence — the zero-fault-green class). |
client_request_id |
UUID |
Yes |
Client-minted idempotency id — REQUIRED. |
content |
object |
Yes |
Candidate JDM content — must hash-match the preview’s binding. The
same size limits as the preview’s content apply; a document past one,
or with a NUL (U+0000) in any string or object key, is a 422
|
preview_id |
UUID |
Yes |
The preview whose evidence this execute consents to. |
reason |
string |
Yes |
Why this promotion is happening (recorded on the snapshot; may
restate or extend the preview’s reason). A NUL (U+0000), which the
column cannot store, is a 422 |
version |
string |
Yes |
Must equal the preview’s candidate version. A NUL (U+0000), which the
column cannot store, is a 422 |
-
200: Promoted (a replay returns the rule set as it now stands)
-
400: Invalid JDM content
-
401: Unauthorized
-
403: Forbidden
-
404: Rule set or preview not found
-
409: promote-preview-stale (live revision moved; re-preview), promote-preview-mismatch (content/version/target differ from the preview’s binding), thin-corpus-unacknowledged, an idempotency conflict, or
config-managed(this deployment’s rule sets come from its configuration source) -
422: Validation failure (
validation-failed) — a missingclient_request_id, an out-of-rangeversion/reason, or a NUL (U+0000) inversion,reason, orcontent -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Enqueue a promotion preview: compile + shadow-canary the candidate as a background job
POST /v1/rules/sets/{id}/promote/preview
Enqueues the promotion preview as the promote_preview background job: the attempt re-reads the live head, replays the last-N real evaluation inputs against live AND candidate on an isolated thread (one cancel checkpoint per item), persists the categorical diff report, and the job’s result is { preview_id, report } — the execute binding. No flip happens here; previews are never burned. The synchronous checks stay synchronous: invalid JDM or the LIVE version string reused with different content is 400, an inactive set 404. Body = the candidate + client_request_id (REQUIRED; the same id replays the SAME job whatever its state, a fresh id is a new job; any field outside the contract is 422 validation-failed). Answers 202 with Location: /v1/rules/jobs/{id} and the job (state = queued); poll the Location until succeeded or failed (error.token closed: engine_failed with detail live-revision-moved when the live revision moved between enqueue and the attempt — re-preview; exhausted after three crashed / interrupted attempts). A second preview of the same rule set while one is queued or running is 409 job-already-active.
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
| Field | Type | Required | Description |
|---|---|---|---|
client_request_id |
UUID |
Yes |
Client-minted idempotency id — REQUIRED: the same id replays the SAME preview job (whatever its state); a fresh id is a new job. |
content |
object |
Yes |
Candidate JDM content ( |
reason |
string |
Yes |
Why this promotion is happening (audit-visible; recorded on the
preview row and, at execute, the promote snapshot). A NUL (U+0000),
which the column cannot store, is a 422 |
version |
string |
Yes |
The version string the candidate will carry once promoted.
Reusing the LIVE version string with different content is
refused (version strings stay human-meaningful even though the
revision is the true content key). A NUL (U+0000), which the column
cannot store, is a 422 |
-
202: Preview enqueued (or a replay of the stored job — nothing re-enqueued);
Location=/v1/rules/jobs/{id} -
400: Invalid JDM content, or the LIVE version string reused with different content
-
401: Unauthorized
-
403: Forbidden — requires RuleSet Update AND RuleEvaluation List (the corpus leg replays real evaluation inputs)
-
404: Rule set not found
-
409: A preview of this rule set is already queued or running (
job-already-active), or this client_request_id was used with a different intent (idempotency-conflict) -
422: Validation failure — a missing
client_request_id, a forged field, an out-of-rangeversion/reason, or a NUL (U+0000) inversion,reason, orcontent(validation-failed) -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.
Roll back to a snapshotted revision (as a NEW revision)
POST /v1/rules/sets/{id}/rollback
Restores the content + version of the snapshot at (this rule set, target_revision) as a NEW revision — monotone history, the counter never rewinds. No canary (the target content previously served); the content is compile-revalidated because the engine may have moved since the snapshot’s vintage. Refuses on soft-deleted rule sets (recreate is the path — the rebinding doctrine).
| Name | In | Required | Description |
|---|---|---|---|
id |
path |
Yes |
Rule set ID |
| Field | Type | Required | Description |
|---|---|---|---|
client_request_id |
UUID |
Yes |
Client-minted idempotency id — REQUIRED. |
expected_revision |
integer |
Yes |
The live revision this rollback expects to move FROM (the CAS — a concurrent mutation 409s instead of silently compounding). |
reason |
string |
Yes |
Why this rollback is happening (mandatory; an unexplained
rollback of eligibility policy is itself an audit finding). A NUL
(U+0000), which the column cannot store, is a 422 |
target_revision |
integer |
Yes |
The snapshot revision to restore — resolved by the FULL
|
-
200: Rolled back (a replay returns the rule set as it now stands)
-
400: The snapshot’s content no longer compiles under the current engine
-
401: Unauthorized
-
403: Forbidden
-
404: Rule set (or an inactive one), or no snapshot at target_revision
-
409: The live revision moved since expected_revision (re-read and retry), an idempotency conflict, or
config-managed(this deployment’s rule sets come from its configuration source) -
422: Validation failure (
validation-failed) — a missingclient_request_id, an out-of-rangetarget_revision/expected_revision/reason, or a NUL (U+0000) inreason -
500: Internal error
-
503: Service Unavailable (RFC 9457 problem document): database pool exhaustion (carries Retry-After: 5), db-connection-lost, db-outcome-unknown, or a synchronous upstream dependency refusal.
-
504: Gateway Timeout (RFC 9457 problem document): the route-class request ceiling elapsed (request-timeout) or the database canceled the statement (db-timeout) — the server yields first.