Plan Red Flags & Alignment Review
Date: 2025-01-XXStatus: π΄ CRITICAL RED FLAGS FOUND
π΄ RED FLAG #1: dim_agent_hierarchy Missing tenant_id
Issue
Semantic view referencestenant_id in agent_hierarchy CTE, but schema doesnβt have it
Location: integration/bigquery/sql/views/semantic_view_commission_traceability.sql (lines 214, 227)
Current Code:
dim_agent_hierarchy_schema.json has NO tenant_id field
Impact:
- β οΈ CRITICAL: View will fail at runtime (column not found)
- β οΈ Tenant isolation broken: Cannot enforce tenant scoping in hierarchy joins
- β οΈ QA tests will fail: Tenant isolation checks assume
tenant_idexists
- Add
tenant_idtodim_agent_hierarchyschema - Create migration script to backfill
tenant_id - Update loader to include
tenant_id - OR: Remove
tenant_idfrom semantic view CTE (if single-tenant assumption)
π΄ RED FLAG #2: agent_key Generation Inconsistency
Issue
Three differentagent_key generation strategies documented
Strategy A (Execution Plan - Line 102):
- Strategy A/B: Hash-based (deterministic, but different from legacy
agent_id) - Strategy C: Uses upstream numeric ID (721995) - NOT deterministic from name
- β οΈ Inconsistent keys: Same agent could get different
agent_keydepending on which strategy is used - β οΈ Breaks determinism: If using upstream ID,
agent_keyis not deterministic fromagent_name - β οΈ Migration confusion: Unclear which strategy to use
- Option 1: Always use hash-based (deterministic from
agent_name) - Option 2: Use upstream ID if available, hash otherwise (requires mapping logic)
- Option 3: Use hash for all, store upstream ID separately in
upstream_agent_id
π΄ RED FLAG #3: Join Strategy Unclear
Issue
No explicit join strategy documented fordim_agent_hierarchy β dim_agent_identity
Current State:
dim_agent_hierarchy.agent_id: STRING (can be numeric β721995β or minted βNAME:abc123β)dim_agent_identity.upstream_agent_id: STRING (nullable, stores upstream ID)dim_agent_identity.agent_key: STRING (hash-based, deterministic)
- How to join
dim_agent_identitytodim_agent_hierarchy? - Should join be:
agent_keyβupstream_agent_idβdim_agent_hierarchy.agent_id? - Or:
agent_namematch? - Or: Direct
agent_idmatch (if hierarchy uses minted IDs)?
- What is the join key between
dim_agent_identityanddim_agent_hierarchy? - Does
dim_agent_hierarchy.agent_idcontain:- Upstream numeric IDs (721995, 668078)?
- Minted hash IDs (βNAME:abc123β)?
- Both?
- Should semantic view join via
agent_keyβupstream_agent_idβdim_agent_hierarchy.agent_id?
π‘ YELLOW FLAG #1: agent_key Hash Length Mismatch
Issue
Legacyagent_id uses 12 hex chars, agent_key uses 16 hex chars
Legacy (mint_agent_id_from_name):
agent_key):
- β οΈ Different lengths:
agent_id= βNAME:abc123def456β (18 chars),agent_key= βAGENT:abc123def4567890β (22 chars) - β οΈ Not directly comparable: Cannot use
agent_idas fallback foragent_keyin hash
π‘ YELLOW FLAG #2: Migration Script Syntax Error
Issue
BigQuery array slicing syntax[:16] may not work
Location: docs/IDENTITY_STABILITY_EXECUTION_PLAN.md (Line 102)
Code:
[:16]
Correct Syntax:
SUBSTR() instead of [:16]
π‘ YELLOW FLAG #3: Missing Migration File
Issue
Migration script referenced but not created Location:docs/IDENTITY_STABILITY_EXECUTION_PLAN.md (Step 1.3, Step 2.3)
Files Referenced:
integration/bigquery/sql/migrations/add_tenant_id_to_business_mapping.sql(NOT CREATED)integration/bigquery/sql/migrations/populate_agent_identity.sql(NOT CREATED)
β ALIGNMENT CHECKS
Schema Alignment
- β
dim_business_mapping_schema.jsonincludestenant_id(updated) - β
dim_agent_identity_schema.jsoncreated with correct fields - β
dim_agent_hierarchy_schema.jsonmissingtenant_id(RED FLAG #1)
MERGE Key Alignment
- β
dim_business_mapping: MERGE key(tenant_id, normalized_name)documented - β
dim_agent_identity: MERGE key(tenant_id, agent_key)documented - β
Both immutable fields (
business_id,agent_key) correctly marked as never updated
Data Type Alignment
- β
stage3_snapshots.agent_id: STRING - β
dim_agent_hierarchy.agent_id: STRING - β Type-compatible for joins
Hash Signature Alignment
- β
stage3_component_idhash documented in both view and tests - β
stage1_row_idhash documented in both view and tests - β οΈ
agent_keygeneration inconsistent (RED FLAG #2)
π΄ CRITICAL ACTION ITEMS
Immediate (Blocking)
- Fix RED FLAG #1: Add
tenant_idtodim_agent_hierarchyschema OR remove from semantic view - Fix RED FLAG #2: Standardize
agent_keygeneration strategy (recommend hash-based) - Fix RED FLAG #3: Document explicit join strategy for
dim_agent_hierarchyβdim_agent_identity
Short-term (Required)
- Fix YELLOW FLAG #2: Update SQL syntax (
[:16]βSUBSTR(..., 1, 16)) - Fix YELLOW FLAG #3: Create migration SQL files
- Clarify: How to handle hardcoded numeric IDs (721995, 668078) in
dim_agent_hierarchy
Summary: Red Flags Found
| Flag | Severity | Issue | Impact |
|---|---|---|---|
| #1 | π΄ CRITICAL | dim_agent_hierarchy missing tenant_id | View will fail, tenant isolation broken |
| #2 | π΄ CRITICAL | agent_key generation inconsistent | Non-deterministic keys, migration confusion |
| #3 | π΄ CRITICAL | Join strategy unclear | Cannot implement semantic view correctly |
| #4 | π‘ HIGH | SQL syntax error ([:16]) | Migration script will fail |
| #5 | π‘ MEDIUM | Migration files missing | Cannot execute plan |