Plan: Safety Assessment Inputs — a ruleset-declared fact surface (#3104)

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-60 evaluates 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 answers SAFE. Only the worker override moves the stored decision.

  • Neither ruleset declares anything. Both files have no metadata and no inputNode schema, so the rules service accepts any document, an empty one included. Texas’s graph has an edge from the inputNode to safety-decision, a table that reads only its parents' outputs; the Texas config agent reports that sending present_danger_active: true decides UNSAFE from the input alone (not re-run for this plan).

  • An assessment is per investigation. safety_assessments has investigation_id and 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_override may replace UNSAFE with SAFE while worker_override_reason is 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 by services/craig-cases/src/api/reports/screening_surface.rs) and IV-E (metadata.ive.inputs, crates/craig-cases-contracts/src/ive_surface.rs, lint census xtask/src/cmd/rules_ive.rs:259-285).

Rulings this plan implements (maintainer, 2026-11-15)

  1. Stored safety assessments are deleted by the migration, overrides included; the release note says they are unrecoverable.

  2. The ruleset’s input schema lists every fact under required, so the rules service itself refuses an incomplete input.

  3. A worker override must carry a non-empty reason. A supervisor step for an override is a follow-up issue.

  4. 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.safety is a closed object with one member, attestable_facts: a non-empty array of closed {key, title, description} objects. key matches FactKey (crates/craig-cases-contracts/src/reports.rs) and is unique; title is non-blank, at most 100 characters; description non-blank, at most 2000.

  • The inputNode content.schema is 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", m not negative.

  • Every schema property is a declared fact or a server key (D3), every declared fact is a schema property, and required equals 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_met says "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}; SafetyFactKind is Boolean or Integer {minimum: i64, maximum: Option<i64>}, tagged like IveInputKind.

  • project_safety_surface(name, identity, ruleset_bytes, server_keys) → Result<_, SafetySurfaceError>, one thiserror variant per refusal. It shares the IV-E projection’s parts: lift the duplicate-rejecting JSON reader, input_schema, property_kind with its numeric bounds and check_text from ive_surface.rs into a crate-private declared_surface.rs; ive_surface.rs calls them unchanged. root_properties is not shared: the IV-E one refuses any non-empty required. The safety projection has its own root reader, which demands that required equals 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 }

    facts is SafetyFacts, a newtype over BTreeMap<FactKey, SafetyFactValue> with SafetyFactValue::{Bool(bool), Count(u32)}, deserialised by a visitor that refuses a repeated key and the 33rd entry, as AttestedFacts does (reuse FactKey and MAX_ATTESTED_FACTS; do not make AttestedFacts generic). A string, float, negative number, null or object value is a 422 at deserialisation. threats and protective_capacities are 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, loses threats and protective_capacities and gains facts: SafetyFacts, rule_set_id, rule_set_revision and evaluation_id.

  • Override reason. worker_override set with a blank or absent worker_override_reason is 422 validation-failed naming worker_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 on services/craig-cases/src/ive_surface_client.rs: one cached slot, a gate, a closed reason enum, a critical worker safety-surface-verifier. It reuses read_ruleset_by_name, ServiceBearer, find_node, schema_string and spawn_surface_verifier from screening_surface_client.rs, and joins SurfaceClients in services/craig-cases/src/lib.rs.

  • GET /v1/cases/safety-surface, a copy of the screening read: authenticated, deny_pure_service, 200, 401, 403, 503 safety-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 409 safety-policy-moved after one re-read and a cache eviction, as the IV-E client does); validate_facts; assemble_safety_document; validate_assembled; evaluate with expect: Some(identity); a craig-rules ruleset-moved answers the same 409; the claimed insert.

  • validate_facts, in this order: a server key or an undeclared key is 400 safety-fact-not-declared naming 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 422 safety-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_decision output is refused, not stored as UNKNOWN: 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_assessments row and every request claim of the scope cases.submit_safety_assessment (services/craig-cases/src/api/intents/intake.rs:89-90); drop threats and protective_capacities; add facts 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 hashes facts and surface in 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; hidden surface.rule_set_id and surface.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, @file or -) replaces --threats and --protective-capacities; the command reads the surface for its identity.

  • Fixture. fixtures/config/testonia/testonia-safety-assessment.json has one table that reads child_age and outputs only vulnerability_level. In step 1 it gains a second output column, safety_decision (UNSAFE on its vulnerable row, SAFE on its total row), the schema requiring child_age, and metadata.safety declaring child_age; fixtures/config/testonia/citations.toml gains 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-606 writes a complete answer set for the Georgia surface and a decision the ruleset gives for it (no SAFE_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.

  1. CRAIG, unarmed commit A. D3, D6 unarmed, the fixture, and TWIN_ALLOWED rows (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); each why names 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 that cargo xtask config fetch honours a lock entry whose branch is not main; if it does not, stop and report.

  2. 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.safety with D2’s wording; a version bump. Its pipeline is red on twin parity at this point, by design.

  3. CRAIG, unarmed commit B: the lock’s Georgia entry names that branch and commit.

  4. Texas, one merge request with CRAIG_VERSION at 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 to safety-decision dropped; metadata.safety; a version bump. Parity now compares new with new. Merge; post the commit. CRAIG commit C pins it. Georgia points CRAIG_VERSION at commit C, goes green, fast-forwards main (same commit) and posts it.

  5. CRAIG, same branch. The lock pins both mains (branch = "main"); arm D6; D4, D5, D7, tests, docs, fragment. Open and arm the merge request.

  6. Georgia and Texas repin CRAIG_VERSION to 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

required makes the rules service refuse it (todays_two_key_input_is_refused_by_each_shipped_safety_schema); the census refuses a read nothing supplies (rules_check_refuses_a_safety_read_nobody_supplies); the_act_sends_the_assembled_facts_as_the_evaluate_input matches the handler’s evaluate body.

A worker, or a direct caller of the rules service, leaves a fact unanswered and gets SAFE.

fail-open

CRAIG refuses before the consult (an_unanswered_declared_fact_is_422_and_consults_nothing); the schema refuses it at the rules service (an_incomplete_input_is_refused_by_each_shipped_safety_schema); Georgia’s row (ga_safety_impending_danger_with_capacities_absent_is_unsafe).

A caller sends an intermediate key and decides the outcome.

fail-open

a_hostile_safety_facts_body_is_refused_and_consults_nothing; an_intermediate_key_is_refused_by_each_shipped_safety_schema.

An override replaces UNSAFE with SAFE and records no reason.

fail-open

an_override_without_a_reason_is_422_and_records_nothing. A supervisor step is a follow-up.

A ruleset declares no facts, or emits no safety_decision.

fail-closed

an_empty_safety_declaration_is_refused; rules_check_refuses_a_safety_graph_without_a_decision_output; a_missing_safety_decision_output_records_nothing.

A ruleset lets a worker attest a server-derived key.

fail-closed

a_declared_registry_key_is_refused; validate_facts_refuses_registry_undeclared_and_off_type_keys.

The policy moves between render and submit.

fail-closed

a_stale_surface_identity_is_409_safety_policy_moved_and_records_nothing.

The surface is unverified at boot or after a bad promotion.

fail-closed

an_unverified_safety_surface_is_503_with_a_closed_reason.

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; a_blank_safety_fact_text_is_refused. No mechanical check of the wording until applies_when.

One attested child stands for several children.

silent

The description says whose fact it is; the_child_facts_do_not_move_either_shipped_safety_decision; the per-child follow-up.

The migration deletes stored assessments and overrides.

silent

Ruled; stated in the release note. the_safety_migration_leaves_no_row_and_no_claim.

The seed recreates a row with no facts.

fail-closed

The CHECK on facts; the_seeded_safety_assessment_answers_every_declared_fact.

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 TWIN_ALLOWED row or the unarmed gate reaches main.

fail-closed

rules check fails a stale row; rules_check_refuses_a_safety_ruleset_without_its_declaration.

Tests

Category Tests (file) Devstack

Regression

the_assembled_facts_decide_each_shipped_safety_ruleset (services/craig-cases/src/api/investigations/safety_assembly.rs, the rules engine as a dev-dependency): for each pinned file, pass a fact set through validate_facts and assemble_safety_document and evaluate; present danger is UNSAFE, a threat meeting every criterion with insufficient capacities is UNSAFE, no danger is SAFE. the_act_sends_the_assembled_facts_as_the_evaluate_input (safety.rs, a body-matching double). Red proof: today’s two-key document against a scratch copy of each pinned file with its schema removed returns SAFE for both unsafe cases; the output goes in the merge request. Also todays_two_key_input_is_refused_by_each_shipped_safety_schema, an_incomplete_input_is_refused_by_each_shipped_safety_schema, an_intermediate_key_is_refused_by_each_shipped_safety_schema, the_child_facts_do_not_move_either_shipped_safety_decision.

no

Live decision

services/craig-cases/tests/api/investigations.rs: a_present_danger_assessment_is_unsafe_through_the_live_ruleset and a_no_danger_assessment_is_safe_through_the_live_ruleset assert the exact stored decision; the existing assert_ne!(decision, "UNKNOWN") becomes an exact value.

yes

Contract (surface)

crates/craig-cases-contracts/src/safety_surface.rs: the_safety_surface_wire_shape_is_pinned; a_blank_safety_fact_text_is_refused; an_empty_safety_declaration_is_refused; a_declared_registry_key_is_refused; a_property_neither_declared_nor_registered_is_refused; a_non_boolean_non_integer_property_is_refused; a_schema_not_requiring_every_property_is_refused; each_shipped_safety_ruleset_projects. Property: project_safety_surface_does_not_panic_on_arbitrary_bytes.

no

Contract (request)

crates/craig-cases-contracts/src/investigations.rs: the_safety_request_wire_shape_is_pinned; safety_facts_round_trip_in_key_order (property); safety_facts_refuse_a_repeated_key_and_the_33rd_entry; the_retired_threats_fields_are_unknown_fields.

no

Refusal

services/craig-cases/tests/api/investigations.rs: an_unanswered_declared_fact_is_422_and_consults_nothing; an_override_without_a_reason_is_422_and_records_nothing; a_stale_surface_identity_is_409_safety_policy_moved_and_records_nothing; an_unverified_safety_surface_is_503_with_a_closed_reason; a_missing_safety_decision_output_records_nothing; the_safety_surface_read_serves_the_declared_facts; the_safety_surface_read_refuses_an_unauthenticated_caller_and_a_pure_service. Unit: validate_facts_refuses_registry_undeclared_and_off_type_keys, an_off_type_fact_refusal_names_the_key_and_kind_and_not_the_value.

yes

Evil input

a_hostile_safety_facts_body_is_refused_and_consults_nothing (services/craig-cases/tests/api/free_text_nul_evil_investigations.rs): an undeclared key, an intermediate key, a repeated key, 33 entries, a key with a NUL, an upper-case and a dotted key, values "true", 1.5, -1, 2^40, null, {}, an unknown top-level field, the old threats field; each row asserts the exact status the extractor and the act give, zero evaluate calls and no row.

yes

Gate

xtask/src/cmd/rules_safety.rs: rules_check_refuses_a_safety_read_nobody_supplies, rules_check_refuses_a_declared_safety_fact_no_table_reads, rules_check_refuses_a_safety_output_reusing_an_input_key, rules_check_refuses_a_safety_graph_without_a_decision_output, rules_check_refuses_a_safety_ruleset_without_its_declaration; shipped_rulesets_pass_check.

no

Ruleset

ga_safety_impending_danger_with_capacities_absent_is_unsafe (services/craig-rules/tests/georgia_ruleset_evaluation.rs); the Texas suite stops sending the two keys its schema refuses.

no

Migration and seed

the_safety_migration_leaves_no_row_and_no_claim (services/craig-cases/tests/constraints/); the_seeded_safety_assessment_answers_every_declared_fact (tools/craig-seed/tests/).

mixed

Web, CLI, e2e

services/craig-web/src/routes/intake/referrals/safety_tests.rs: the_safety_form_renders_each_shipped_surface, the_fold_sends_exactly_the_answered_facts, a_surface_read_failure_is_not_a_blank_form, an_override_without_a_reason_is_not_submitted; services/craig-cli/tests/cli/investigation.rs; tests/e2e/specs/journey-investigation-pending-review-close.spec.ts asserts UNSAFE for present danger.

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, a metadata.safety section beside metadata.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 declare metadata.safety or 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 required no valid input reaches such a row, so ga_safety_impending_danger_with_capacities_absent_is_unsafe is not written. Georgia also drops its leftover edge from child-vulnerability to safety-decision.

  • Erratum (2026-11-16): the order of § Scope steps 1 to 4 changes, because the pre-push hook runs rules check and that refuses a TWIN_ALLOWED row 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 points CRAIG_VERSION at it and fast-forwards its main. There are no commits B and C.

  • Erratum (2026-11-16): both files give child_age the 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.

Edit this page · latest