ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / docs/plans/2026-06-29-ws3-clearance.md

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / docs/plans/2026-06-29-ws3-clearance.md
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberdocs/plans/2026-06-29-ws3-clearance.md
Original SHA-256ad12fe37eb42484dc24209a35e0e31485f8c5d584bc8175154ca0b07f00b9d94
Git blob SHA6cf6bedc6a691178b85a231aff6069e0845de474
Reading-copy SHA-256ad12fe37eb42484dc24209a35e0e31485f8c5d584bc8175154ca0b07f00b9d94

Original source ↗

Every recorded occurrence

These 3 records contain identical original source bytes. Their paths and revisions remain part of the archive.

Original recordBranch or archiveRevision / identifierOriginal location
Janady13/missionmatch / docs/plans/2026-06-29-ws3-clearance.mdfeature/opportunity-to-outcome720d47fae476b0d38477ae4401697d372b1ea2bcOpen original
Janady13/missionmatch / docs/plans/2026-06-29-ws3-clearance.mdmaster1e9249840a4302ec82e123b9c9cb6f75badea3e4Open original
Janady13/missionmatch / docs/plans/2026-06-29-ws3-clearance.mdfeature/aioe-upgrade2178e7298d0e5d9af83afa12402fd587f0ba6ed8Open original

Recovered source transcript

