Jurisdiction-neutrality gate: state policy in shared Rust, SQL CHECKs, templates and the neutral packs fails the pre-push battery (#2208, epic &128)
Status: Done (2026-09-22) — !1484
Epic: &128
Issues: #2208
Branches: feat/2208-neutrality-gate (carries this page)
This is a Design + Scope plan: GitLab owns tracking, #2208 carries the brief, the plan freezes when U-A starts. One MR — page + nav, U-A, U-B, U-C, the Done flip — one battery.
Erratum (2026-09-22): N5 also skips a JSON string value whose key begins with _ (_comment, _source — the packs' JSON annotation convention, the analogue of the TOML notes exemption); N3’s unsupported-CHECK failure applies to list and pattern forms on a declared column (IN, NOT IN, = ANY, ~, LIKE, SIMILAR TO), not to a single-token = / <> / IS NULL reference, which the real tree carries (snap_certification_adjustments, application_interviews).
Context
The audit behind epic &128 found 42 sites of state policy compiled into shared code (closed Georgia vocabularies in canopy-contracts- and canopy-reference, PAMMS-cited enums, nine SQL CHECK … IN (…) lists that pin pack vocabularies, Georgia copy in canopy-web templates and canopy-portal, Georgia values under rulesets/federal/) and named the mechanism: every existing lint targets *numeric literals. policy audit-literals (xtask/src/cmd/policy.rs:1604-1644) matches Decimal::from( and dec!(; policy audit-jurisdiction-literals (:1854-1953) matches the helpline digits, a quoted "GA" and Georgia prose in canopy-portal only; policy audit (crates/canopy-policy/src/citation.rs:498-510) checks citation authority in rulesets/default/ only. Nothing reads enums, string arrays, migrations, templates, rulesets/federal/ or the fixture packs, so each family passed the ADR-011 sweeps with its numbers extracted and its vocabulary intact.
The battery already has the shape this gate needs: in-process static gates registered in stage_static_gates (xtask/src/cmd/validate.rs:277-309) with a matching stage(id, name, policy, capture) row in STAGES (xtask/src/validate_report.rs:204-515; the [N/57] label is STAGES.len(), so a new row renumbers everything); findings printed as ✗ path:line … and an anyhow::bail! count; the fail-closed walker (walk::files_with_extension, walk::read_to_string); textscan::mask_literals_and_comments + test_block_ranges to skip #[cfg(test)] bodies; syn 2 (full, visit), regex 1, walkdir 2, toml 0.8, proptest already in xtask/Cargo.toml. The allowlist conventions are split across two files: compliance/jurisdiction-literal-allowlist.toml (file + line_contains + reason; no stale detection) and compliance/action-coverage-allowlist.toml (issue = "#N" or kind = "by-design" + adr; stale entries fail, policy_actions.rs:212-246, action.rs:356-380). This gate takes the second convention and adds an exact per-entry count so an allowlisted file can neither grow nor drain silently. Migrations are forward-only (ADR-016): a wrong CHECK is retired by a later DROP CONSTRAINT, never by editing the file, so the SQL detector must read the constraint lifecycle, not single files.
Rulings in force: the gate is scoped to the SHARED tree — a per-jurisdiction extension crate (#2216) may name its state, so the config carries an exclude_globs list; no site is fixed by the #2208 MR (each belongs to a family issue of &128 — #2209, #655, #2210–#2215); every baseline entry names its owner; git push is the only gate.
Scope
In scope
-
One new xtask module
xtask/src/cmd/neutrality_lint.rs(six pure detectors, the config loader, the allowlist matcher, the report), syntax-aware comment masking inxtask/src/textscan.rs, theneutralityvalidate stage and thecargo xtask neutrality-lint [--explain] [--print-baseline]subcommand. -
One config file
compliance/neutrality-gate.toml(token lists, pack-vocabulary column declarations, allowlist) with the baseline entries for every open site the gate finds onmain, each carrying its family issue (or a by-design ADR) and a reason. -
Antora: the xtask catalog section, the validate stage table, the ADR-011 ATO evidence gate table, one paragraph in
rulesets.adoc; CHANGELOG.
Out of scope
-
Fixing any flagged site (the families); folding
audit-jurisdiction-literals(#1226) into this module (a follow-up only if the maintainer wants one gate; its helpline detector spans test code, which this gate does not). -
A CI job (the pre-push battery is the gate; CI runners are not).
-
Enforcing fixture-pack divergence from georgia (each family’s acceptance criterion); the gate does flag Georgia identity and non-fixture authorities INSIDE
rulesets/test-minandrulesets/test-max, the corpus half it can see. -
Numeric policy values (ADR-011’s sweeps own them); the semantics of extension-crate exclusion beyond
exclude_globs(#2216); growth INSIDE an already-flagged line (a second Georgia token on the same line) — the gate’s promise is no new line, declaration member, constraint token or pack file, stated in the catalog page.
Design
Decisions
| # | Decision |
|---|---|
D1 |
One in-process Blocking stage, |
D2 |
Scope of the walk (fail-closed,
|
D3 |
The config file |
D4 |
Six pure detectors,
|
D5 |
Allowlist matching, the count ratchet and staleness.
|
D6 |
Output. |
D7 |
Baseline.
|
D8 |
Docs. |
Config schema
[scope]
exclude_globs = [] # per-jurisdiction extension crates (#2216), e.g. "crates/canopy-ext-*/**"
[tokens] # see "Patterns" — P1 prose regexes, P2 identifier stems, P4 manual citations
prose = [...]
stems = [...]
compound_stems = [...]
manual_citation = [...]
[[pack_vocabulary_columns]] # a live CHECK list on this column is always a finding
table = "snap_certifications"
column = "certification_type"
pack_key = "snap.certification.categories" # documentary: the loader never resolves it
issue = "#2209"
[[allow]]
detector = "rust-vocab" # rust-identity | rust-vocab | sql-check | copy-identity | pack-identity | test-canon
file = "crates/canopy-contracts-renewals/src/certifications.rs"
line_contains = "digest=3f9a1c0b7e2d" # optional, non-empty; N2/N3 entries pin the digest
count = 1 # exact number of findings this entry absorbs
issue = "#2209" # tracked form; OR kind = "by-design" + adr = "ADR-NNN" (page must exist)
reason = "closed CertificationType enum (Chart 3105.1); #2209 makes the vocabulary pack data"
Validation (a config error, not a pass): every regex compiles; detector deserialises into Detector; count ≥ 1; line_contains, when present, is non-empty; reason non-empty; tracked entries carry issue = "#N" and no adr; by-design entries carry adr whose page exists (policy_actions::adr_page_exists, made pub(crate)) and no issue; a (detector, file) pair carries EITHER exactly one entry without line_contains OR one-or-more entries with distinct line_contains, never both; file is repo-relative with forward slashes; [[pack_vocabulary_columns]] rows carry table, column, issue (pack_key optional, documentary).
Patterns
# P1 — prose regexes (case-sensitive, the `regex` crate), matched over the non-comment text
prose = ["PAMMS", "Chart [0-9]", "\\bMT-[0-9]", "\\bDFCS\\b", "\\bDCH\\b", "\\bDECAL\\b", "\\bDPH\\b",
"Women's Health Medicaid", "Planning for Healthy Babies", "NOW waiver", "COMP waiver", "Senior SNAP",
"\\bForm [0-9]{2,4}\\b"]
# P2 — identifier rule: every [A-Za-z0-9_]+ run is split on `_` and on a lower-case-or-digit → upper-case
# boundary (P4hbFp → p4hb, fp; GrgPayment → grg, payment; tfsp_signature → tfsp, signature; "georgia-snap-…"
# → georgia, snap, …); a run hits when any lower-cased segment equals a stem, or the lower-cased whole run
# contains a compound stem (PeachCare → peachcare). `msp` is deliberately absent (Medicare Savings Program).
stems = ["georgia", "dfcs", "dch", "decal", "pathways", "p4hb", "whm", "edwp", "icwp", "grg", "crisp", "tfsp", "cso"]
compound_stems = ["peachcare", "pamms", "nowwaiver", "compwaiver", "seniorsnap", "georgiadol"]
# P3 — SQL (case-insensitive, applied to whitespace-collapsed, comment-masked text); IDENT = "?[A-Za-z_][A-Za-z0-9_]*"?
# column list: IDENT (?:::\w+)? \s+ (?:NOT\s+)? IN \s* \( TOK (?:\s*,\s*TOK)* \)
# any-array: IDENT \s* = \s* ANY \s* \( \s* ARRAY \s* \[ TOK (?:\s*,\s*TOK)* \] \s* \)
# TOK = '(?:[^']|'')*' (?:::\w+)? — quoted tokens only; numeric lists ignored
# table: CREATE TABLE (?:IF NOT EXISTS )? (?:IDENT\.)? IDENT | ALTER TABLE (?:ONLY )? (?:IDENT\.)? IDENT
# retire: DROP CONSTRAINT (?:IF EXISTS )? IDENT · DROP TABLE (?:IF EXISTS )? IDENT · DROP COLUMN IDENT
# P4 — manual-citation regexes for N2's doc attributes
manual_citation = ["PAMMS", "Chart [0-9]", "\\bMT-[0-9]", "\\bDFCS\\b", "\\bDCH\\b", "\\bDECAL\\b", "\\bDPH\\b", "state plan", "Georgia"]
Invariants
-
The gate is pure over the tree + the config: no network, no database, no git; a walk or read error, an unparsable Rust file, an unsupported CHECK over a declared column or a table rename with live constraints fails the run (never shrinks it).
-
Comments never produce a finding in Rust code, SQL, TOML, Typst or templates — with one deliberate exception, N2’s reading of the doc attributes ON a vocabulary declaration, which is the citation that marks the vocabulary as policy.
-
Every allowlist entry names an owner and a reason, absorbs at least one finding and exactly
countfindings; every pack-vocabulary declaration matches a live constraint. -
rulesets/georgiais never scanned; a path under[scope].exclude_globsis never scanned. -
Adding a stage row and its
run_gatecall is the whole battery change;--skip-dockerand stage capture kinds are untouched.
Units (weights by complexity) — U-A → U-B → U-C, one MR
U-A (w5) — feat(xtask): add the jurisdiction-neutrality gate (#2208)
Files: xtask/src/cmd/neutrality_lint.rs (new), xtask/src/cmd/mod.rs + xtask/src/main.rs (subcommand), xtask/src/textscan.rs (CommentSyntax + mask_comments), xtask/src/cmd/policy.rs (is_test_path, is_in_ranges, test_block_ranges → pub(crate)), xtask/src/cmd/policy_actions.rs (adr_page_exists → pub(crate)), xtask/src/cmd/validate.rs + xtask/src/validate_report.rs (stage), compliance/neutrality-gate.toml (scope + tokens + columns; allow = [] in this commit).
Tests (inline #[cfg(test)], in-memory sources, tempfile trees for walks):
-
Identity rule —
tfsp_signature,GrgPayment,pathways_enabled,whm_eligible,P4hbFp,"PeachCare for Kids","georgia-snap-self-employment-deduction",GEORGIAhit;msp_eligible,crispness(prose),Peach,snapshotdo not. -
N1 — identity in a string literal and in an identifier are findings; the same token in
//and///and inside a[cfg(test)] modis not; a file declared by[cfg(test)] mod test_support;inmain.rsis not scanned by N1 (and is scanned by N6);mask_commentskeeps literal interiors and blanks nested block comments. -
N2 — an enum whose doc cites
PAMMS 3105 Chart 3105.1is a finding withmembers=anddigest=; adding a variant changes the digest; an enum withPeachCareas a variant is a finding; an enum documented with a CFR cite only is not; aconst X: [&str; 5]holding"tfsp_signature"is a finding; an unparsable file fails the run naming the path. -
N3 —
CHECK (form_kind IN ('528','297','508'))is a finding when V holds the three tokens, and not when V holds one; migration A adds an inline CHECK and migration B drops it by its PostgreSQL default name → no finding, A alone → a finding at A’s line; a namedCONSTRAINT … CHECKdropped by name → no finding;DROP TABLEretires; a multi-line CHECK, a lowercasecheck (, aNOT IN (…)list,CHECK ("certification_type" IN ('standard'::text,'senior'::text)),public.snap_certifications, an= ANY (ARRAY[…])form and an escaped''token parse; a numericIN (1,2)is ignored;program IN ('snap','tanf')is not a finding; the realapplication_interviews.interview_modeSQL is a finding under its declaration; a declared column inside a CHECK P3 cannot parse fails the run;ALTER TABLE … RENAME TOwith a live tracked constraint fails the run; the digest changes when a token is added. -
N4 —
{# PAMMS #}and<!-- Georgia -→are not findings,<option>Senior SNAP (36 months)</option>is. -
N5 —
notes = "… PAMMS …", a multi-linenotes = """ … Georgia … """,bbce_enabled = true # Georgia uses BBCEand a Typstlet x = 1 // Georgia//* PAMMS /are not findings;label = "Georgia # 1",label = "PeachCare", a"""…"""string containingGeorgiaas content, a.txtline naming Georgia and a Typst string"PeachCare"are; atest-maxcitation row withauthority = "pamms"and a federal row withstate_citationare; adefault/.jsonnamegeorgia-snap-eligibilityis. -
N6 —
assert!(text.contains("PAMMS")),assert_eq!(text.contains("PAMMS"), true)andassert_ne!(text.contains("PAMMS"), false)are findings;assert!( !text.contains("PAMMS")),assert_eq!(text.contains("PAMMS"), false)andassert_ne!(text.contains("PAMMS"), true)are not;.join("rulesets").join("georgia")in acrates/canopy-contracts-test is a finding, the same line incrates/canopy-policyor aservices/*test is not. -
Allowlist — each validation rule has a rejecting test (unknown detector, empty reason, empty
line_contains,count = 0, tracked without issue, by-design with a missing ADR page, both forms on one pair, stale pack-vocabulary declaration);countexact passes, over → regression, under → ratchet, zero → stale; aline_containsentry absorbs only its finding;exclude_globsprunes (,?,*); an unreadable subdirectory fails the run (walk::fault::lock_dir); the stage inventory tests (inventory_has_no_duplicate_ids,fresh_report_seeds_full_inventory_as_not_run) still pass with 58 stages. -
Property tests (
proptest, thetextscan.rsprecedent): everyCommentSyntaxmasker never panics and preserves the line count and every line’s char count for arbitrary input; theCHECK (…)extractor never panics and every span it returns is parenthesis-balanced; the glob matcher never panics and**matches any path prefix; the identifier splitter never panics and its segments re-join to the run.
U-B (w3) — chore(compliance): seed the neutrality-gate baseline (#2208)
Files: compliance/neutrality-gate.toml (the [[allow]] entries and [[pack_vocabulary_columns]] per D7; every entry with an owner and a reason).
Tests: cargo xtask neutrality-lint is clean on the branch; --explain shows every entry with exactly count hits; the five live-failure sites named in 2208 appear under their family issue; a repo-reading test in neutrality_lint.rs asserts the committed config parses and validates and that every tracked entry’s issue matches \d+ and every by-design entry’s ADR page exists — no test pins a site that a family will remove.
Verification
-
cargo xtask neutrality-linton the branch: clean;--explainlists every allowlist entry with its hit count equal tocount;--print-baselineon a tree with the[[allow]]entries removed prints exactly the committed entries'(detector, file, line_contains, count)set. -
Mutation checks in a scratch copy (never committed): add
let x = "PeachCare";to a servicesrcfile → onerust-identityfinding; delete the single site behind acount = 1entry → onestalefailure; delete one of the N sites behind acount = Nentry → oneratchetfailure; add a secondGeorgialine to that file → oneregressionfailure; add a variant to an allowlisted enum → itsdigest=entry goes stale and the new digest is un-allowlisted; add a forward migration thatDROP CONSTRAINTs an allowlisted CHECK → its entry goes stale (the drain path); addCHECK (kind IN ('528','297'))to a migration → onesql-checkfinding; addGeorgiainside{# #}→ clean. -
The push battery prints
[17/58] jurisdiction-neutrality gate (#2208)after[16/58] jurisdiction-literal audit (#1226);test-results/validate-report.jsoncarries the stage. -
git push— the pre-push battery is the gate (it runscargo xtask validate; no separate run).
Documentation Updates
-
tooling/xtask-catalog.adoc(row + section),testing.adoc(stage row + count),compliance/adr-011-ato-evidence.adoc(gate row),rulesets.adoc(one paragraph). -
CHANGELOG.adoc—== Unreleased=== Added. -
GitLab: every
fix:issue filed for an orphan cluster in D7 related to &128; #2208’s closing comment lists the baseline size per family.
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 (2026-09-21) |
Anthropic |
claude-fable-5-1 |
no-ship — six blockers fixed in-plan: a nav anchor that did not exist; N5’s TOML rule made a trailing |
2 (2026-09-21) |
OpenAI |
gpt-6-astra |
no-ship — 18 findings (5 P1, 11 P2, 2 P3), each verified against |