ai-powered-conversational-intelligence

44 — AI Governance Center

Prompt 44 of the ongoing Enterprise AI Analytics & Recommendation Platform initiative: a governed Draft -> Test -> Evaluate -> Approve -> Deploy -> Rollback lifecycle for models, providers, prompts, agents, tools, retrieval sources, and policies – owners, versions, approvals, usage/cost/latency, and policy events, restricted by role, with release and rollback APIs plus dashboard views. INSPECT/PLAN/IMPLEMENT/TEST/ REVIEW/FIX/DOCUMENT — one new top-level package (governance_center/), two new identity tables, a new standalone REST surface (api/governance.py), a new frontend page, server-driven nav wiring, new RBAC permissions, and a dedicated cross-cutting regression test proving the mission’s own two named test requirements. No existing route, node, prompt, or Settings field changed behavior for any pre-existing caller.

0. A found, disclosed concurrent-work note

While this prompt was in progress, a separate, concurrent session committed its own unrelated work (5b2e6a5, Prompt 43’s “Schema Drift Impact Analysis,” schema_drift//api/schema_drift.py) directly on top of this branch’s own history, mid-session. This was discovered by re-checking git status before committing and confirmed by git log – not a conflict with anything this prompt built (no shared file was left in an inconsistent state; api/main.py/config/settings.py/ frontend/vite.config.ts/frontend/src/components/layout/AppShell.tsx were all re-read fresh after that commit landed, and this prompt’s own edits to each were applied cleanly on top of it, confirmed by a full api.main import check and a clean alembic heads single-head check immediately after). Disclosed here for the same reason Prompt 42’s own §0 disclosed a different cross-branch finding: an honest record of what happened during implementation, not a silent workaround.

1. Inspection: what already existed vs. the real gap

Exhaustive inspection confirmed no prior “asset lifecycle/release governance” concept existed anywhere in this codebase for models, providers, prompts, agents, tools, retrieval sources, or policies – every one of those is governed today only by static .env configuration (Settings.ollama_allowed_models, ENABLE_* flags, agent/multiagent/’s own hardcoded AgentSpec/Tool registrations) with no draft/test/evaluate/approve/deploy/rollback workflow, no versioning, no owner/approval record, and no audit trail of who changed what and when. The closest existing building blocks, all found by inspection and reused rather than reimplemented:

2. What was built

governance_center/ (new top-level package)

identity/models.py + migration c7d2e5f8a1b4

identity/repositories/governance.py

create_draft, update_draft (draft-only, mirrors SemanticCatalogEntry’s identical in-place-edit exception), submit_for_testing/record_test_results/submit_for_evaluation/ record_evaluation_results/approve/reject/deploy/rollback/ retire/record_usage, list_events, usage_summary (a plain, deterministic sum/mean aggregation – DATABASE_FACT), version_to_snapshot. Every transition goes through _apply_transition’s atomic, conditional UPDATE ... WHERE stage = expected_current – proven race-safe with two independent Sessions (not real threads, for the identical, already-documented reason a shared in-memory SQLite connection isn’t a safe stand-in for genuine concurrency). deploy/rollback each mutate a second row (the previously-deployed/ rollback-target version) on the same ORM object before the primary row’s own atomic commit, so a lost race on the primary row rolls the second row’s change back too.

identity/rbac.py

New Permission.GOVERNANCE_MANAGE (admin tier) / GOVERNANCE_REVIEW (analyst tier), seeded via the existing idempotent identity.bootstrap .seed_rbac – no migration needed for RBAC data itself, the same “picked up automatically on next startup” contract every prior permission addition already has.

api/governance.py + api/governance_schemas.py

15 routes under /governance, all requiring a local account (require_local_user). No Settings.enable_* feature flag – an administrative/compliance surface gated purely by RBAC, the identical posture api/onboarding.py/api/semantic_catalog.py/ api/platform_admin.py already establish. Every route resolves the target version by id first, then calls authorize_governance_action and acts only on allowed=True – a cross-tenant version is denied the same 404 a genuinely nonexistent one would get.

Frontend

frontend/src/pages/AIGovernance.tsx – list + detail + capability- gated action buttons, mirroring SemanticReview.tsx’s own shape. frontend/src/lib/governanceApi.ts – thin request() wrappers. Wired through security/navigation.py (new ai_governance NavItem), App.tsx, AppShell.tsx’s screen-presentation map (new ClipboardCheck icon), frontend/vite.config.ts’s dev-proxy BACKEND_ROUTES, and all 5 locale files’ nav label.

3. Authorization, tenant isolation, and provenance

RBAC: GOVERNANCE_MANAGE (admin tier – every operational action: create/edit draft, submit for testing/evaluation, record results, deploy, roll back, retire, record usage) and GOVERNANCE_REVIEW (analyst tier – approve/reject only, the identical domain-judgment tier ONBOARDING_REVIEW/CATALOG_REVIEW/RECOMMENDATION_REVIEW already sit at). Proven directly: a GOVERNANCE_REVIEW-only caller can approve but gets a 403 on deploy/rollback/retire; a GOVERNANCE_MANAGE caller can do everything review can plus every operator action.

Tenant isolation mirrors onboarding.policy/semantic .catalog_policy exactly – GovernanceAssetVersion.tenant_id + governance_center.policy.authorize_governance_action’s own ABAC check, cross-tenant denial mapped to the same 404 a genuinely nonexistent version would get. Proven directly against a real identity database with two real tenants: a cross-tenant GET/deploy/rollback is a 404; a tenant’s own GET /governance/assets list never includes another tenant’s versions.

Provenance: every version’s own truth_level is a governance- approval signal (CONFIRMED_BUSINESS_TRUTH only once a human approves it for deployment) – never a claim about anything the asset itself produces at runtime, which remains each engine/pipeline’s own, already-established provenance, completely unaffected by this prompt.

4. Two real bugs found and fixed before any test was left to merely

document the wrong behavior

  1. LIST/GET .../current were wrongly denied with a 403. authorize_governance_action originally treated every non- CREATE_DRAFT action’s asset_tenant_id=None as “resource not found” – correct for VIEW on one specific, already-resolved version, but wrong for listing/looking-up-the-current-deployed- version, neither of which has one specific resource to tenant-match against (the query itself scopes the result to the caller’s own tenant). Fixed by giving LIST its own, distinct GovernanceAction, authorized by permission alone like CREATE_DRAFT. Locked in by a dedicated unit test in tests/test_governance_center.py.
  2. approve/retire required a request body even though every field on each is optional. FastAPI treats a bodied-model route parameter as requiring some JSON content unless that parameter itself has a default – a caller correctly omitting the body entirely (since nothing on ApproveRequest/RetireRequest is required) got a 422. Fixed by giving each route’s own payload parameter a module-level singleton default instance (not a mutable default constructed inline, which ruff’s B008 correctly flags). Locked in by tests/test_api_governance.py ::test_approve_and_retire_work_with_no_request_body_at_all.

5. Testing

Full suites re-run clean: backend governance-specific tests 121/121 passing; mypy clean on every new/changed production module (two pre- existing, unrelated nullable-FK-assignment mypy errors elsewhere in identity/repositories/ confirmed untouched by this session, matching a pattern already tolerated there); ruff/black clean; frontend tsc --noEmit clean, npm run lint clean on every new file, and the full frontend suite passes (one pre-existing, unrelated flaky test in TurnCard.analytics.test.tsx – confirmed to pass reliably in isolation and to involve no file this prompt touched – noted honestly, not silently ignored).

6. Known, disclosed limitations

Either (a) a read-only “drift” check between this center’s own deployed versions and the live Settings/agent/multiagent/ configuration (flagging, never auto-correcting, a mismatch – “this tool is marked deployed here but isn’t registered in the live tool registry”), which would close §6’s last limitation without taking on the much larger risk of making live pipeline selection database-driven; or (b) extending observability/metrics.py with real per-model/ per-prompt usage capture (closing the “operator-reported, never auto-instrumented” limitation for real), which several other prompts in this series have already identified as a disclosed, deferred gap.