Runbook — World model deployment (Registers & Datasets)
How a deployment (sandbox or country) gets its world model, and how the model evolves safely in production.
Scope: this runbook covers the world-model catalog, compiled migrations, datasets, and the demo model. It does NOT cover SmartRules procedure authoring (see the editor runbook) or Keycloak role administration beyond the
domain_stewardnotes below.
1. Where the model lives
- The world model is a directory of YAML files (
model.yaml,entities/,relationships/,datasets/) plus the platform’s read-only seed vocabulary (src/opengov/worldmodel/seed/). - The backend loads it from
OPENGOV_WORLDMODEL_DIR. Default (unset): the packaged example (src/opengov/worldmodel/examples/d26-company-register/— the Kenya company-register model used by the sandbox demo). A production deployment MUST setOPENGOV_WORLDMODEL_DIRto its own model directory, or it will serve the demo dataset. - The Studio edits a draft and publishes through the governance queue
(propose →
domain_stewardapproves → files are written toOPENGOV_WORLDMODEL_DIR). Never hand-edit the live model on a running instance.
2. How the model reaches the database
The model validates (grammar rules 1–10, fail-closed):
python -m opengov.worldmodel.compile <model_dir> --check <migration>The compiler emits a deterministic Alembic migration. The regenerate-and-diff drift guard (
--check) must pass in CI — a hand-edited migration fails the gate.alembic upgrade headsapplies it: typedwm_*tables,wm_history+ triggers. Verify:\dt wm_*shows every entity/relationship table.heads, plural — do not “correct” this tohead. On an instance that has approved a publish, the migration chain has two branches: the ones shipped in the image, and the publishes written to this instance’s own volume. Singularheadrefuses to choose between them, and the deployment fails to start. This took the sandbox down twice in two days before the plural form landed. Background: issue #1378.Additive changes (new entity, new nullable field) compile to ALTERs on the same tables — never table-per-version. Breaking changes require an explicit major version in
model.yamland a migration note reviewed by the steward.
3. The sandbox demo model
The sandbox runs the packaged example (unset OPENGOV_WORLDMODEL_DIR): the
Kenya world (company, person, address, government) with two registers —
the Company register (registration) and name reservations. The public
dataset company_directory is served anonymously at
GET /api/public/v1/datasets/company_directory. Redeploys reset demo data
unless a seeding job re-runs (see the demo seeding script under scripts/).
4. Production checklist (per country)
-
OPENGOV_WORLDMODEL_DIRset to the country’s model directory (mounted read-write for the API/worker containers; owned by the steward workflow). - The country’s model reviewed and approved through the governance queue — not copied by hand.
-
domain_stewardrole assigned to the country’s authorized person(s) in Keycloak; registrars holdregistrarfor corrections. -
alembic upgrade headsafter each model publish (the publish preview shows the compiled migration before approval). - Datasets: each
datasets/*.yamlvalidates (definition-time privacy gate); after the first publish, spot-check one public dataset for private-field absence. - Nightly reconciliation job visible in the worker; first week’s drift reports reviewed (they are alert-only by design).
5. Troubleshooting
| Symptom | Likely cause | Action |
|---|---|---|
GET /api/public/v1/datasets/<key> 404 | dataset not defined in the active model dir, or OPENGOV_WORLDMODEL_DIR unset/mispointed | check the env var; load_and_validate the dir locally |
| publish-preview 422 | model violates grammar rules 1–10 | the response body lists every violation in plain language |
| compiled migration won’t apply | hand-edited migration (drift) | regenerate via the compiler; never hand-edit |
| correction 403 | caller lacks registrar/admin | assign the role in Keycloak |
| history missing for a record | writes bypassed materialize_filing/correct_record (raw SQL) | never write wm_* outside the runtime; restore from backup if needed |