Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / BUILD_REPORT.md |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 43d56387270ef4da4cabd794d97ca6a49909bc7d |
| Branch | w3-ai-staffing-recommendations |
| Path or archive member | BUILD_REPORT.md |
| Original SHA-256 | 3b0fabb8122917eb9a4b9dc3cb3fe98062330ee9df39b4a1bec0046b07a93e7d |
| Git blob SHA | 58db601e59d677e9b1acb8213b483b7dc282258d |
| Reading-copy SHA-256 | 3b0fabb8122917eb9a4b9dc3cb3fe98062330ee9df39b4a1bec0046b07a93e7d |
Recovered source transcript
Download complete source text ↓147 lines · 12.0 KB
# BUILD_REPORT.md — W3 AI Staffing Recommendations
**Date:** 2026-06-29. **Branch:** `w3-ai-staffing-recommendations` (off `ai-intelligence-layer`).
**Build host:** M2. **Database validated on:** M4 staging (`tenant_w3_staging`, goose v18).
W3 is a backend build: an AEDT compliant recommendation layer on top of the deterministic decimal engine.
It turns the frozen engine scores into explained, human decided staffing ACTIONS in three views over one
core. This report records what was built, what was researched and relied on, the test results, what the
adversarial review found and what was fixed, and what remains.
## Non negotiable constraints, all held
1. **No Python.** `find . -name '*.py'` outside node_modules is empty. The optimizer is a pure Go minimum
cost flow solver, no cgo, no native math. Narration runs out of process on the existing MEGAMIND plane.
2. **FIPS intact.** The API binary builds `CGO_ENABLED=0 GOFIPS140=v1.0.0`; the stamp was verified after
every build. W3 added no cgo and no dependency (it uses only the standard library plus the packages
already present: shopspring/decimal, pgx, chi, uuid).
3. **EEO isolation absolute.** No W3 path names the eeo schema; sqlc models no eeo table. The existing
`TestNoAIFileReferencesEEO` tripwire was extended to walk every staffing source file, and a new
`TestNoProtectedAttributeInCoreTypes` reflects over the core input and output types (and the engine
Candidate and Requirement) and fails on any protected attribute field. `safety.ForbidEEO` guards every
string sent to the plane, with a defense in depth re check on the model's output.
4. **Tenant isolation.** Every W3 database operation runs inside `RunInTenantTx`, RLS scoped, on the
validated org. The MEGAMIND plane stays stateless. The proactive cron lists orgs through the migrator
role but does the per org work under the NOBYPASSRLS app role and RLS.
5. **The deterministic engine is the floor.** Eligibility, the six component scores, the band, and the
rank come only from `engine.ScoreCandidate`, reused through the matching package (new exported load
wrappers, `matching.LoadEngineRequirement` / `LoadEngineCandidate`) and persisted frozen to
`candidate_evaluations`, which each non source recommendation references by composite FK. W3 never
recomputes or overrides a score. The optimizer arbitrates allocation only among candidates the engine
already qualified; it never qualifies or disqualifies anyone.
6. **Explainable, human in the loop, never auto reject.** Every recommendation traces to frozen numbers
and explicit rules. A person approves, rejects, or dismisses each one. Rejecting a suggestion dismisses
only that row; it never blacklists a candidate. A source recommendation names no candidate.
7. **No model in the decision path.** The model produces only the rationale prose, behind the existing
faithfulness gate, with a deterministic fallback. Who, what action, what rank, what confidence, and the
portfolio allocation are computed only from frozen engine outputs, rules, adjacency, availability,
commitment, and the deterministic optimizer.
## Research (primary sources, cited in code)
A 3 agent research workflow verified the optimizer math and the faithfulness pattern before building:
- **Minimum cost flow by successive shortest paths with node potentials** (Tomizawa 1971; Edmonds and
Karp 1972; Ahuja, Magnanti, Orlin, *Network Flows*, ch 9 and 12). Confirmed: seed potentials with one
Bellman Ford pass (a max profit objective produces negative costs), then Dijkstra over non negative
reduced costs per augmentation; potentials keep all residual reduced costs non negative; augment one
unit while the shortest augmenting path has negative real cost and STOP at zero (the cost vs flow curve
is convex, so this is the exact max profit optimum); integer exact under unit capacities and total
unimodularity, no float in the objective; deterministic via stable node ids and a node id priority
queue tiebreak. This is implemented exactly in `optimizer.go`.
- **Maximum profit unbalanced assignment** as a min cost flow where candidates and slots may be left
unmatched (the SOURCE rows), and the value matrix counterfactual as the interpretable, AEDT defensible
explanation (the next best alternative held fixed, not an LP re solve marginal).
- **Faithfulness gating** (CRAG, Self RAG family): constrain the prose to the supplied evidence, withhold
and fall back to a deterministic template when the gate cannot confirm, and record why for later tuning.
## What was built
- **Migration 0018** (`recommendation_runs`, `staffing_recommendations`): RLS enabled and forced, org
scoped, composite FKs leading with organization_id, the engine evaluation reference as a composite FK to
`candidate_evaluations (organization_id, candidate_id, requirement_id)` that MATCH SIMPLE correctly skips
for a source row, candidate scoped for erasure, grants to `missionmatch_app` only. Numbered 0018 on the
v17 head.
- **The pure recommendation core** (`config.go`, `types.go`, `value.go`, `confidence.go`, `classify.go`):
global config with per run override and auditable defaults; the int64 scaled value function (engine
total times a bounded priority multiplier from the opportunity dollar value, documented rounding);
deterministic confidence (fit, clearance provenance, completeness); the action classifier (assign,
reassign with a priority delta, reskill gated on the clearance gate plus a KAG adjacency, a single
source note). All pure, no DB, no clock, no model.
- **The optimizer** (`optimizer.go`): the pure Go minimum cost flow solver, a size cap and a context time
budget so a solve never hangs, and the value matrix counterfactual extraction.
- **The three views** (`gap.go`, `portfolio.go`, `proactive.go`): the gap view reads current commitment so
a committed candidate is a reassign, not a duplicate assign; the portfolio view runs the optimizer,
builds per assignment counterfactuals, and is value fallback safe (an unknown opportunity value is
imputed with the median of the known values, never silently zero); the proactive bench watch.
- **Narration** (`narrate.go`): faithfulness gated prose grounded only in the deterministic evidence, with
a deterministic fallback and a recorded fallback reason (kept out of the audit). The recommendation
never depends on it; a plane outage degrades the prose, not the correctness.
- **The service and endpoints** (`service.go`, `handler.go`, `dto.go`, `errors.go`): four endpoints behind
the session resolver, CSRF, RBAC, rate limit, and audit, with one typed error envelope (404, 409, 413,
422, 503), pagination, a fresh run per POST that supersedes only the prior pending rows of its scope, the
decision path with row locking and a 409 on a non pending row, and the two AEDT events
(`aedt.staffing.recommended` on a run, `aedt.staffing.decided` on a decision) plus a served score audit
for each surfaced candidate (consistent with the W2 four fifths fix). No PII, no names, no demographics,
and no rationale prose in any audit payload.
- **The scheduled job** (`cmd/staffing-proactive-sync`, `infra/systemd/mm-staffing-proactive.{service,
timer}`): pure Go, FIPS built, daily at 05:00 after the ingestion timers, idempotent, deterministic
rationales.
- **Erasure**: the right to erasure removes a candidate's recommendations in BOTH the sourcing anonymize
and the governance retention paths (the FK cascade does not fire on anonymize in place).
- **RBAC**: a new write capability `staffing.recommend`, granted to the roles that hold `slate.write`. The
decision reuses the slate capability; reads reuse `candidate.read`.
- **Wiring and contract**: mounted in `cmd/api/main.go` (reusing the one skill matcher, an optional
inference client); the full request and response contract added to `docs/openapi.yaml`.
## Test results
- **Unit (race, no DB):** all pass, including 18 classifier, value, and confidence golden tests and the 9
optimizer tests. The decisive optimizer test proves it is a true optimizer, not greedy: an instance
where greedy scores 11 and the true max profit is 17, solved to 17, plus determinism over 20 runs, the
size cap, the budget, and the counterfactuals.
- **Safety unit:** the EEO tripwire (now over the staffing package) and the no protected attribute test.
- **Live integration on M4 staging:** 5 of 5 W3 tests pass (gap assign plus source with a real frozen
evaluation reference and the deterministic fallback; portfolio allocation with value and counterfactual;
the proactive bench watch; the decision plus a 409 conflict with no auto reject; erasure removal). The
full suite on the bare staging database: 37 pass, 6 skip (plane or seed dependent), 1 fail
(`TestCommandCenterUpcomingIncumbentAdopt`, which needs the global federal forecast catalog seeded;
empty on a fresh staging database, unrelated to W3). Zero W3 caused failures.
- **Migration:** 0018 applied cleanly through the full v18 schema plus the eeo set on staging.
- **Build gates:** FIPS stamp present after every build, `make ci-gates` green (backdoor and FIPS), vet
and gofmt clean, the whole repo builds, no Python, no cgo.
## What the adversarial review found and what was fixed
A 5 dimension adversarial review (EEO and AEDT safety, the engine floor and no model in the decision path,
denial of service and concurrency, data integrity and tenancy, hygiene and contract) with each finding
independently verified, confirmed two issues, both fixed:
1. **Medium, concurrency.** The gap and proactive write paths superseded then inserted without the per org
advisory lock the portfolio path held. Under READ COMMITTED, two concurrent same scope runs could each
leave a live pending set. Fixed: the advisory lock was generalized to a `(view, org, scope)` key and
applied to all three write paths, so same scope writes serialize while different scopes still run in
parallel. (Decided rows were never at risk; the status guarded supersede and the FOR UPDATE decision
path were already correct.)
2. **Low, hygiene.** `GetRecommendationRun` and `ListRecommendationsByRun` were dead queries. Fixed:
removed and regenerated.
## What remains (genuine decisions or sequenced work)
1. **The frontend** is a separate workstream (out of scope here by direction). The backend interface
handoff is `docs/openapi.yaml`: the finalized request and response schemas, the enums, and the one
error envelope the future UI consumes. The decision columns mirror `slate_members` so the existing
approve and reject component carries over.
2. **The production cutover** is the operator's manual step in `DEPLOY_PLAN.md` (apply 0018, deploy the
binary that mounts the routes, install the proactive timer, verify, roll back). It was validated on M4
staging and deliberately NOT run against production.
3. **Per org configuration** of the floor, the adjacency threshold, and the confidence constants is a
future addition; v1 is global defaults plus a per run override, recorded in the run parameters.
4. **The learned LTR reranker with SHAP** (AI layer Phase 8) and the **learned win probability** (Phase 9)
stay OUT of W3 v1 by direction. The **TEAM** action is reserved in the enum and waits on GraphRAG
teaming leaving scaffold.
5. **Proactive change attribution.** The bench watch refreshes the full available bench each run and tags
the trigger as a recompute. Attributing a specific change (newly available, newly certified, a new
opportunity unlock) via candidates.updated_at diffing is a refinement.
6. **Feed freshness.** The watch only surfaces an opportunity once the ingestion timers have ingested it;
the audit flagged the SAM sync timer as possibly not firing. DEPLOY_PLAN notes confirming the timer
before relying on the watch for new postings. W3 does not change the sync timers.
## Commits
`5485603` migration and queries and RBAC; `10828b2` the recommendation core; `a60ef4c` the optimizer;
`e183eb0` the three views, narration, service, endpoints, wiring, and safety tests; `e298916` the proactive
job and timer; `2ac466f` the erasure join and integration tests; `15fc448` the openapi and deploy plan;
`635a410` the final review fixes.