Overview
This guide covers common error scenarios, their causes, and solutions. All errors are logged with structured context for efficient debugging.Error Categories
Errors are organized into these categories:- Webhook Errors: Signature verification, deduplication issues
- Tenant Configuration Errors: Missing or invalid tenant config
- Instructions Errors: Missing or invalid prompts
- Capacity Errors: Call limits exceeded
- Tool Errors: Tool build or execution failures
- Database Errors: MongoDB connection or query failures
Common Error Scenarios
Webhook Verification Failed
Error Code:webhook_verification_failed
Cause: Invalid webhook signature from OpenAI
Location: openai_webhook.py:81
Log Example:
| Issue | Solution |
|---|---|
| Wrong secret configured | Verify OPENAI_WEBHOOK_SECRET matches OpenAI console |
| Clock skew | Ensure server time is synchronized (NTP) |
| Proxy modifying headers | Check reverse proxy doesn’t strip signature headers |
Tenant Not Configured
Error Code:tenant_not_configured
Exception: TenantNotConfiguredError (exceptions.py:53)
Cause: Tenant has no configuration document or invalid state
Location: openai_webhook.py:346
Log Example:
| Issue | Solution |
|---|---|
| Tenant not provisioned | Create tenant configuration in database |
| Invalid tenant ID in routing | Check phone number → tenant mapping |
| Configuration deleted | Restore tenant config from backup |
| State document malformed | Validate JSON schema of state document |
Instructions Missing
Error Code:instructions_missing
Exception: InstructionsMissingError (exceptions.py:73)
Cause: Tenant configured but instruction text cannot be resolved
Location: openai_webhook.py:368
Log Example:
| Issue | Solution |
|---|---|
| Greeting text empty | Add greeting content to tenant configuration |
| Instruction text empty | Add instruction/prompt content |
| Referenced ID not found | Check greeting_id/instruction_id exist in database |
| Prompt deleted but still referenced | Update state pointers or restore prompt |
Instructions DB Error
Error Code:instructions_db_error
Exception: InstructionsDBError (exceptions.py:101)
Cause: Database connection failure or query timeout
Location: openai_webhook.py:390
Log Example:
data/prompts/downtime.py):
| Issue | Solution |
|---|---|
| MongoDB connection timeout | Check MONGODB_URI and network connectivity |
| Database overloaded | Scale MongoDB resources or add read replicas |
| Query timeout | Optimize indexes or increase timeout settings |
| Authentication failure | Verify MongoDB credentials |
fallback_instructions_used increments when fallback is used
Capacity Limit Reached
Error Code:call_reject_failed or capacity rejection
Cause: Global or per-tenant concurrent call limit exceeded
Location: openai_webhook.py:298-337
Log Example:
| Issue | Solution |
|---|---|
| Legitimate traffic spike | Increase MAX_CONCURRENT_CALLS |
| Single tenant monopolizing | Implement per-tenant limits |
| Calls not ending properly | Check for session cleanup bugs |
| Pending calls stuck | Review _release_pending_capacity_state calls |
Tenant Config Parse Error
Error Code:tenant_config_parse_error
Exception: TenantConfigParseError (exceptions.py:136)
Cause: Tenant config exists but fails Pydantic validation
Location: openai_webhook.py:487
Log Example:
| Issue | Solution |
|---|---|
| Invalid JSON syntax | Validate JSON with linter |
| Missing required fields | Check TenantConfig model requirements |
| Wrong data types | Ensure fields match expected types (str, int, etc.) |
| Schema version mismatch | Update config to current schema version |
Tool Build Error
Error Code:tool_build_error
Exception: ToolBuildError (exceptions.py:240)
Cause: Tool configuration invalid or tool builder failure
Location: openai_webhook.py:537
Log Example:
| Issue | Solution |
|---|---|
| Invalid tool configuration | Validate tool config schema |
| Missing tool dependencies | Ensure required tool modules installed |
| Tool initialization failure | Check tool constructor parameters |
Tool Execution Errors
Exception:ToolExecutionError (exceptions.py:164)
Variants:
ToolNotFoundError(exceptions.py:194): Tool invoked but not in tool listToolArgsParseError(exceptions.py:214): Cannot parse tool arguments JSON
| Error | Solution |
|---|---|
| ToolNotFoundError | Ensure tool name matches tool list exactly |
| ToolArgsParseError | Validate arguments JSON format |
| ToolExecutionError | Check tool implementation for exceptions |
Debugging with Structured Logging
Log Event Function
All events are logged usinglog_event from src/core/logger.py:97:
Log Output Format
Logs use JSON format (logger.py:24):Context Variables
Tenant and call IDs are automatically attached via context vars (logger.py:9):Filtering Logs
Filter logs by event, tenant, or call:Log Levels
Configure viaLOG_LEVEL environment variable (settings.py:22):
Call Flow Debugging
Trace Complete Call Lifecycle
- Incoming webhook:
realtime.call.incoming - Webhook verified: No
webhook_verification_failederror - Deduplicated: Check
duplicate_webhook_id - Tenant resolved: Check
tenant_resolution_failed - Capacity checked: Check
rejected: "capacity" - Instructions fetched: Check
instructions_missingorinstructions_db_error - Config loaded: Check
tenant_config_parse_error - Tools built: Check
tool_build_error - Call accepted: Look for
call_accepted - Session started: Look for
call_session_start_failed - Call ended:
realtime.call.endedwebhook
Health Checks
Application Health
MongoDB Connectivity
Check for DB errors in logs:OpenAI API Connectivity
Check for call acceptance failures:Exception Details
All custom exceptions include structured context viato_log_dict() (exceptions.py:44):
Quick Reference: Error Codes
| Event | Severity | Cause | Response |
|---|---|---|---|
webhook_verification_failed | ERROR | Invalid signature | HTTP 401 |
duplicate_webhook_id | WARNING | Duplicate webhook | Ignored |
tenant_resolution_failed | ERROR | Unknown phone number | Call rejected |
tenant_not_configured | ERROR | No tenant config | Call rejected |
instructions_missing | ERROR | Missing prompts | Call rejected |
instructions_db_error | ERROR | DB failure | Fallback prompts used |
tenant_config_parse_error | ERROR | Invalid config JSON | Call rejected |
tool_build_error | ERROR | Tool config invalid | Call proceeds without tools |
call_accept_failed | ERROR | OpenAI API error | Call not accepted |
call_session_start_failed | ERROR | Session start exception | Call hung up |
Getting Help
When reporting issues, include:- Call ID: From logs or metrics
- Tenant ID: Affected tenant
- Event sequence: Filtered logs for the call
- Error context: Full
to_log_dict()output - Environment: LOG_LEVEL, capacity settings, MongoDB version