Plan: Jurisdiction extension modules, first slice (#3437)
Status: Done (2026-11-18) — five units as planned, with the errata below; the replay refusal was not built because no replay path exists (ADR-052 Amendment 3)
Epic: &128
Issues: #3437 (parent) · #3451 U1 (w5) · #3452 U2 (w5) · #3453 U3 (w8) · #3454 U4 (w8) · #3455 U5 (w3)
Closes: #3437 (by U5)
Branches: docs/adr-052-extension-modules, feat/determination-status-withheld, feat/extension-host, feat/extension-admission-gate, feat/extension-decision-interception
Erratum (2026-11-18): a second review (gemini-4-carbon), run after approval because its first attempt timed out, raised eight findings. The accepted ones are the errata below; ADR-052 carries the detail.
Erratum (2026-11-18): releasing a place. As approved, a place could never be released: a denied subject never reaches the gate, the module hears of no enrollment ending, and a withheld person has no renewal. U4 gains a second export, outcome, called for every subject with the final status, so a module can release a place on a denial. A place freed because enrollment ended still waits for the event-subscription plan; until then a real cap cannot run unattended (maintainer ruling).
Erratum (2026-11-18): a person who already holds a place keeps it. The gate’s input states whether the subject’s most recent determination in the same program is approved; the fixture module admits such a subject without taking a place. An earlier approval followed by a denial does not count. The gate is not a way to remove an enrolled person at renewal (maintainer ruling).
Erratum (2026-11-18): the contract. admit carries an optional label and reason, so "approved plus a module label" can be expressed; withhold requires both. U3 states how the label and reason reach the determination event and the letter.
Erratum (2026-11-18): confinement. Module SQL may neither read nor write a core table, may not change role, control the transaction or take advisory locks; module migrations run under the module’s own role with their own migration table; each SQL call runs in a savepoint with statement and lock timeouts, and a failed call fails the extension point. U3’s tests cover reads as well as writes.
Erratum (2026-11-18): replay. A duplicate dispatch fails the persist transaction on the existing unique constraints (map_determination_persist_error), so the module’s writes roll back with it; U4 adds a test that a replayed dispatch takes no second place.
Erratum (2026-11-18): households. Subjects reach the gate in a fixed order (by person id), and one subject’s module failure fails the whole household’s determination, as any persist failure does today.
Erratum (2026-11-18): risks. A core change that reshapes an intercepted decision’s inputs or outputs without renaming it is a silent risk, not fail-closed; only a rename is refused at boot. The manifest pins the decision’s name only; this is the stated cost of the unsupported level.
Erratum (2026-11-18): one bundle. A layer holds exactly one directory under extensions/; a second refuses the boot. The U4 and U5 fixtures are one bundle.
Erratum (2026-11-18): system interfaces. ADR-052 states which WASI interfaces a module may import: no filesystem, sockets or environment; clock and randomness supplied by the host.
Erratum (2026-11-18): order inside finalize_member. The extension record goes into the input snapshot, the snapshot is sealed and hashed, the envelope takes the hash and the record, then it is signed.
Erratum (2026-11-18): what U1 settled. Of the three items the Design left open: replay is settled in ADR-052 (refuse on a digest mismatch); the fixture build is settled there (a committed component, rebuilt and compared by a lint in the CI lint job; no Python fixture in this slice); schema confinement is not settled by U1. ADR-052 states the rules and a candidate mechanism, and U3 must prove it with adversarial tests or replace the SQL import. The Design’s "the car’s image has no cargo" means the image the car’s tests run in; the car job itself compiles.
Erratum (2026-11-18): U3 as built. The contract's SQL imports return plain values and a refused statement traps the module; decide has no database; the host restores the session after every call (ADR-052 Amendment 1). The fixture bundles live in fixtures/extensions/, outside any pack, until U4 gives a pack one: a pack that shipped a bundle no service loads would be untested configuration. U3 also adds program_determinations.extension in canopy-eligibility, which the plan did not list: without it the orchestrator refuses an envelope carrying the record as unrepresentable.
Erratum (2026-11-18): U4 as built. The gate runs for an approved subject only; outcome is then called for every subject. A withheld subject keeps the class it is eligible for on the envelope and the row, with no benefit type and no coverage date. The fixture bundle stays in fixtures/extensions/ and the tests install it under a namespace of their own, because a fixture pack that shipped a cap would cap every other test that uses the pack. The module runs on a task of its own and its statements are served on the caller’s connection. A manifest that lists decisions for canopy-medicaid refuses the boot until U5. Measured on the development box against a local PostgreSQL 18, one single-person determination: 14.7 ms without a module and 22.3 ms with the cap (release build), about 7.6 ms for two module calls, each a fresh instance and some eleven host statements.
Erratum (2026-11-18): U5 as built. A manifest may list any decision a determination evaluates except medicaid-cmd-cascade-priority, whose evaluation supplies the corpus hash every snapshot records; a name outside that set refuses the boot. A module’s answer carries no derivation firings, so the subject’s graph has none for that decision and the signed record’s decisions names it instead. A manifest may declare decisions without the admission gate. The Express Lane decisions are not interceptable: they are not part of a determination.
Erratum (2026-11-18): replay. The Risks row "a replay runs an old determination against a newer module" says the refusal was built in U3. It was not: U3 records the digest, and no service that hosts a module re-runs a recorded determination, so there was nothing to refuse. ADR-052 Amendment 3 says which later change owes the check (#3456).
This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Context
A jurisdiction changes policy through its rules pack (ADR-006, ADR-051). A pack holds values, lists and decisions. Some approved waivers and demonstrations need machinery a pack cannot express: their own records, their own checks, their own outcomes. Without a way to add that, a state must fork canopy. The maintainer’s test: "If I don’t allow a jurisdiction to extend canopy in a non-standard way based on [an] approved waiver, they can’t use it and they will have to fork, which is the issue."
The waiver survey recorded on #3437 (FNS certification waivers, the State Options Report, KFF’s section 1115 tracker, medicaid.gov’s waiver list) found that most waiver types are already core, pack data, or fit the two lower levels below. Enrollment caps and waiting lists (8 section 1115 rows) have no home in core. No surveyed waiver needs a core database constraint changed.
What exists today:
-
The verdict is
DeterminationStatusincrates/canopy-reference/src/enums.rs:Approved,Denied,Sanctioned. It is matched in about 27 crates and pinned byCHECKlists in 9 migration files. -
The program service decides the verdict and signs it (
SignableDetermination::buildincrates/canopy-signing/src/envelope.rs; canopy-medicaid builds it inservices/canopy-medicaid/src/determine.rs). canopy-eligibility verifies and records. So anything that changes an outcome must run in the program service, before signing. -
Configuration is signed git layers loaded once at boot, and every determination carries the layer commits (
ConfigStamp, ADR-051). -
ADR-021 defers WebAssembly plugins for worker-portal panels to a later version. No WebAssembly host exists in canopy.
wasmiis in the dependency tree only through typst;wasmtimeis absent.
Rulings this plan implements (maintainer, 2026-11-17 and 2026-11-18)
-
One sandboxed WebAssembly bundle per jurisdiction (code, migrations, manifest), loaded by the core service it extends, running in that service’s transaction. Every jurisdiction runs its own deployment.
-
Three levels of reach. Level 1: named, supported extension points plus the module’s own tables. Level 2: unsupported interception that answers a host decision itself, every override recorded. Level 3: a module migration that changes a core constraint, declared in the ADR as a last resort and not built (tracked in #3449).
-
Outcomes: core defines the classes it understands; a module’s own outcome names its class. The class is the existing determination status. Core adds one class,
withheld(eligible but not admitted). A limited benefit isapprovedplus a module label. -
An admission gate is a named extension point at level 1 and answers with
withheld. -
The runtime is wasmtime with a WIT contract, so a module can be written in Rust, Python or JavaScript. U1 measures the dependency cost and brings the B6 number to the maintainer for an explicit ruling, because B6 must not rise without one (#2923).
-
Outside parties are generic authorized-representative work (#3450), outside this plan.
-
No guardrails on the unsupported level beyond the record. Letters stay pack data.
Scope
In scope:
-
ADR-052, and an amendment to ADR-021 pointing at it.
-
The
withheldstatus in core, handled by every consumer of the status. -
A host crate that loads a bundle from the jurisdiction’s configuration layer, runs it under limits, runs its migrations in its own schema, and records on each determination which module took part.
-
The admission gate in canopy-medicaid, proven by a fixture module that caps enrollment.
-
Decision interception in canopy-medicaid, proven by a fixture module that answers one decision.
Out of scope:
-
Level 3 (#3449). Authorized-representative accounts (#3450).
-
Background legs, event subscriptions and worker-portal slots for modules: each needs its own plan after this one. Until then a withheld person is re-determined by a worker action or a renewal, not automatically.
-
Extension points in the other program services, and interview modes and postponement reasons (#2211), which follow once the host exists.
-
A real state’s module. This plan ships fixture modules only.
Design
The bundle
A bundle lives in the jurisdiction’s configuration layer under extensions/<name>/: extension.toml (the manifest), module.wasm (a WebAssembly component) and migrations/*.sql. It is covered by the layer’s signed commit and so by ConfigStamp. The manifest states the module’s name and version, the services it extends, the extension points it implements, the decisions it intercepts, and its limits. A service loads only what the manifest declares for it and refuses to boot on a manifest it cannot honour.
The contract (WIT)
crates/canopy-extension-host/wit/canopy-extension.wit defines one world. Exports are the extension points, each optional. Imports are the host functions: run SQL, read a pack value, and log. SQL runs in the host’s transaction at an extension point that has one (the admission gate) and read-only otherwise (decision interception). The contract carries a version; a bundle built for another major version is refused at boot.
The record
SignableDetermination gains an optional signed member, extension, omitted when no module took part (so existing signatures verify unchanged, the same rule as previous_determination_id). It holds the module name, version and SHA-256 of module.wasm; the extension points that ran; each interception with the decision name; and the module’s outcome label and reason when it set one. The input snapshot records the same.
The withheld outcome
DeterminationStatus::Withheld: the person is eligible and not admitted. Consumers match the status exhaustively in most places, so the compiler lists them. The rule for each: no enrollment, no benefit, no coverage dates; counted as not approved in federal reports unless a report has its own category; a letter is required and comes from the pack. New migrations widen the CHECK lists those 9 files set (8 services; canopy-snap has two files); no shipped migration is edited.
The admission gate (level 1)
The host calls the module’s admit export with the subject, the assigned class and the evaluation date. The answer is admit or withhold { label, reason }. A withhold turns an Approved into Withheld. The gate cannot turn a denial into an approval. The module keeps its own counts in its own tables.
Where it runs. Today evaluate_member in services/canopy-medicaid/src/determine.rs computes and signs each subject with no transaction ("Pure compute + sign — NO persistence"), and persist_determinations opens the transaction only afterwards. A gate before signing would therefore have no transaction, and a slot taken could not commit or roll back with the determination. U4 restructures this, for every determination and not only gated ones, so there is one path:
-
evaluate_memberkeeps the rules-engine calls (HTTP, no transaction held) and returns an unsigned verdict: the status, class, reasons and the inputs the snapshot needs. -
A new
finalize_memberbuilds the envelope and the input snapshot and signs. It makes no network call:DeterminationSigner::signis local (crates/canopy-signing/src/traits.rs). -
persist_determinationsopens its transaction, and for each subject calls the gate (when the manifest declares one), thenfinalize_member, then writes the rows as today.
So the module’s SQL, the signed determination and its rows commit or roll back together. The cost is that the transaction is now held across the module call and the signing, both in-process; U4 measures it.
Decision interception (level 2)
canopy-medicaid evaluates its decisions by name through its rules client. A manifest may list decision names the module answers instead of the rules engine. The host calls the module’s decide export with the decision name and the input the rules engine would have received, and uses the answer. Each interception is recorded. This level is unsupported: core may rename or reshape a decision.
Decisions are evaluated in the compute phase, which holds no transaction. For a decide call the host’s SQL function is read-only, in a short transaction of its own opened for that call. A module that must write does so at the admission gate.
Open for U1 to settle in the ADR
-
How module SQL is confined to the module’s schema (the proposed default: a database role that owns only that schema, set for the call). Depends on how canopy-db sets up roles, which is not yet read.
-
How the fixture component is built and kept honest: the car’s image has no cargo. Proposed default: a committed component plus a check that rebuilds and compares it in the lint job.
-
Replay: a dry-run or recompute of an old determination needs the module version it ran with. Proposed default: replay refuses when the loaded module’s digest differs from the recorded one.
Units (weights by complexity) — U1 → U2 → U3 → U4 → U5
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one independently shippable MR = one child issue.
U1 (w5) — ADR-052, the measurement and two walks
Files: docs/modules/ROOT/pages/adrs/adr-052-jurisdiction-extension-modules.adoc, docs/modules/ROOT/pages/adrs/adr-021-composability-runtime-and-plugin-model.adoc, docs/modules/ROOT/pages/architecture.adoc, docs/modules/ROOT/nav.adoc, docs/modules/ROOT/pages/plans/jurisdiction-extension-modules.adoc, CHANGELOG.adoc
The ADR records the rulings, the three levels, the bundle, the contract, the record, the outcome classes and the three open items above, and links #3449 from its level 3 section. It walks two cases against the code, naming every file touched: on-demand interviews (inventory in hand) and an enrollment cap. It reports, from a throwaway branch that is not merged, what adding wasmtime does to the package count, B6 and build time. The maintainer rules on B6 before U3 starts. No product code.
U2 (w5) — the withheld outcome in core
Files: crates/canopy-reference/src/enums.rs, crates/canopy-signing/src/envelope.rs, services/canopy-eligibility/src/orchestrator.rs, services/canopy-enrollment/src/successors.rs, services/canopy-renewals/src/determination_subscriber.rs, services/canopy-reporting/src/worker/medicaid.rs, services/canopy-reporting/src/worker/tanf.rs, services/canopy-notices/src/generator.rs, one new migration in each of the 8 services those 9 files belong to (canopy-medicaid, canopy-eligibility, canopy-renewals, canopy-reporting, canopy-snap, canopy-caps, canopy-wic, canopy-tanf), the OpenAPI snapshots, the per-service api/ and data-models/ pages, docs/modules/ROOT/pages/services.adoc
Adds the variant and handles it in every consumer. The file list above names the main ones; the full set is whatever the compiler and a search for DeterminationStatus, "approved" and 'approved' find, which also includes services/canopy-renewals/src/renewal_decisions.rs, services/canopy-renewals/src/materiality.rs, services/canopy-enrollment/src/continuation/arm.rs, services/canopy-enrollment/src/auto_enroll.rs, services/canopy-applications/src/determination_subscriber.rs, services/canopy-portal/src/home.rs and the canopy-web determination views. Nothing emits it yet. Tests: the status vocabulary and agreement tests; one test per consumer that a withheld determination enrolls nobody, dates no coverage and is not counted as approved; a notices test that a withheld determination with no pack letter is refused, not mailed blank; migration tests that each widened constraint accepts withheld and still refuses an unknown token.
U3 (w8) — the host crate
Files: crates/canopy-extension-host/ (new), Cargo.toml, Cargo.lock, deny.toml, xtask/quality-budgets.lock, xtask/src/lanes.rs, crates/canopy-signing/src/envelope.rs, crates/canopy-pack-check/src/, fixtures/config/default/extensions/**, docs/modules/ROOT/pages/shared-crates.adoc, docs/modules/ROOT/pages/security.adoc, docs/modules/ROOT/pages/jurisdiction-onboarding.adoc
The crate: manifest parsing, component loading from a ConfigSnapshot, fuel and memory limits, the WIT contract, the host functions, the module’s schema and migrations, and the extension record on the envelope. canopy config check reports a bundle whose manifest a service would refuse. Tests: manifest refusals; a module that exhausts fuel or memory fails the call and the determination, never the process; a contract-version mismatch refuses the boot; the record is covered by the signature and absent when no module ran; database-backed tests that module migrations land in the module’s schema and that module SQL cannot write a core table.
U4 (w8) — the admission gate in canopy-medicaid
Files: services/canopy-medicaid/src/determine.rs, services/canopy-medicaid/src/main.rs, services/canopy-medicaid/src/extension.rs (new), services/canopy-medicaid/tests/extension_admission_test.rs (new), fixtures/config/test-max/extensions/enrollment-cap/**, compliance/input-requirements/medicaid.toml, docs/modules/ROOT/pages/api/canopy-medicaid.adoc, docs/modules/ROOT/pages/data-models/canopy-medicaid.adoc, docs/modules/ROOT/pages/rulesets.adoc
Splits evaluate_member into evaluation and finalize_member as the Design states, wires the gate inside persist_determinations, and ships a fixture module with a cap of N. The split lands first in the MR as its own commit with no behaviour change: the pinned payload snapshot (evaluate_member_pin.rs), the input-snapshot tests and the signature tests must pass unchanged. Tests: a failure after the gate (a persist error) rolls the module’s slot back with the determination; with a cap of 2, the third eligible subject is withheld with the module’s label and reason; a denied subject never reaches the gate; a module error fails the determination; two concurrent determinations cannot both take the last slot (database-backed); a pack with no bundle behaves exactly as today. U4 also measures the gate’s added time per determination and records it on the issue.
U5 (w3) — decision interception in canopy-medicaid
Files: services/canopy-medicaid/src/rules_client.rs, services/canopy-medicaid/src/extension.rs, services/canopy-medicaid/tests/extension_interception_test.rs (new), fixtures/config/test-max/extensions/**, docs/modules/ROOT/pages/rulesets.adoc, docs/modules/ROOT/pages/jurisdiction-onboarding.adoc
Tests: a listed decision is answered by the module and recorded by name; an unlisted decision still goes to the rules engine; a manifest naming a decision the service does not evaluate refuses the boot; a module answer missing an output the service reads fails the determination as a rules-engine answer would.
Tests by category
-
Unit lane (fixture only): manifest parsing and refusals, the status vocabulary, envelope signing with and without the record, each consumer’s handling of
withheld, the gate and interception logic over fixture modules. -
Integration lane (database-backed, on the car): module migrations and schema confinement, the concurrent last-slot test, the widened constraints, end-to-end determinations through canopy-medicaid with each fixture bundle.
-
CI lint: quality budgets (B6 at the ruled value),
cargo deny,cargo machete, input coverage, the fixture-component check. -
Not tested here: a real state’s module, performance under load, a Python guest (U1 states whether a Python fixture is worth adding).
Risks
| Risk | Failure mode | Mitigation |
|---|---|---|
A module traps, runs out of fuel or returns malformed output during a determination |
fail-closed |
The determination fails with an error; nothing is signed. Tested in U3 and U4. |
A consumer treats |
fail-open |
Exhaustive matches make each consumer a compile error until handled; U2 tests each one enrolls nobody. |
A consumer with a non-exhaustive comparison ( |
silent |
U2 searches every comparison and SQL literal, not only |
The admission gate is skipped because the bundle failed to load, so a capped program admits everyone |
fail-open |
A manifest the service cannot honour refuses the boot; no "continue without the module" path exists. |
Two determinations take the last slot |
fail-open |
The gate runs inside the transaction |
A slot is taken but the determination fails to persist, so the cap leaks a place |
silent |
Same transaction: the slot rolls back. Tested in U4. |
The U4 split changes a signed payload or an input snapshot for determinations with no module |
silent |
The split is its own commit with the pinned payload, snapshot and signature tests unchanged. |
Federal reports omit or miscount withheld cases |
silent |
U2 decides each report’s treatment explicitly and tests it; reports with no category count them as not approved and say so in the page. |
An intercepted decision is renamed in core and the module’s answer is no longer asked for |
fail-closed |
A manifest naming an unknown decision refuses the boot. |
Module SQL writes a core table |
fail-open |
Schema confinement, tested in U3; the mechanism is settled in U1. |
wasmtime raises B6 and the dependency surface |
fail-closed |
U1 measures; U3 does not start without the maintainer’s ruling; |
A replay runs an old determination against a newer module |
silent |
The record carries the module digest; replay refuses on a mismatch (settled in U1, built in U3). |
The committed fixture component drifts from its source |
silent |
The rebuild-and-compare check in the lint job. |
Verification
-
cargo xtask test --uniton each push (the pre-push hook). -
The merge train’s pipeline is green for each unit: it runs the whole battery (CI is the gate).
-
After U4: a canopy-medicaid determination against
test-maxwith the cap fixture withholds the subject over the cap, and the signed envelope names the module and its digest. -
After U5: the neutrality allowlist count has not risen.
Documentation Updates
-
ADR-052 and the ADR-021 amendment;
architecture.adocADR index (U1) -
The durable plan page
plans/jurisdiction-extension-modules.adocwith a nav entry (U1) -
api/canopy-.adoc,data-models/canopy-.adocandservices.adocfor the new status and the medicaid changes (U2, U4) -
shared-crates.adoc,security.adoc,jurisdiction-onboarding.adoc,rulesets.adoc(U3 to U5) -
CHANGELOG.adoc— an entry under== Unreleasedin every unit
Delivery steps
-
At approval: file U1 to U5 as child issues of #3437; record the wasmtime ruling on #3437; post the merge notes held during plan mode.
-
U1: the ADR, the durable plan page, the CHANGELOG entry. Bring the B6 measurement to the maintainer.
-
U2 to U5 in order, one MR each through the train, each with its doc pages and CHANGELOG entry.
-
U5’s MR closes #3437. Set this plan’s Status to Done and tell the jurisdiction agents on
canopy/rules.
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
anthropic |
claude-fable-5-2 |
FLAGS (P2): the admission gate was placed before signing, where canopy-medicaid holds no transaction. Resolved: U4 splits |
2 |
gemini-4-carbon |
First attempt timed out. Re-run after approval, reading the plan but not the repository: FLAGS (8). Accepted findings are the errata of 2026-11-18; its replay finding assumed persist-time adoption, where canopy-medicaid refuses a duplicate and rolls back. |