Identity Stability Execution Plan
Status: ⚠️ CRITICAL FIXES REQUIREDPriority: BLOCKING for semantic view production use
Quick Reference: Guarantee Statements
Business ID Stability (Post-Fix)
MERGE Key:(tenant_id, normalized_name)Immutable Field:
business_idGeneration: MD5 hash of
normalized_name (first 16 hex chars)Guarantee: Same
(tenant_id, normalized_name) → same business_id forever
Agent Identity Stability (Post-Migration)
MERGE Key:(tenant_id, agent_key)Immutable Field:
agent_keyGeneration: SHA256 hash of normalized
display_name (prefix: "AGENT:" + 16 hex chars)Guarantee: Same
(tenant_id, normalized_name) → same agent_key forever
Phase 1: Business ID Fixes (IMMEDIATE)
Step 1.1: Update Schema
File:integration/bigquery/schemas/dim_business_mapping_schema.jsonChange: Add
tenant_id as first field ✅ DONE
Step 1.2: Create MERGE SQL
File:integration/bigquery/sql/tables/dim_business_mapping.sql ✅ CREATED
MERGE Key: (tenant_id, normalized_name)Immutable:
business_id (never updated)
Step 1.3: Migration Script
File:integration/bigquery/sql/migrations/add_tenant_id_to_business_mapping.sql (CREATE)
Step 1.4: Update BusinessIDGenerator
File:utils/business_id_generator.pyChanges:
- Add
tenant_idparameter to__init__()and all methods - Include
tenant_idin CSV schema - Update
_save_mapping()to includetenant_id
Step 1.5: Update Loader
File:integration/bigquery/scripts/load_reference_tables.pyChange: Replace
WRITE_TRUNCATE with MERGE statement (use SQL from dim_business_mapping.sql)
Phase 2: Agent Identity Migration (REQUIRED)
Step 2.1: Create Schema
File:integration/bigquery/schemas/dim_agent_identity_schema.json ✅ CREATED
Step 2.2: Create MERGE SQL
File:integration/bigquery/sql/tables/dim_agent_identity.sql ✅ CREATED
MERGE Key: (tenant_id, agent_key)Immutable:
agent_key (never updated)
Step 2.3: Initial Population Script
File:integration/bigquery/sql/migrations/populate_agent_identity.sql (CREATE)
Step 2.4: Update Semantic View (Backward Compatible)
File:integration/bigquery/sql/views/semantic_view_commission_traceability.sql
Changes:
- Add
agent_identityCTE (join todim_agent_identity) - Update
stage3_component_idhash to useagent_key(fallback toagent_id) - Keep
agent_idin final SELECT for backward compatibility - Add
agent_keyto final SELECT
Phase 3: QA Invariants
Step 3.1: Add Business ID Churn Check
File:tests/test_semantic_view_qa_invariants.sql
Add Invariant #7 (see IDENTITY_STABILITY_GUARANTEES.md section 4.1)
Step 3.2: Add Agent Key Stability Check
File:tests/test_semantic_view_qa_invariants.sql
Add Invariant #8 (see IDENTITY_STABILITY_GUARANTEES.md section 4.2)
Step 3.3: Update Tenant Isolation Tests
File:tests/test_semantic_view_qa_invariants.sql
Update Invariant #6 Check A to use agent_key joins (see IDENTITY_STABILITY_GUARANTEES.md section 2.4)
Validation Checklist
Before marking as complete:-
dim_business_mappinghastenant_idcolumn - MERGE SQL uses
(tenant_id, normalized_name)key -
business_idis never updated in MERGE (only inserted) -
BusinessIDGeneratorincludestenant_idin all operations - Loader uses MERGE instead of
WRITE_TRUNCATE -
dim_agent_identitytable created and populated - Semantic view uses
agent_keyinstage3_component_idhash - QA invariants pass (0 business_id churn, 0 agent_key churn)
- Tenant isolation tests updated for
agent_key
Rollout Order
-
Week 1: Business ID fixes (Phase 1)
- Deploy schema update
- Run migration script
- Update generator and loader
- Validate with QA invariants
-
Week 2: Agent identity migration (Phase 2)
- Create
dim_agent_identitytable - Populate from existing data
- Update semantic view (backward compatible)
- Validate with QA invariants
- Create
-
Week 3: QA and validation (Phase 3)
- Run all invariants
- Verify no ID churn
- Test tenant isolation
- Document results
Risk Mitigation
Backward Compatibility
- Keep
agent_idin semantic view SELECT (addagent_keyalongside) - Existing queries continue to work
- Gradual migration path
Data Loss Prevention
- MERGE operations are idempotent (safe to rerun)
business_idandagent_keyare immutable (never updated)- QA invariants detect churn before production
Rollback Plan
- Keep old loader code in git history
- MERGE statements can be reverted to INSERT-only
- Schema changes are additive (can drop
tenant_idif needed)
Next Steps: Execute Phase 1 fixes immediately, then proceed with Phase 2.