Audit Notes: Agent Creation (Phase 6.7)
Last Updated: 2025-01-XXEndpoint:
POST /api/v1/admin/agent-profiles/createService:
payroll-backend-prod (System of Record)
Invariants
1. No Client-Side UUID Generation
Invariant: Backend owns all UUID generation foragent_entity_id. No client-side UUID generation is allowed.
Verification:
agent_entity_id generation.
Violation Impact: Duplicate identities, data inconsistency, audit trail corruption.
2. No Org Leak
Invariant: Cross-org requests return generic NOT_FOUND. No information leak about agent existence in other orgs. Verification:- Create agent in Org A (get
agent_entity_id) - Call endpoint from Org B with same
agent_entity_id - Verify:
error.stage="identity",code="NOT_FOUND", generic message (no indication agent exists in Org A)
3. Deterministic UUIDv5 Path Stability
Invariant: Sameagent_id (within same tenant+org) always produces same agent_entity_id (UUIDv5).
Verification:
- Call endpoint with
agent_id="721995"(Org A, Tenant X) - Capture
agent_entity_id(UUIDv5) - Call endpoint again with same
agent_id="721995"(Org A, Tenant X) - Verify: Same
agent_entity_idreturned,identity_created=false
4. Org/Tenant Scoping Enforcement
Invariant: All operations are scoped totenant_id + org_id. No cross-scope data access.
Verification:
- All BigQuery queries include
tenant_idandorg_idfilters - All identity lookups require matching
tenant_id+org_id - All contact operations require matching
tenant_id+org_id
Expected Failure Modes
1. Contact Creation Fails After Identity Created
Scenario: Identity creation succeeds, but contact creation fails (e.g., invalid email format, BigQuery timeout). Expected Behavior:- Response:
200 OKwitherror.stage="contact",code="CONTACT_CREATE_FAILED" identity_created=true,contact_created=falseagent_entity_idandidentity_idreturned (usable for retry)contact_id=null
- Warning shown: “Identity created but contact creation failed”
- “Retry Contact Creation” button available
- Retry uses stored
agent_entity_id(skips identity creation)
- User clicks “Retry Contact Creation”
- UI sends request with
agent_entity_id(noagent_id) - Backend skips identity creation, retries contact creation
2. Partial Idempotency Response
Scenario: Idempotency key lookup succeeds, but response is incomplete (e.g.,contact_id missing).
Expected Behavior:
- Backend checks
config_agent_profile_idempotencytable - If idempotency key exists, returns stored response
- If stored response is incomplete, logs warning, continues with normal flow
- If idempotency table missing, logs warning, continues (UUIDv4 path still works)
- Option A (idempotency-key heal) requires table; Option B (retry via
agent_entity_id) does not
3. Identity NOT_FOUND on Retry
Scenario: User providesagent_entity_id for retry, but identity doesn’t exist (wrong org, deleted, etc.).
Expected Behavior:
- Response:
200 OKwitherror.stage="identity",code="NOT_FOUND" - Generic message: “Agent identity not found” (no internal values echoed)
- No indication that agent exists in different org
- Error shown: “Agent identity not found. Please create a new agent.”
- Form remains editable, user can create new agent
4. Agent ID Mismatch
Scenario: User providesagent_entity_id + agent_id, but existing identity has different agent_id.
Expected Behavior:
- Response:
200 OKwitherror.stage="identity",code="VALIDATION_ERROR" - Message: “Agent ID mismatch detected” (generic, no internal values)
- Error shown: “Agent ID mismatch. Please verify the agent ID or use a different agent entity ID.”
- Form remains editable
Production Verification Checklist
Pre-Deploy Verification
- BigQuery table
config_agent_profile_idempotencyexists (if using Option A) - Backend code includes idempotency-key handling
- Frontend does NOT generate
agent_entity_id(only idempotency keys for UUIDv4 path) - All BigQuery queries include
tenant_id+org_idfilters
Post-Deploy Smoke Tests
Test 1: Deterministic Path Idempotency
agent_entity_id on both calls.
Test 2: Bootstrap Path (UUIDv4)
agent_entity_id returned, agent_id stored as NULL.
Test 3: Idempotency Key (UUIDv4 Path)
Test 4: Retry Path (agent_entity_id)
identity_created=false, contact updated, same agent_entity_id returned.
Test 5: Cross-Org Security
error.stage="identity", code="NOT_FOUND", generic message (no leak).
BigQuery Verification
Related Documentation
- Checkpoint Document:
PHASE_6_7_CHECKPOINT.md- Full API contract, smoke tests - Deployment Guide:
docs/DEPLOYMENT.md- Manual deploy instructions - Phase Index:
docs/PHASES.md- Phase 6.7 details and locked decisions