# WS3 Clearance and Compartment Layer Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task by task. Steps use checkbox (`- [ ]`) syntax. **Goal:** Make clearance first class reference data (levels, polys, compartments, reciprocity) that is FK enforced and governable, and add additive compartment aware scoring to the engine, without changing the frozen weights, bands, threshold, or the existing golden clearance values. **Architecture:** New global reference tables (`clearance_levels`, `polygraph_types`, `clearance_compartments`, `clearance_reciprocity`) FK enforced on the candidate and requirement clearance columns. Two new array columns (`candidates.clearance_compartments`, `requirements.required_compartments`) flow into the engine through the existing `SELECT *` reads (sqlc auto picks them up). The engine gains `Compartments`/`RequiredCompartments` fields and one additive check in `scoreClearance` after the poly check: a requirement that lists compartments is only met by a held clearance that carries them all. Existing inputs carry no compartments, so the check never fires and the three frozen golden scores are byte identical. ModelVersion bumps to v1.3.0. A consistency test pins the engine rank enum to the seeded `clearance_levels.rank` so the documented hierarchy equals the scored one. **Tech stack:** Go 1.26, pgx/v5, sqlc v1.31.1 (now installed), goose, shopspring/decimal. CGO_ENABLED=0, GOFIPS140=v1.0.0, no Python. **The hard rule:** `go test ./internal/modules/matching/engine/...` stays green; the three frozen golden scores (100.00, 87.50, 26.00) and the WS2 alias and relationship golden cases are unchanged. The only allowed frozen change is the ModelVersion assertion to v1.3.0. --- ## Task 1: Migration 0023, reference tables, compartment columns, v1.3.0 **Files:** Create `db/migrations/0023_clearance_reference.sql` ```sql -- +goose Up -- WS3 clearance reference layer. Four GLOBAL reference tables (no organization_id, outside RLS, app -- SELECT only, migrator writes), FK enforced on the candidate and requirement clearance columns. Adds -- compartment array columns to candidates and requirements for additive compartment aware scoring. The -- six component weights, the bands, and the 0.62 threshold are unchanged; this registers ModelVersion -- v1.3.0 for the new compartment match dimension. CREATE TABLE clearance_levels ( code text PRIMARY KEY, rank int NOT NULL UNIQUE, requires_polygraph boolean NOT NULL DEFAULT false, label text NOT NULL ); INSERT INTO clearance_levels (code, rank, label) VALUES ('unknown',0,'Unknown'),('none',1,'None or Public Trust'),('confidential',2,'Confidential'), ('secret',3,'Secret'),('top_secret',4,'Top Secret'),('ts_sci',5,'Top Secret SCI'); CREATE TABLE polygraph_types ( code text PRIMARY KEY, rank int NOT NULL UNIQUE, label text NOT NULL ); INSERT INTO polygraph_types (code, rank, label) VALUES ('none',0,'None'),('ci',1,'Counterintelligence'),('full_scope',2,'Full Scope'); CREATE TABLE clearance_compartments ( code text PRIMARY KEY, kind text NOT NULL CHECK (kind IN ('sci','sap')), label text NOT NULL ); -- Publicly documented SCI control systems plus generic markers. A SAP is named per program; SAP here is -- the generic marker, specific programs are added by the customer. INSERT INTO clearance_compartments (code, kind, label) VALUES ('SCI','sci','Sensitive Compartmented Information (generic)'), ('SI','sci','Special Intelligence (SIGINT)'), ('TK','sci','Talent Keyhole (overhead collection)'), ('HCS','sci','HUMINT Control System'), ('SAP','sap','Special Access Program (generic)'); -- Stub for future non rank reciprocity exceptions (agency specific). The engine uses the rank ladder -- today; this table documents and will later carry exceptions. Seeded empty. CREATE TABLE clearance_reciprocity ( held_code text NOT NULL REFERENCES clearance_levels(code), required_code text NOT NULL REFERENCES clearance_levels(code), satisfies boolean NOT NULL, source text NOT NULL DEFAULT '', PRIMARY KEY (held_code, required_code) ); ALTER TABLE candidates ADD COLUMN clearance_compartments text[] NOT NULL DEFAULT '{}'; ALTER TABLE requirements ADD COLUMN required_compartments text[] NOT NULL DEFAULT '{}'; -- FK enforce the clearance codes against the reference tables (the existing CHECK constraints already -- bound the values to exactly these codes, so the FKs are satisfiable on existing rows). ALTER TABLE candidates ADD CONSTRAINT candidates_clearance_level_fk FOREIGN KEY (clearance_level) REFERENCES clearance_levels(code); ALTER TABLE candidates ADD CONSTRAINT candidates_clearance_poly_fk FOREIGN KEY (clearance_poly) REFERENCES polygraph_types(code); ALTER TABLE requirements ADD CONSTRAINT requirements_required_level_fk FOREIGN KEY (required_level) REFERENCES clearance_levels(code); ALTER TABLE requirements ADD CONSTRAINT requirements_required_poly_fk FOREIGN KEY (required_poly) REFERENCES polygraph_types(code); GRANT SELECT ON clearance_levels, polygraph_types, clearance_compartments, clearance_reciprocity TO missionmatch_app; INSERT INTO aedt_model_versions (version, weights, band_cuts, notes) VALUES ( 'v1.3.0', '{"clearance":0.25,"skills":0.25,"certifications":0.15,"customer_experience":0.15,"experience":0.10,"location_availability":0.10}', '{"green":90,"yellow":75}', 'Adds an additive compartment dimension to the clearance component, and makes clearance levels, polygraph types, and compartments FK enforced reference data. A requirement that lists compartments is met only by a held clearance carrying them all. The level and poly logic, the binary 0 or 100 clearance score, the six weights, the bands, and the 0.62 threshold are unchanged from v1.2.0. Clearance remains a self reported indicator, never an input proxy for a protected attribute.' ) ON CONFLICT (version) DO NOTHING; -- +goose Down DELETE FROM aedt_model_versions WHERE version = 'v1.3.0'; ALTER TABLE requirements DROP CONSTRAINT requirements_required_poly_fk; ALTER TABLE requirements DROP CONSTRAINT requirements_required_level_fk; ALTER TABLE candidates DROP CONSTRAINT candidates_clearance_poly_fk; ALTER TABLE candidates DROP CONSTRAINT candidates_clearance_level_fk; ALTER TABLE requirements DROP COLUMN required_compartments; ALTER TABLE candidates DROP COLUMN clearance_compartments; DROP TABLE clearance_reciprocity; DROP TABLE clearance_compartments; DROP TABLE polygraph_types; DROP TABLE clearance_levels; ``` - [ ] Write the file. Verify against 0022 (global grant pattern) and 0019 (the aedt_model_versions insert columns). Do NOT apply live (Task 6 validates on staging). Commit. --- ## Task 2: sqlc regen for the compartment columns - [ ] Run `sqlc generate` (sqlc is installed; `$(go env GOPATH)/bin` is on PATH). Because `GetCandidate` and `GetRequirement` are `SELECT *`, the new `clearance_compartments` and `required_compartments` columns appear on the `dbgen.Candidate` and `dbgen.Requirement` structs as `[]string` automatically. Confirm `go build ./...` is clean and that `git diff` on dbgen shows only the two new compartment fields (the ontology and alias models were already regenerated on the WS2 branch). - [ ] Commit the dbgen diff. --- ## Task 3: Engine compartment check, convert population, ModelVersion v1.3.0 **Files:** Modify `internal/modules/matching/engine/types.go`, `engine.go`, `internal/modules/matching/convert.go`, `internal/modules/matching/engine/frozen_test.go` - [ ] **Step 1:** In `types.go`, add `Compartments []string` to `Clearance` and `RequiredCompartments []string` to `Requirement` (both default nil/empty, so every existing construction is unchanged). Bump the `ModelVersion` constant in `engine.go` to `"v1.3.0"`. Update the single ModelVersion assertion in `frozen_test.go`. - [ ] **Step 2:** In `engine.go` `scoreClearance`, add a new `case` AFTER the poly check (`case held.Poly < r.RequiredPoly:`) and before `default:`: ```go case !hasAll(held.Compartments, r.RequiredCompartments): missing := missingCompartments(held.Compartments, r.RequiredCompartments) g := fmt.Sprintf("Requires compartments %v; candidate lacks %v.", r.RequiredCompartments, missing) return zero, g + " Scores 0.", []string{g} ``` Add the two helpers (case insensitive, empty required means satisfied): ```go // hasAll reports whether held carries every required compartment. An empty requirement is always met, // so existing inputs (no required compartments) are unaffected and the frozen scores do not change. func hasAll(held, required []string) bool { if len(required) == 0 { return true } set := map[string]bool{} for _, h := range held { set[strings.ToUpper(strings.TrimSpace(h))] = true } for _, r := range required { if !set[strings.ToUpper(strings.TrimSpace(r))] { return false } } return true } func missingCompartments(held, required []string) []string { set := map[string]bool{} for _, h := range held { set[strings.ToUpper(strings.TrimSpace(h))] = true } var out []string for _, r := range required { if !set[strings.ToUpper(strings.TrimSpace(r))] { out = append(out, r) } } return out } ``` (Add `strings` to the engine.go imports if not present.) - [ ] **Step 3:** In `convert.go`, set `Compartments: c.ClearanceCompartments` on the built `engine.Clearance` (line 89 area) and `RequiredCompartments: r.RequiredCompartments` on the built `engine.Requirement` (line 132 area), reading the new dbgen fields. - [ ] **Step 4:** Run `go test ./internal/modules/matching/...` and `go build ./...`. The three frozen golden scores and the WS2 golden cases stay green. Commit. --- ## Task 4: Golden case for compartment scoring **Files:** Modify `internal/modules/matching/golden_test.go` (the WS2 matching-package golden file) - [ ] Add two cases scored through `engine.ScoreCandidate`: (a) a requirement with `RequiredLevel ts_sci` and `RequiredCompartments ["SI"]`, a candidate with active TS/SCI carrying `Compartments ["SI","TK"]`, Clearance scores 100; (b) the same requirement, a candidate with active TS/SCI but `Compartments ["TK"]` (no SI), Clearance scores 0 with a gap naming the missing SI. Lock the totals. Confirm the three frozen and the WS2 cases are unchanged. Commit. --- ## Task 5: Consistency test, the documented hierarchy equals the scored one **Files:** Create `internal/integration/clearance_reference_integration_test.go` - [ ] An integration test (DB tagged) that reads `clearance_levels(code, rank)` and `polygraph_types(code, rank)` and asserts that for every code, the seeded rank equals the engine enum value (`engine.ParseClearanceLevel(code)` cast to int, and the polygraph equivalent). This pins the reference data to the scored hierarchy so they can never silently diverge. Commit. --- ## Task 6: Validate on M4 staging, then load production - [ ] **Step 1:** On `brain_staging` apply 0023 (goose from M2 as migrator), confirm up and down both work, the FK constraints are added, the four reference tables are seeded, and the compartment columns exist. - [ ] **Step 2:** Run the consistency integration test against staging, confirm the reference ranks match the engine enum. - [ ] **Step 3:** Prove compartment scoring end to end on staging: seed one candidate with TS/SCI + compartment SI and a requirement for TS/SCI + SI, screen them, confirm Clearance 100; remove SI from the candidate, confirm Clearance 0 with the gap. - [ ] **Step 4:** Production (gated, backup first): apply 0023 to production via goose, confirm the FKs hold against the live candidate and requirement rows (the existing CHECK guarantees this), verify the reference seeds. No binary redeploy is required for the reference layer; the compartment scoring activates when the already deployed engine reads compartment data, so deploy the WS3 binary (same gated swap as WS2) to ship the scoreClearance compartment check. - [ ] **Step 5:** Final whole branch code review, then the finishing handoff. --- ## Self-Review 1. Spec coverage: WS3 in `docs/AI_GROUNDING_PROGRAM.md` calls for clearance and compartment modeling with reference tables and reciprocity, the engine staying the floor. Covered: reference tables and FK and seed (Task 1), the columns flowing through sqlc (Task 2), the additive engine check and convert and version bump (Task 3), the golden proof (Task 4), the consistency pin (Task 5), staging then production (Task 6). Reciprocity is a documented stub table for future exceptions, the engine keeps the rank ladder. 2. Frozen contract: the only frozen change is the ModelVersion assertion to v1.3.0; the compartment check returns satisfied for an empty requirement, so all existing inputs score identically. 3. Type consistency: `Clearance.Compartments`, `Requirement.RequiredCompartments`, `hasAll`, and the dbgen `[]string` fields are used identically across Tasks 2, 3, 4.

Search equations, builds, manuscript text, and recovered sources.