Troubleshooting
Troubleshooting
Section titled “Troubleshooting”This guide covers common issues you may encounter when running Alita Robot and how to resolve them.
Bot Won’t Start
Section titled “Bot Won’t Start”Invalid Bot Token
Section titled “Invalid Bot Token”Error:
Failed to create new bot: invalid tokenSolution:
- Verify your bot token from @BotFather
- Ensure no extra spaces or newlines in the token
- Check that the token format is correct:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz
# Correct format in .envBOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
# Wrong - has quotesBOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"Database Connection Failed
Section titled “Database Connection Failed”Error:
[Database][Connection] Failed after 5 attempts: connection refusedSolutions:
-
Check PostgreSQL is running:
Terminal window # Linuxsudo systemctl status postgresql# Dockerdocker-compose ps postgres -
Verify connection string:
Terminal window # Test connection directlypsql "postgres://user:pass@localhost:5432/alita?sslmode=disable" -
Check network access:
Terminal window # Is the port open?nc -zv localhost 5432 -
Docker Compose: Ensure PostgreSQL is healthy before Alita starts:
depends_on:postgres:condition: service_healthy
Redis Connection Failed
Section titled “Redis Connection Failed”Error:
[Redis] Failed to connect: connection refusedSolutions:
-
Check Redis is running:
Terminal window redis-cli ping# Should return: PONG -
Verify address and password:
Terminal window REDIS_ADDRESS=localhost:6379REDIS_PASSWORD=your_password # Leave empty if no password -
Docker: Ensure Redis is started before Alita
MESSAGE_DUMP Invalid
Section titled “MESSAGE_DUMP Invalid”Error:
[Bot] Failed to send startup message to log groupSolutions:
-
Format: Channel ID must start with
-100:Terminal window MESSAGE_DUMP=-100123456789 -
Bot access: Add the bot as an admin to the channel
-
Get correct ID: Forward a message from the channel to @userinfobot
Webhook Issues
Section titled “Webhook Issues”Not Receiving Updates
Section titled “Not Receiving Updates”Symptoms:
- Bot starts successfully
- No messages are processed
- Health check returns
healthy
Solutions:
-
Check webhook status:
Terminal window curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo"Look for:
urlshould match yourWEBHOOK_DOMAINhas_custom_certificateif using self-signed certlast_error_messagefor any errors
-
Verify domain is accessible:
Terminal window curl -I https://your-domain.com/health -
Check SSL certificate:
Terminal window openssl s_client -connect your-domain.com:443 -servername your-domain.com
401 Unauthorized
Section titled “401 Unauthorized”Error in Telegram webhook info:
"last_error_message": "Unauthorized"Solutions:
-
Check WEBHOOK_SECRET matches:
- The URL path must include your secret
- Example:
/webhook/your-secret-here
-
Verify configuration:
Terminal window USE_WEBHOOKS=trueWEBHOOK_DOMAIN=https://your-domain.comWEBHOOK_SECRET=your-secret-here
Connection Timeout
Section titled “Connection Timeout”Error:
"last_error_message": "Connection timed out"Solutions:
- Verify port 8080 is accessible from the internet
- Check firewall rules:
Terminal window # Allow port 8080sudo ufw allow 8080/tcp - Check reverse proxy/tunnel is running
Database Issues
Section titled “Database Issues”Migration Failed
Section titled “Migration Failed”Error:
[Database][AutoMigrate] Migration failed: column already existsSolutions:
-
Skip with silent fail (development only):
Terminal window AUTO_MIGRATE_SILENT_FAIL=true -
Mark migration as applied manually:
INSERT INTO schema_migrations (version, executed_at)VALUES ('problematic_migration.sql', NOW()); -
Check migration status:
Terminal window make psql-status
Too Many Connections
Section titled “Too Many Connections”Error:
pq: too many connections for role "alita"Solutions:
-
Reduce connection pool size:
Terminal window DB_MAX_OPEN_CONNS=50DB_MAX_IDLE_CONNS=10 -
Increase PostgreSQL max connections:
Terminal window # In postgresql.confmax_connections = 200 -
Use connection pooling (PgBouncer):
Terminal window DATABASE_URL=postgres://user:pass@pgbouncer:6432/alita
Query Timeout
Section titled “Query Timeout”Error:
pq: canceling statement due to statement timeoutSolutions:
-
Check for slow queries:
SELECT pid, query, state, query_startFROM pg_stat_activityWHERE state != 'idle'ORDER BY query_start; -
Add indexes for slow queries
-
Increase timeout (not recommended for production)
Permission Errors
Section titled “Permission Errors”Bot Lacks Admin Rights
Section titled “Bot Lacks Admin Rights”Error:
telegram: Bad Request: need administrator rights in the chatSolutions:
- Promote the bot to admin in the group
- Grant specific permissions:
- Delete messages
- Ban users
- Pin messages
- Manage topics (for forum groups)
User Not Admin
Section titled “User Not Admin”Error:
You need to be an admin to use this commandThis is expected behavior. Admin commands require the user to be a group admin.
Cannot Restrict Chat Owner
Section titled “Cannot Restrict Chat Owner”Error:
telegram: Bad Request: can't restrict chat ownerThis is a Telegram limitation. The chat owner cannot be:
- Banned
- Muted
- Warned
Performance Issues
Section titled “Performance Issues”High Memory Usage
Section titled “High Memory Usage”Symptoms:
- Memory exceeds
RESOURCE_MAX_MEMORY_MB - Bot becomes slow or unresponsive
Solutions:
-
Enable auto-remediation:
Terminal window ENABLE_PERFORMANCE_MONITORING=trueRESOURCE_MAX_MEMORY_MB=500RESOURCE_GC_THRESHOLD_MB=400 -
Reduce worker pools:
Terminal window DISPATCHER_MAX_ROUTINES=100DATABASE_WORKERS=3 -
Check for memory leaks:
Terminal window DEBUG=true # Enable detailed logging
Slow Response Times
Section titled “Slow Response Times”Symptoms:
- Commands take several seconds to execute
- Database queries are slow
Solutions:
-
Enable query caching:
Terminal window ENABLE_RESPONSE_CACHING=trueRESPONSE_CACHE_TTL=30 -
Check database performance:
-- Find slow queriesSELECT query, calls, mean_exec_timeFROM pg_stat_statementsORDER BY mean_exec_time DESCLIMIT 10; -
Optimize connection pooling:
Terminal window DB_MAX_IDLE_CONNS=50DB_MAX_OPEN_CONNS=200 -
Enable HTTP connection pooling:
Terminal window ENABLE_HTTP_CONNECTION_POOLING=trueHTTP_MAX_IDLE_CONNS=100
High CPU Usage
Section titled “High CPU Usage”Solutions:
-
Limit concurrent goroutines:
Terminal window DISPATCHER_MAX_ROUTINES=100RESOURCE_MAX_GOROUTINES=1000 -
Check for infinite loops in logs
-
Profile with pprof (development only)
Log Analysis
Section titled “Log Analysis”Enable Debug Logging
Section titled “Enable Debug Logging”DEBUG=trueCommon Log Fields
Section titled “Common Log Fields”| Field | Description |
|---|---|
update_id | Telegram update identifier |
error_type | Error type (e.g., *TelegramError) |
file | Source file |
line | Line number |
function | Function name |
Finding Errors in Logs
Section titled “Finding Errors in Logs”# Dockerdocker-compose logs alita 2>&1 | grep -i error
# Systemdjournalctl -u alita-robot | grep -i error
# Last 100 errorsdocker-compose logs --tail=1000 alita 2>&1 | grep -i error | tail -100Log Levels
Section titled “Log Levels”| Level | When to Use |
|---|---|
| DEBUG | Verbose debugging (requires DEBUG=true) |
| INFO | Normal operations |
| WARN | Expected issues (e.g., user blocked bot) |
| ERROR | Unexpected failures |
| FATAL | Critical errors that stop the bot |
Docker-Specific Issues
Section titled “Docker-Specific Issues”Container Keeps Restarting
Section titled “Container Keeps Restarting”# Check exit codedocker-compose ps
# View logsdocker-compose logs alita
# Check for OOM killdocker inspect alita-robot | grep -i oomHealth Check Failing
Section titled “Health Check Failing”# Test health endpoint manuallydocker-compose exec alita /alita_robot --health
# Or from hostcurl http://localhost:8080/healthCannot Connect to Other Services
Section titled “Cannot Connect to Other Services”# Check networkdocker network inspect alita_robot_default
# Verify service names match in DATABASE_URL and REDIS_ADDRESSDATABASE_URL=postgresql://alita:alita@postgres:5432/alita # Use service name, not localhostGetting Help
Section titled “Getting Help”If you cannot resolve an issue:
- Check existing issues: GitHub Issues
- Enable debug logging and collect relevant logs
- Open a new issue with:
- Full error message
- Steps to reproduce
- Environment details (OS, Docker version, etc.)
- Relevant configuration (without secrets)