## Summary
This is the second and final Security cleanup PR in [AERIE-3051 — restore configuration editing and remove transition code](https://linear.app/builder-team/issue/AERIE-3051/after-security-migration-restore-configuration-editing-and-remove), following merged #2214.
It removes the completed migration tools, old Security setup and activation switch. New sites use the current Security model and published configuration through the normal setup paths.
Production effect: cleanup or removal.
## Why
The Security migration is complete. Keeping both setup models and one-time migration controls leaves obsolete paths in the application. API scoring reads must also stop depending on the removed activation switch while preserving the migrated sites whose stored configuration version differs from the active catalog.
## Business Value
- New sites receive the current Security items and ten opening jobs without a separate activation step.
- Normal setup respects published names and points and keeps ordinary duplicate checks.
- Existing ratings, exceptions, notes, documents, jobs, tasks and migration history remain stored.
- Completed migration controls disappear from the admin page.
## How does it work
1. The current Security catalog becomes the default. Published configuration still controls the actual rows, names and points. Only the ten opening work definitions are automatically created; all 36 work definitions remain available through existing work-creation paths.
2. Remove the old sixteen-item defaults, eleven old work definitions, activation checks and the Security-specific permanent provisioning block. Normal duplicate/conflict checks continue to apply, including matching older jobs without definition keys.
3. Remove the migration preview/apply/activation endpoints, admin migration panel and migration-only contract exports. Keep populated history/receipt schema fields and the assessment markers needed to distinguish historical rows.
4. Scoring uses the existing current-model rules. On an API catalog-version mismatch, compare the actual configured rows using the existing bounded comparison, including Security; matching migrated sites remain readable without the switch. Actual configuration differences still require reconciliation. Other Quality Bars keep their scoring behavior.
## Scope
### Included in this phase
- Final Security transition removal and its necessary API/setup compatibility changes.
- Shorten or update existing tests for removed behavior. No new tests or cases; no modified test file grows in lines or bytes.
- Exact final diff paths:
chat/components/admin/p2-scoring/p2-scoring-page.tsxchat/components/admin/p2-scoring/security-migration-panel.tsx
chat/convex/_generated/api.d.ts
chat/convex/p2WorkUnits.test.ts
chat/convex/publicApi/v2/domains/insightsData.ts
chat/convex/publicApi/v2/workManagement.test.ts
chat/convex/rhodes/p2Scoring.ts
chat/convex/rhodes/p2ScoringConfig.ts
chat/convex/rhodes/p2WorkUnitDefinitions.ts
chat/convex/rhodes/p2WorkUnits.ts
chat/convex/rhodes/portfolioWorkbench.ts
chat/convex/rhodes/runtime/siteProvisioning.ts
chat/convex/rhodes/runtime/writes/workUnitGroupWrites.ts
chat/convex/rhodes/securityAssessmentMigration.ts
chat/convex/rhodes/securityAssessmentRollout.ts
chat/convex/rhodes/securityMigrationSchema.ts
chat/convex/rhodes/securityWorkSupport.ts
chat/convex/rhodes/sites.ts
chat/convex/rhodesDashboardParity.test.ts
chat/convex/rhodesMcpMutationParity.test.ts
chat/convex/rhodesMcpParity.test.ts
chat/convex/rhodesP2Scoring.test.ts
chat/convex/securityRepairJourney.test.ts
packages/contracts/package.json
packages/contracts/src/security-assessment-catalog.ts
packages/contracts/src/security-assessment.ts
packages/contracts/src/security-migration.ts
packages/contracts/src/security-work-catalog.ts
### Deliberately excluded for later phases
- No production migration, data rewrite, activation operation, deployment or upstream writeback is performed by this PR's publication.
- No new product controls, automatic work moves, review queues, documentation, scripts or test fixtures are included.
- The pre-existing setup failure when an admin removes an item required by an automatic job is separate work. Local E2E reproduced it with Cameras; direct inspection of the code before the original five migration PRs confirms the same failure behavior already existed, including in Security. This PR does not fix it or expand its scope. Restoring the item makes creation succeed and the failed request saves no partial site.
## Test plan
### Automated validation
- Full pre-rebase Chat suite: 851 files, 12,744 tests passed and one existing skip, plus seven asset tests (pnpm --dir chat test).
- Contracts: 1,426 tests across 104 files passed (pnpm --dir packages/contracts exec vitest run --maxWorkers=1).
- Workspace typechecks, full lint/boundary checks and production Next build passed locally. The build used placeholder public configuration and performed no deployment.
- Independent implementation and post-rebase reviews passed. The rebase preserved the exact feature patch and all intervening main updates. Post-rebase validation passed: 54 tests across five focused files; app and Convex typechecks (pnpm --dir chat typecheck); full lint and boundaries (pnpm lint, three unchanged warnings). The first broad lint attempt included untracked local E2E artifacts; after moving those into the existing ignored scratch folder, the complete normal lint command passed without product-code/config changes. Hosted CI [41105036484](https://github.com/AI-Builder-Team/Aerie/actions/runs/41105036484) passed on exact head 457ef3cf740544b339bbd26e7445b0e5ac8062f2 (attempt 2). The first run failed one unchanged Drive folder-selection browser test. Independent diagnosis found a test synchronization race; the exact test and its full 69-test file passed locally. Retrying only failed CI jobs passed without any code change, commit or push. Mercy review is separate and still pending.
- Agent-run local browser/API E2E on an isolated local Convex backend: Security status/points/exception cases; HTTP reads/writes and scope denial; new-site automatic setup and duplicate prevention; browser rename/reweight/publish; remove/add/restore preserving original work, note, task and dates; configured new-site setup; all 36 work definitions available and shared monitoring work linked to the specified four items; non-Security configuration and ordinary job edits; version-1 site/version-2 catalog scoring reads without a Security activation record. The separately recorded pre-existing removed-item setup failure above was also reproduced and was not changed.
- git diff --check passed. Local E2E introduced no product code or tests. Temporary API keys were revoked.
### Time for Implementation
Approximately 3–4 engineering days without AI assistance for the cleanup, compatibility checks, review and local/browser/API validation.
## Review repairs and contract clarifications
### Latest review: 5716981678
[Review 5716981678](https://github.com/AI-Builder-Team/Aerie/pull/2219#pullrequestreview-5716981678) withdrew the original key/deployment findings. Its metadata also explicitly defers the retired-identity claim because the requested stable-key query already prevents it. Only the broad resolver catch remains marked blocking. Independent current-code diagnosis classifies that concern as valid nonblocking hardening, not a demonstrated cleanup defect.
- The broad resolveSecurityWork catch exists in the [base before this PR](https://github.com/AI-Builder-Team/Aerie/blob/e3f8205cba50d2223bffde6da038119c515e20a3/chat/convex/rhodes/p2WorkUnits.ts#L209-L217). It already converted resolver exceptions into missing-group entries. The cleanup adds only pure duplicate comparison inside that existing try block (p2WorkUnits.ts:203-213; sameResolvedTarget at :102-111).
- The current resolver (securityWorkSupport.ts:20-69) looks up a trusted definition, reads the site and a bounded indexed group list, and validates deterministic key coverage. This call does not supply selected, so selected-item error branches are not reachable here. All catalog references were audited in the prior round. No external request, action, user callback or distinct new exception source was introduced. Expected incomplete/ambiguous catalog failures already followed this path before cleanup. The review supplies no concrete supported input or current failure reproducing the asserted infrastructure-induced partial result.
- The concern is not dismissed as impossible: some existing callers intentionally allow partial provisioning. infrastructure/rhodesProvisioning.ts:518-533 omits strict completeness and can return kind: "ok"; sites.ts:110,174,209 also does not require completeness. Narrowing unexpected-error handling would improve diagnostics and future robustness, but no new reachable defect has been established for this cleanup.
- Partial results include missing counts/details (p2WorkUnits.ts:337-347) and produce site.p2WorkUnits.partialProvision audit records (:362-370). The strict special-program path checks completeness and aborts (specialPrograms.ts:182, runtime/siteProvisioning.ts:45-52). Actual work creation is outside the catch (p2WorkUnits.ts:223-230), and its own resolver call is not wrapped by this catch (runtime/writes/workUnitWrites.ts:95-100). These facts do not imply every caller aborts or every conceivable exception propagates.
- The retired-group allegation remains directly disproved by the exact site/key query at p2ScoringConfig.ts:442-446; restoration never considers an unrelated key. This was also demonstrated by the local remove-A/add-B/restore-A E2E.
No code/test changes, commit, push, production operation, merge or review-trigger mention is made for this round. Cainã explicitly requested evidence without tagging Mercy. Exact-head hosted CI remains green. The hardening concern stays visible here and in AERIE-3051 as separate possible follow-up, without expanding this cleanup or claiming it was fixed.
### Previous review: 5716823870
[Mercy review 5716823870](https://github.com/AI-Builder-Team/Aerie/pull/2219#pullrequestreview-5716823870), reviewed/current head 457ef3cf740544b339bbd26e7445b0e5ac8062f2, tracked in [AERIE-3051](https://linear.app/builder-team/issue/AERIE-3051/after-security-migration-restore-configuration-editing-and-remove). Both findings were independently diagnosed and rejected as blockers; no code or test repair is warranted.
1. The guard-staffing key exists. [security-assessment-catalog.ts:6](https://github.com/AI-Builder-Team/Aerie/blob/457ef3cf740544b339bbd26e7445b0e5ac8062f2/packages/contracts/src/security-assessment-catalog.ts#L6) declares security.security-guard-staffing verbatim. An audit importing the actual TypeScript constants checked every supported key in all 36 work definitions against the ten assessment keys: zero invalid references. SecurityWorkDefinition.supportedItemKeys is typed as readonly SecurityAssessmentItemKey[] (security-work-catalog.ts:14). p2WorkUnitDefinitions.ts:463-479 derives the ten opening definitions from these same imports; securityWorkSupport.ts:40-47 resolves those same keys against current groups, and p2WorkUnits.ts:196-230 uses that resolver for creation. Local live E2E created the ten opening jobs successfully. The claimed nonexistent key does not exist as a defect.
2. This is cleanup after the completed migration, not a migration mechanism for old sites. Cainã authorized this final cleanup only after all 178 sites—including the cancelled/inactive/test records—were migrated and verified and new-site activation was enabled. A fresh read-only production inventory during this review confirmed 178 sites, all current model, zero old-model sites, 1,780 active current Security items, 1,068 historical items and zero inconsistent sites. The verified migration evidence has 178 distinct receipt sites; independent examination of all post-migration snapshots found no remaining work/task/note group references to the six retired legacy Security items. The dependent-record moves have already happened.
The code preserves that production state: runtime/siteProvisioning.ts:30-43 sets new sites to version 2 before configuration/work setup; sites.ts:22-68 preserves that version on raw patch/replace, and its create paths force version 2. p2ScoringConfig.ts:639 and p2Scoring.ts:946 create current Security groups. securityModelOwnership.ts:35-71, applied by crud.ts:150,226,347, preserves owned site fields and rejects legacy imports that would overwrite the Security assessment catalog/history. Active reconciliation reads use the index excluding retired rows (p2Scoring.ts:710-726), so the already migrated six historical items are not reprocessed as current assessments. Ordinary configuration retirement preserves existing records and follows the behavior restored in #2214; this PR does not reintroduce migration-style work moves.
Restoring an unmigrated historical database would require its migration before this post-migration cleanup; it is outside the approved current deployment. Adding a new legacy fallback to support that hypothetical state would contradict the authorized removal rather than repair a demonstrated reachable production failure.
Validation remains: exact-head hosted CI [41105036484](https://github.com/AI-Builder-Team/Aerie/actions/runs/41105036484) passed (attempt 2); post-rebase focused tests 54/54 and app/Convex types plus lint/boundaries passed; prior full Chat 12,744 tests plus seven assets and contracts 1,426 tests passed for the identical cleanup patch. No tests added or enlarged. Independent diagnosis and the key audit changed no source. Production operations for this review were read-only inventory queries; no deployment, migration, activation or data mutation.