ADR-052: Jurisdiction Extension Modules — a Sandboxed WebAssembly Bundle in the Pack Extends a Core Service
Status: Accepted (2026-11-18) with plan jurisdiction-extension-modules
Issue: #3437
Ruling: the maintainer, 2026-11-17 and 2026-11-18, quoted in the Decision below.
Amends: ADR-021 (its deferred WebAssembly option is for worker-portal panels; this ADR is a separate mechanism for program services) and ADR-002 (a fourth determination status and an optional signed member, when the plan’s U2 and U3 land).
Relates to: ADR-006, ADR-051.
Context
A jurisdiction changes policy through its rules pack: values, lists and decisions in a signed configuration repository (ADR-006, ADR-051). Some approved waivers and demonstrations need more than that: records of their own, checks of their own, outcomes of their own. With no way to add them, a state must fork canopy, and a fork is what the project exists to prevent. 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."
A survey of current waivers is recorded on #3437. It read the FNS certification-waiver spreadsheet (145 active approvals, 20 types), the SNAP State Options Report, KFF’s section 1115 tracker and medicaid.gov’s waiver list (190 section 1115 entries). Its checks against canopy’s code were searches, and it read no demonstration’s terms. It found:
-
Most waiver types are already in core, are 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.
-
Outside parties acting for applicants are the most common shape core lacks. That is generic authorized-representative work (#3450), not extension work.
Decision
-
One bundle per jurisdiction, loaded by the service it extends. A bundle is a sandboxed WebAssembly component, its migrations and a manifest. It runs in the host service’s process and, where the extension point has one, in the host’s transaction. Rejected: a separate service, and Rust compiled into canopy.
-
Every jurisdiction runs its own deployment. "There isn’t a saas canopy deployment. Every jurisdiction runs their own." So one jurisdiction’s module cannot harm another’s data, by construction.
-
Three levels of reach. A module may mix them and owns tables at every level.
-
Level 1, supported: named extension points. canopy carries the upgrade risk: "if we have a supported extension then by definition we do make the promise".
-
Level 2, unsupported: the module answers a named host decision itself. Every override is recorded. canopy may rename or reshape what is intercepted.
-
Level 3, declared and not built: a module migration that widens or drops a core constraint. It is a last resort and is tracked in #3449, which must name a real waiver before anyone builds it.
-
-
No promise to downstream beyond level 1. "We can’t really make promises to downstream." The rule of thumb: "We will support, officially, most shapes and will inherently adapt to new federal rules and options."
-
Outcomes have classes core understands. The class is the determination status. Core adds one:
withheld, a person who is eligible and not admitted. A module’s own outcome is a signed label and reason beside the status. A limited benefit isapprovedwith a label. -
An admission gate is a level 1 extension point. It may withhold an otherwise approved person. It cannot approve a denied one.
-
The runtime is wasmtime and the contract is WIT, so a module can be written in Rust, Python or JavaScript.
-
A determination records the module that took part, inside the signed bytes.
-
Letters stay pack data.
The design
The bundle
A jurisdiction layer holds at most one directory under extensions/: extensions/<name>/extension.toml, module.wasm and migrations/*.sql. A second directory refuses the boot. The layer’s signed commit covers the bundle, so every determination’s configuration stamp already identifies it.
The manifest states the module’s name and version, the contract version it was built for, the services it extends, the extension points it implements, the decisions it intercepts, and its limits. A service loads what the manifest declares for it. A manifest the service cannot honour refuses the boot: a module that is silently not loaded would let a capped program admit everyone.
The contract
One WIT world, in crates/canopy-extension-host/wit/canopy-extension.wit.
Exports, each optional:
-
admit(subject, class, as-of, currently-approved) → admit { label?, reason? } | withhold { label, reason } -
outcome(subject, status), called for every subject with the final status, so a module can release a place when a person is denied. -
decide(decision-name, input) → output
Imports: run a SQL statement with typed parameters, read a pack value, and log.
The contract has a version. A bundle built for another major version is refused at boot.
What a module may touch
-
Its own schema only. Module SQL may neither read nor write a core table. canopy-medicaid’s tables hold sealed snapshots and their wrapped keys, so reads matter as much as writes.
-
No control of the session. A module may not change role, begin, commit or roll back, set session parameters, or take or release advisory locks.
-
Its migrations run as the module. They use the module’s own role and their own migration table, so a migration cannot alter a core table. That would be level 3 by accident.
-
Each SQL call is contained. It runs in a savepoint with a statement timeout and a lock timeout. A failed call fails the extension point; the module cannot swallow it and carry on in an aborted transaction.
-
System interfaces. A Python or JavaScript module needs some WASI interfaces to start. The host grants no filesystem, no sockets and no environment. Clock and randomness come from the host, so a determination replays the same and the test clock applies.
-
Limits. Fuel and memory per call, from the manifest, under a ceiling the host sets. Fuel does not meter time spent in the database, which is why the SQL timeouts exist.
How confinement is enforced is U3's to prove. The candidate is a per-module database role that owns only the module’s schema, with module statements executed through a function that runs as that role. The services already create purpose-built roles in migrations (canopy_chain_owner_medicaid), and the deployment’s PostgreSQL is version 18. Whether that mechanism truly prevents a role reset was not tested for this ADR. U3 ships adversarial tests: a module that tries to read a core table, write one, reset its role, commit, and release a lock. If the role mechanism cannot pass them, the SQL import is replaced by a narrower typed data interface, and this ADR is amended.
Fixture modules
The plan ships fixture modules, written in Rust and built for a WebAssembly component target. The tests that use them run on the car from a prebuilt test archive, in an image without cargo, so a test cannot build its own module. The component is therefore committed beside its source under fixtures/config/<pack>/extensions/<name>/, and a lint in the CI lint job, which does have cargo, rebuilds it and refuses a difference. If the build proves not to be reproducible byte for byte, the lint compares the component’s exported interface and the source’s hash recorded in the manifest instead, and this ADR is amended.
No Python fixture ships in the first slice. A Python component embeds an interpreter, so it is large, and building it needs a Python toolchain in the CI image. The WIT contract is what keeps Python possible; a Python fixture is worth adding when a jurisdiction asks to write one.
The record
SignableDetermination gains an optional signed member, extension. It is omitted when no module took part, so existing signatures verify unchanged, the rule previous_determination_id already follows. It holds:
-
the module’s name, version and the SHA-256 of
module.wasm; -
the extension points that ran;
-
each intercepted decision, by name;
-
the module’s label and reason, when it gave them.
The input snapshot records the same. The order is fixed: the record goes into the snapshot, the snapshot is sealed and hashed, the envelope takes the hash and the record, then it is signed.
Replay. A dry-run or a recompute of an old determination refuses when the loaded module’s digest differs from the recorded one. Running old inputs through a newer module would produce an answer nobody signed.
The withheld status
DeterminationStatus::Withheld. For every consumer: no enrollment, no benefit, no coverage dates. Federal reports count it as not approved unless a report has a category of its own. A letter is required and comes from the pack; a withheld determination with no pack letter is refused, never mailed blank and never sent a denial letter.
A person who already holds a place keeps it. The gate is told whether the subject's most recent determination in the same program is approved. Any earlier approval does not count: a person who was approved, then denied, has given up the place and queues again. The gate is not a way to remove an enrolled person at renewal.
Where the gate runs
canopy-medicaid computes and signs each household member before it opens a transaction (evaluate_member), then persists the household in one transaction (persist_determinations). A gate before signing would have no transaction, and a place taken could not roll back with the determination. So the plan’s U4 splits the function: evaluation keeps the rules-engine calls and returns an unsigned verdict, and a new finalize_member builds and signs inside the persist transaction, after the gate. Signing is local (DeterminationSigner::sign), so no network call is held inside the transaction.
Consequences of that placement:
-
The module’s writes, the signed determination and its rows commit or roll back together.
-
A duplicate dispatch fails on the existing unique constraints and rolls back, so it takes no second place.
-
Subjects reach the gate in a fixed order, by person id, so two households cannot lock module rows in opposite orders.
-
One member’s module failure fails the household’s determination, as any persist failure does today.
-
A module that locks one shared row holds it across the rest of the household. U4 measures that.
Decision interception
canopy-medicaid evaluates decisions by name. A manifest may list names the module answers in place of the rules engine. A name the service does not evaluate refuses the boot. Decisions run in the compute phase, which holds no transaction, so SQL from decide is read-only.
This level is unsupported, and its hazard is silent: if core changes the inputs or outputs of an intercepted decision without renaming it, the service boots and the module answers a question that has changed. The record makes the interception visible afterwards; it does not prevent the drift.
Two walks against the code
An enrollment cap
A demonstration covers at most N adults in a class.
| Need | Where | In the first slice? |
|---|---|---|
Count places taken |
A table in the module’s schema |
Yes |
Withhold the person over the cap |
|
Yes (U4) |
Record the outcome |
|
Yes (U2, U3) |
Tell the person |
A pack letter routed on the withheld status |
Yes, as pack data |
Release a place when a person is denied later |
|
Yes (U4) |
Release a place when enrollment ends (closure, death) |
canopy-enrollment’s events; the module would need an event subscription |
No |
Admit the next person on the list |
A background leg |
No |
Let a worker see and manage the list |
A worker-portal slot |
No |
So the first slice proves the mechanics and cannot run a real cap unattended. A real cap needs event subscriptions and background legs, each its own plan.
On-demand interviews
On-demand interviews are in core today. The walk asks what moving such a feature into a module would take. It touches three services, two contract crates and the notices pack:
| Need | Where it is today | Extension point needed |
|---|---|---|
A deadline on the interview record |
|
A module table keyed by the interview; or level 3 |
The mode is accepted |
|
The mode list as pack data (#2211), plus a validation point |
A default deadline at scheduling |
|
A level 1 point in canopy-applications |
A daily scan for missed deadlines |
|
A background leg |
Events carry the deadline |
|
An open member on the event |
Letters |
Two routes in |
Pack data |
Worker screens |
|
A worker-portal slot |
None of this is reachable in the first slice, which extends canopy-medicaid only. The walk confirms the order of the later plans: background legs and event members first, then extension points in canopy-applications, then worker-portal slots. It also shows why on-demand interviews stay in core: 20 states hold that waiver, and a shape that common is core’s job.
The cost of wasmtime
Measured on 2026-11-18 on a scratch edit that was not kept: wasmtime 50.0.2 added to one crate, with the runtime, cranelift, component-model and async features and no defaults.
| Before | After | |
|---|---|---|
Packages in |
1,054 |
1,097 (1,100 with |
B6, duplicate dependency installs ( |
157 |
165 |
The eight new duplicates: object (0.37.3 beside 0.40.0), wasmparser (0.228.0 through typst beside 0.261.0), semver, wasm-encoder, and four wasmtime-internal crates that are built for both host and build scripts. A debug build of wasmtime, wasmtime-wasi and their dependencies took about 30 seconds on a 32-core box with shared dependencies already built. Not measured: a clean workspace build, the release build, the image size, and the car’s time.
B6 only falls without the maintainer’s word (#2923). U3 does not start until the maintainer rules on raising it to 165.
Alternatives considered
-
wasmi. Already in the tree through typst, but at 0.51.5 where the current release is 2.0.1, and it does not run components, so no Python or JavaScript modules and no WIT contract. Rejected: the contract of a supported extension point is the one part that is costly to change later.
-
A separate service per jurisdiction. Rejected by ruling: it cannot share the host’s transaction, so a place taken and a determination signed could disagree.
-
Rust compiled into canopy. Rejected by ruling: it is a fork with extra steps.
-
A JSON column on core records for module data. Rejected: unsealed personal data, a conflict with the hash chains, no change in behaviour, and residue when the module is removed.
-
Free-form module outcomes. Rejected: core could not act on an outcome it does not understand. A fixed core list alone was also rejected: an unforeseen outcome would force a fork.
-
The gate before signing. Rejected on review: no transaction exists there.
Consequences
-
A state can add a cap, a waiting list or a decision of its own without a fork, and every determination it affects says so.
-
Core gains a fourth status that every consumer must handle. Most match the status exhaustively, so the compiler lists them; comparisons and SQL literals must be found by search.
-
canopy-medicaid holds its persist transaction across the module call and the signing.
-
The dependency tree grows by about 45 packages.
-
Module records are invisible to core’s federal reports. A report that must count them needs a core change.
-
A new kind of actor, a new program and a new status class still need core.
-
The first slice ships fixture modules only. No state can run a real waiver on it until the later plans land.
Verification
The plan’s units carry the tests. The ones this ADR depends on: U2's test per consumer that a withheld determination enrolls nobody; U3's adversarial confinement tests; U4's concurrent last-place test, its rollback test and its replay test.
Amendment 1 (2026-11-18) — confinement as built and tested (#3453)
The candidate mechanism was tested on PostgreSQL 18 before it was built, and the section "What a module may touch" is superseded where it differs.
What the role mechanism stops, by itself. Reading, writing or altering a host table; granting itself rights; creating objects outside its schema; changing role or session authorization; committing or rolling back; turning a read-only transaction read-write. A host timeout cancels a module statement.
What it does not stop, and what the host does about each. The module shares the host's session:
-
It can change
search_path, set the custom settings the host's append-only guards read, and take session advisory locks. After every call the host runsRESET ALLand releases session advisory locks. For that reset to be safe, a transaction that already carries a session setting of its own is refused before the module runs. -
It can create a temporary object that shadows a host table, or drop the driver's prepared statements. The host compares both before and after; a difference rolls the call back and fails it.
-
It owns its executor functions, so it can alter them to run with the caller's rights. The host checks them before every statement and after the call.
-
A trigger on a module table runs as whoever touches the table. The host never touches a module table directly.
The maintainer ruled, with these findings in hand, to keep SQL under the module's role with the host restoring the session, over a narrower typed store or a statement parser.
A refused statement ends the call. The contract's query and execute return plain values: a statement the database refuses traps the module. A module cannot catch the failure and continue, because the transaction is unusable until the call's savepoint is rolled back.
Timeouts are set before every statement. A module can change them, and PostgreSQL arms a statement's timer from the value in force when it starts. A module can still turn the lock timeout off for the remainder of one statement; the statement timeout ends that statement.
Prepared statements are checked on failure too. They live outside any transaction, so a rollback does not restore them: after a failed call as after a successful one, a difference drops them all and has the driver forget them.
A module exports both interfaces. "Exports, each optional" is superseded: a component that lacks either export is refused at boot, and a module answers an interface it does not implement with an error. The manifest decides what a service calls.
A migration is a module call. Each migration runs under the same wrapper as a call at an extension point, one statement batch with the manifest's longest timeout (30 seconds), and is refused on the same residue. The installer's own statements are not prepared, so a migration has none to replace.
Residual risks, accepted. A module can hold a transaction-level advisory lock or a row lock until the host's transaction ends; it can spend the statement count and the timeouts its manifest was granted; a setting it changes is in force for its own later statements in the same call. A jurisdiction runs its own deployment, so the harm is to itself.
Decisions have no database. The plan gave decide read-only SQL in a transaction of its own. As built it has none: a decision is evaluated outside any transaction, and a module that needs its records at decision time is a reason to design that properly, not to open a second connection per decision.
Fixture modules. The build is not byte-identical across checkouts: the same source built from another directory gives different bytes, and the CI lint job refused the committed components. So the fallback applies. cargo xtask extension-fixtures --write records the SHA-256 of a module's source beside its component; the lint fails when that digest is not the current source's, and builds the module to prove the source still compiles to a valid component. A component edited by hand without its source is not caught.
Amendment 2 (2026-11-18) — the first slice as built (#3454, #3455)
-
The gate is asked about approved subjects only, then
outcomeis called for every subject. A withheld subject keeps the class they are eligible for. -
Holding a place follows the person.
currently-approvedis the subject's most recent determination under the program, in whichever household it was made. -
The module runs on a task of its own and its statements are served on the caller's connection.
-
Interception covers the determination's decisions except the cascade order, whose evaluation supplies the corpus hash every snapshot records. An intercepted decision leaves no derivation firings; the signed record names it.
-
Measured cost of the gate, on a development box against a local database, release build, one single-person determination: 14.7 ms without a module, 22.3 ms with the fixture cap.
-
Not checked offline.
canopy config checkreads a bundle's files; whether its manifest names points and decisions a service offers is found at that service's boot.
Amendment 3 (2026-11-18) — replay is not built, because nothing replays (#3456)
The Decision says a dry-run or a recompute of an old determination refuses when the loaded module's digest differs from the recorded one. That check does not exist, and no path it would guard exists either:
-
The dry-run (
orchestrator::dry_runin canopy-eligibility) is SNAP-only. It dispatches to canopy-snap alone, and canopy-snap hosts no module. -
canopy-medicaid, the one service that hosts a module, has no dry-run and no recompute route. Its admin replay re-delivers inbox events; it does not re-run a determination. A duplicate dispatch is refused on the unique constraints and rolls back.
-
canopy-eligibility's quarantine replay returns the stored result of an earlier reverify; it evaluates nothing.
What is built is the record: the module's SHA-256 rides the signed determination and canopy-eligibility stores it.
The refusal is therefore owed by the change that first re-runs recorded inputs through a service that hosts a module: a Medicaid dry-run, or a module host in canopy-snap. That change compares the recorded digest with the loaded module's and refuses on a difference, and when one side has a module and the other has none, with a test for each. Until then the sentence in the Decision states a rule, not a behaviour.