Plan: Safety Assessment Inputs — a ruleset-declared fact surface (#3104)
- Status
- Context
- Rulings this plan implements (maintainer, 2026-11-15)
- Design
- D1. One assessment per investigation; the child facts are attested
- D2. The declaration:
metadata.safetyand a closed, fully required inputNode schema - D3. Contracts
- D4. craig-cases: the surface, the read and the act
- D5. The integer fact and the form’s controls
- D6. The gate in
cargo xtask rules check(newxtask/src/cmd/rules_safety.rs) - D7. Clients, fixture and seed
- Scope and order (three repositories)
- Risks
- Tests
- Delivery
- Errata
- Review log
Status
Done (2026-11-16) — the safety assessment evaluates the facts each jurisdiction’s ruleset declares; an incomplete answer set is refused by craig-cases and by the rules service, and an override needs a reason.
Closes: #3104 (P1). Relates to: #1661, #1667, #2389.
Branch: fix/safety-assessment-inputs. Written against main of 2026-11-15.
Precondition: the Georgia pin carrying georgia-safety-assessment v3.0 (#1661) is on main.
A Design + Scope plan. It freezes when work starts; a deviation is a one-line erratum.
Context
-
The input is two keys nobody reads.
services/craig-cases/src/api/investigations/safety.rs:57-60evaluates the jurisdiction’s safety ruleset with{"threats", "protective_capacities"}, two untyped JSON values of the request (crates/craig-cases-contracts/src/investigations.rs:161,:166). Neither shipped ruleset has a column of either name, so every row that needs a true input fails to match and the last, total row answersSAFE. Only the worker override moves the stored decision. -
Neither ruleset declares anything. Both files have no
metadataand no inputNode schema, so the rules service accepts any document, an empty one included. Texas’s graph has an edge from the inputNode tosafety-decision, a table that reads only its parents' outputs; the Texas config agent reports that sendingpresent_danger_active: truedecidesUNSAFEfrom the input alone (not re-run for this plan). -
An assessment is per investigation.
safety_assessmentshasinvestigation_idand no child column (services/craig-cases/migrations/20240201000000_create_case_tables.sql:64-76). -
Why no test saw it. The ruleset suites call the engine with the right keys; the cases suites script the evaluate on a double or assert only that the decision is not
UNKNOWN(services/craig-cases/tests/api/investigations.rs:457-496). -
An override needs no reason.
worker_overridemay replaceUNSAFEwithSAFEwhileworker_override_reasonis null (crates/craig-cases-contracts/src/investigations.rs:169-174). -
The pattern exists twice. Intake screening (
metadata.screening.attestable_facts,services/craig-cases/src/screening_surface_client.rs, served byservices/craig-cases/src/api/reports/screening_surface.rs) and IV-E (metadata.ive.inputs,crates/craig-cases-contracts/src/ive_surface.rs, lint censusxtask/src/cmd/rules_ive.rs:259-285).
Rulings this plan implements (maintainer, 2026-11-15)
-
Stored safety assessments are deleted by the migration, overrides included; the release note says they are unrecoverable.
-
The ruleset’s input schema lists every fact under
required, so the rules service itself refuses an incomplete input. -
A worker override must carry a non-empty reason. A supervisor step for an override is a follow-up issue.
-
The published manual decides policy; nothing waits on an agency.
Design
D1. One assessment per investigation; the child facts are attested
The assessment stays per investigation. child_age, child_has_disability and Texas’s child_nonverbal are
declared attestable; each description says whose fact it is ("the youngest or most vulnerable child of the
investigation"). Both config agents report that neither safety_decision depends on them today;
the_child_facts_do_not_move_either_shipped_safety_decision holds that. Per-child assessment is a follow-up.
D2. The declaration: metadata.safety and a closed, fully required inputNode schema
-
metadata.safetyis a closed object with one member,attestable_facts: a non-empty array of closed{key, title, description}objects.keymatchesFactKey(crates/craig-cases-contracts/src/reports.rs) and is unique;titleis non-blank, at most 100 characters;descriptionnon-blank, at most 2000. -
The inputNode
content.schemais a JSON string:"type":"object","additionalProperties":false,"properties", and"required"listing every property. Each property is exactly{"type":"boolean"}or{"type":"integer","minimum":m}with an optional"maximum",mnot negative. -
Every schema property is a declared fact or a server key (D3), every declared fact is a schema property, and
requiredequals the property set. The projection refuses anything else. -
Some table output is named
safety_decision(checked by the gate, D6). -
Descriptions carry the answering rule, because every fact must be answered and conditional questions are out of scope. Required wording, written in the config repositories: the threshold criteria say "Answer No when no impending danger threat is identified" and "all of these criteria describe one and the same threat, for at least one identified threat"; Georgia’s
in_home_safety_plan_criteria_metsays "Answer as if a safety plan were needed"; the count says what is counted. Only non-blank text is checked mechanically; the wording is reviewed in each config merge request and at the pin.
D3. Contracts
New crates/craig-cases-contracts/src/safety_surface.rs:
-
SafetySurfaceResponse {rule_set_name, identity: IveRulesetIdentity, facts: Vec<SafetyFactView>};SafetyFactView {key, title, description, kind};SafetyFactKindisBooleanorInteger {minimum: i64, maximum: Option<i64>}, tagged likeIveInputKind. -
project_safety_surface(name, identity, ruleset_bytes, server_keys) → Result<_, SafetySurfaceError>, onethiserrorvariant per refusal. It shares the IV-E projection’s parts: lift the duplicate-rejecting JSON reader,input_schema,property_kindwith its numeric bounds andcheck_textfromive_surface.rsinto a crate-privatedeclared_surface.rs;ive_surface.rscalls them unchanged.root_propertiesis not shared: the IV-E one refuses any non-emptyrequired. The safety projection has its own root reader, which demands thatrequiredequals the property set. -
SAFETY_SERVER_KEYS: &[&str], the keys craig-cases derives. Empty in this fix; passed as a parameter so both of its rules are tested with a non-empty list. -
The request,
#[serde(deny_unknown_fields)]:{ "client_request_id": "…", "surface": { "rule_set_id": "…", "revision": 7 }, "facts": { "present_danger_identified": false, "impending_danger_threats_count": 0 }, "worker_override": null, "worker_override_reason": null }factsisSafetyFacts, a newtype overBTreeMap<FactKey, SafetyFactValue>withSafetyFactValue::{Bool(bool), Count(u32)}, deserialised by a visitor that refuses a repeated key and the 33rd entry, asAttestedFactsdoes (reuseFactKeyandMAX_ATTESTED_FACTS; do not makeAttestedFactsgeneric). A string, float, negative number, null or object value is a 422 at deserialisation.threatsandprotective_capacitiesare gone, with no shim. -
The response and the stored row.
SafetyAssessment(services/craig-cases/src/store/models.rs:614-643), the 200 body of the act, losesthreatsandprotective_capacitiesand gainsfacts: SafetyFacts,rule_set_id,rule_set_revisionandevaluation_id. -
Override reason.
worker_overrideset with a blank or absentworker_override_reasonis 422validation-failednamingworker_override_reason. -
Problem types in
crates/craig-common/src/error.rs, each mirroring its screening or IV-E sibling:SAFETY_SURFACE_NOT_READY(503, one closed reason token),SAFETY_POLICY_MOVED(409),SAFETY_FACT_NOT_DECLARED(400),SAFETY_FACT_UNANSWERED(422).
D4. craig-cases: the surface, the read and the act
-
services/craig-cases/src/safety_surface_client.rs, modelled onservices/craig-cases/src/ive_surface_client.rs: one cached slot, a gate, a closed reason enum, a critical workersafety-surface-verifier. It reusesread_ruleset_by_name,ServiceBearer,find_node,schema_stringandspawn_surface_verifierfromscreening_surface_client.rs, and joinsSurfaceClientsinservices/craig-cases/src/lib.rs. -
GET /v1/cases/safety-surface, a copy of the screening read: authenticated,deny_pure_service, 200, 401, 403, 503safety-surface-not-ready. -
The act, in order: body validation (including the override reason); investigation read (404); authz (unchanged); replay precheck;
require_current(body.surface)(503, or 409safety-policy-movedafter one re-read and a cache eviction, as the IV-E client does);validate_facts;assemble_safety_document;validate_assembled; evaluate withexpect: Some(identity); a craig-rulesruleset-movedanswers the same 409; the claimed insert. -
validate_facts, in this order: a server key or an undeclared key is 400safety-fact-not-declarednaming the key; a value failing its compiled property is the same 400 naming the key and the expected kind, never the value (an_off_type_fact_refusal_names_the_key_and_kind_and_not_the_value); then the declared facts absent from the body are 422safety-fact-unanswered, the missing keys sorted in the detail. Nothing is consulted or stored on any refusal. Integer bounds are checked by the compiled property, not in Rust. -
assemble_safety_document: the attested facts verbatim, then server keys (none today). -
A missing
safety_decisionoutput is refused, not stored asUNKNOWN: the act answers the same upstream-defect status screening gives for a missing required output key, and stores nothing. -
Storage, one migration: delete every
safety_assessmentsrow and every request claim of the scopecases.submit_safety_assessment(services/craig-cases/src/api/intents/intake.rs:89-90); dropthreatsandprotective_capacities; addfacts JSONB NOT NULL CHECK (facts <> '{}'::jsonb),rule_set_id UUID NOT NULL,rule_set_revision BIGINT NOT NULL,evaluation_id UUID NOT NULL. The intent projection hashesfactsandsurfacein place of the two documents. -
utoipa
responses(…)of the act lists 400, both 409 causes, the 422 causes and 503.
D5. The integer fact and the form’s controls
The threat count and child_age are {"type":"integer","minimum":0}; the surface serves
{"kind":"integer","minimum":0}; the wire carries a JSON integer. The form renders a number input with min (and
max when declared) and parses it as an unsigned integer itself: it does not reuse the IV-E number() helper, which
produces a float. Booleans render as a required Yes / No pair, so unanswered differs from No.
D6. The gate in cargo xtask rules check (new xtask/src/cmd/rules_safety.rs)
Called from check_one beside the IV-E link. A ruleset carrying metadata.safety must pass the projection, the
Draft-7 compile and the IV-E graph census (make census and CensusFault in rules_ive.rs pub(super)): a table
read that is neither a schema property read over an edge from the inputNode nor a parent’s output is refused, as are
a declared key no table reads, a table output reusing an input key, and a graph with no safety_decision output.
Armed (step 5), a ruleset whose stem or name ends in -safety-assessment without metadata.safety is refused.
D7. Clients, fixture and seed
-
craig-web. The form reads the investigation and the surface; a failed surface read renders the upstream-failure page, with the retry handling of
services/craig-web/src/routes/cases/ive_determination.rs:133-147. One control per served fact; hiddensurface.rule_set_idandsurface.revision. No fact key is named in the template, route or catalogue. The override select requires a reason. The two JSON textareas and their catalogue keys go. -
CLI.
craig investigation safety-assessment <id> --facts JSON(inline,@fileor-) replaces--threatsand--protective-capacities; the command reads the surface for its identity. -
Fixture.
fixtures/config/testonia/testonia-safety-assessment.jsonhas one table that readschild_ageand outputs onlyvulnerability_level. In step 1 it gains a second output column,safety_decision(UNSAFEon its vulnerable row,SAFEon its total row), the schema requiringchild_age, andmetadata.safetydeclaringchild_age;fixtures/config/testonia/citations.tomlgains the matching rows, as that file’s existing rows are written. The fixture then passes the gate armed or unarmed. -
Seed.
tools/craig-seed/src/datagen/families.rs:577-606writes a complete answer set for the Georgia surface and a decision the ruleset gives for it (noSAFE_WITH_PLAN); its hashes are re-blessed.
Scope and order (three repositories)
The branch fix/safety-assessment-inputs is never rebased or force-pushed: config repositories pin its commits.
-
CRAIG, unarmed commit A. D3, D6 unarmed, the fixture, and
TWIN_ALLOWEDrows (xtask/src/cmd/rules_twins.rs):Properties(Input)for Georgia (impending_danger_threats_count,threat_observable,threat_vulnerable_child,threat_out_of_control,caregiver_protective_capacities_sufficient,in_home_safety_plan_criteria_met) and Texas (safety_threats_count,child_nonverbal,cognitive_capacity_sufficient,affective_capacity_sufficient,behavioral_capacity_sufficient); eachwhynames the manual section and ends "each file’s safety surface is its own". Push; do not open a merge request. File the follow-up issues. Verify here thatcargo xtask config fetchhonours a lock entry whosebranchis notmain; if it does not, stop and report. -
Georgia pushes a signed branch, unmerged: the row making impending danger with capacities absent
UNSAFE(citation as a recorded derivation); the schema of D2 over its eleven keys, none of them an intermediate key;metadata.safetywith D2’s wording; a version bump. Its pipeline is red on twin parity at this point, by design. -
CRAIG, unarmed commit B: the lock’s Georgia entry names that branch and commit.
-
Texas, one merge request with
CRAIG_VERSIONat commit B: the schema over its ten keys (omitting the two keys no longer read and the four intermediate keys); the edge from the inputNode tosafety-decisiondropped;metadata.safety; a version bump. Parity now compares new with new. Merge; post the commit. CRAIG commit C pins it. Georgia pointsCRAIG_VERSIONat commit C, goes green, fast-forwards main (same commit) and posts it. -
CRAIG, same branch. The lock pins both mains (
branch = "main"); arm D6; D4, D5, D7, tests, docs, fragment. Open and arm the merge request. -
Georgia and Texas repin
CRAIG_VERSIONto CRAIG’s merge.
Both files agree on what parity compares: a schema on both, additionalProperties: false, required over the five
shared properties, the same metadata shape, the same type for each shared property.
Out of scope, each a follow-up issue filed in step 1: Georgia’s per-threat threshold criteria; an attestable
indicator list that CRAIG counts; applies_when conditional questions; per-child assessment; a supervisor step for an
override; Texas’s CONDITIONALLY_SAFE, which the override enum cannot express. Not touched: #2389’s flag names.
Risks
| Risk | Class | Mitigation, and the test that pins it |
|---|---|---|
The assembled input again misses what a ruleset reads. |
fail-open |
|
A worker, or a direct caller of the rules service, leaves a fact unanswered and gets |
fail-open |
CRAIG refuses before the consult ( |
A caller sends an intermediate key and decides the outcome. |
fail-open |
|
An override replaces |
fail-open |
|
A ruleset declares no facts, or emits no |
fail-closed |
|
A ruleset lets a worker attest a server-derived key. |
fail-closed |
|
The policy moves between render and submit. |
fail-closed |
|
The surface is unverified at boot or after a bad promotion. |
fail-closed |
|
A description leaves a worker guessing, or reads the criteria across two threats. |
silent |
D2’s wording, reviewed in each config merge request and at the pin; |
One attested child stands for several children. |
silent |
The description says whose fact it is; |
The migration deletes stored assessments and overrides. |
silent |
Ruled; stated in the release note. |
The seed recreates a row with no facts. |
fail-closed |
The |
The lock cannot pin a config branch, or a config pipeline pairs its layer otherwise than assumed. |
fail-closed |
Verified in step 1 before any config change; a red config pipeline blocks only that merge. The agent posts the failing job before changing anything. |
The CRAIG branch is rewritten while a config main pins one of its commits. |
fail-closed |
The branch is never rebased; the config pipeline fails on fetch, visibly. Step 6 moves the pins to main. |
A stale |
fail-closed |
|
Tests
| Category | Tests (file) | Devstack |
|---|---|---|
Regression |
|
no |
Live decision |
|
yes |
Contract (surface) |
|
no |
Contract (request) |
|
no |
Refusal |
|
yes |
Evil input |
|
yes |
Gate |
|
no |
Ruleset |
|
no |
Migration and seed |
|
mixed |
Web, CLI, e2e |
|
mixed |
Every new test gets a red proof. Existing callers that build the request move to the new shape with no assertion weakened.
Gates and suites this change also moves (each handled in step 5, none weakened): the DTO ceilings in
xtask/src/cmd/lints.rs (untyped, counted on request extractors, falls by two; opaque counts every reached type
with a hand-written Deserialize and must not rise: SafetyFacts and AttestedFacts become derived, transparent
newtypes over one shared hand-deserialised map type, so the count is unchanged and screening’s OpenAPI schema keeps
its name; if the count still rises, stop and report, do not raise the ceiling);
crates/craig-api/authz-exempt-routes.txt; the worker lists in services/craig-cases/tests/api/health.rs and
keyed_harness.rs (its SurfaceClients must carry a verified safety surface); tx_live_http.rs;
cargo xtask coverage-matrix --check (the read needs its 401 leg); contested-surfaces.toml;
services/craig-web/tests/i18n_coverage.rs; services/craig-web/src/routes/subject_fallback_tests.rs; and the
e2e specs that render the form (intake.spec.ts, screenshots.spec.ts, accessibility-audit.spec.ts).
What the design asserts, and the test that pins each:
-
The act never evaluates with a declared fact unanswered:
an_unanswered_declared_fact_is_422_and_consults_nothing. -
The rules service never decides an incomplete input:
an_incomplete_input_is_refused_by_each_shipped_safety_schema. -
A server-derived key cannot be attested:
a_declared_registry_key_is_refused. -
A ruleset read nobody supplies cannot pass
rules check:rules_check_refuses_a_safety_read_nobody_supplies. -
The act always sends exactly the declared facts:
the_act_sends_the_assembled_facts_as_the_evaluate_input. -
An override never lands without a reason:
an_override_without_a_reason_is_422_and_records_nothing.
Delivery
-
Canonical page:
docs/modules/ROOT/pages/rulesets.adoc, ametadata.safetysection besidemetadata.ive. -
Also updated:
data-model-cases.adoc,cli.adoc(inline, file and stdin examples),shared-crates.adoc,services.adoc. -
OpenAPI:
cargo xtask api-docs; the ledger-lift golden is re-blessed (services/craig-cases/tests/api/ledger_lift_golden.rs), with a note naming #3104 and what moved. -
CHANGELOG entry: the fragment
changelog.d/3104.changed.adoc, pre-1.0 BREAKING: the request body, the required override reason, the dropped columns, the CLI flags, the new read. Ops: the migration deletes every stored safety assessment and its override, which cannot be recovered; a safety ruleset must declaremetadata.safetyor the act answers 503. -
Close:
Closes #3104; after merge, one line with the merge SHA and the follow-up issues.
Errata
-
Erratum (2026-11-16): Georgia adds no row for impending danger with capacities absent. With every fact under
requiredno valid input reaches such a row, soga_safety_impending_danger_with_capacities_absent_is_unsafeis not written. Georgia also drops its leftover edge fromchild-vulnerabilitytosafety-decision. -
Erratum (2026-11-16): the order of § Scope steps 1 to 4 changes, because the pre-push hook runs
rules checkand that refuses aTWIN_ALLOWEDrow no pair shows. Both config repositories push their signed branches first; CRAIG’s first pushed commit carries the gate (armed), the allow rows and a lock that pins both branch tips; each config repository then pointsCRAIG_VERSIONat it and fast-forwards its main. There are no commits B and C. -
Erratum (2026-11-16): both files give
child_agethe bounds 0 to 130 and use one sentence for whose facts the child facts are: the most vulnerable alleged victim in the home (when unsure, the youngest).
Review log
Two cold reviews of an earlier draft ran before plan mode (claude-fable-5-2, then gemini-4-carbon); both failed it on implementability. Folded here: the Testonia fixture, the parity deadlock (steps 2 to 4), the fully required schema, the override reason, the handler-level tests, the claims and seed, the unlisted gates, and the missing-output refusal.
The plan-mode reviews (claude-fable-5-2, then gemini-4-carbon) each flagged implementability. Folded: the fixture’s
missing safety_decision output and its citation rows; root_properties cannot be shared; the response contract;
the test for value-free refusals.
Approved by the maintainer in plan mode on 2026-11-16. The commit review of this page then corrected three facts about the DTO ceilings and the response body; no decision changed.