This guide helps diagnose and resolve common issues with SocialAi.
- Quick Diagnostics
- Installation Issues
- Database Issues
- Backend Issues
- Worker Issues
- Frontend Issues
- Performance Issues
- Security Issues
Run this comprehensive health check:
# Check Node.js version
node --version # Should be 18.x or higher
# Check PostgreSQL
psql --version # Should be 14.x or higher
pg_isready # Should say "accepting connections"
# Check if services are running
lsof -i :3000 # Backend
lsof -i :4321 # Public app
lsof -i :4200 # Admin console
# Check database connection
psql -U postgres -d socialai -c "SELECT COUNT(*) FROM users;"
# Check API health
curl http://localhost:3000/health- Restart everything:
# Stop all processes (Ctrl+C in each terminal)
# Then restart
npm run dev
npm run dev:public
npm run dev:admin- Clear caches and reinstall:
rm -rf node_modules package-lock.json
rm -rf apps/*/node_modules apps/*/package-lock.json
npm install- Reset database:
dropdb socialai
createdb socialai
psql -U postgres -d socialai -f db/schema.sqlSymptoms:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path package.json
Solutions:
- Verify you're in the correct directory:
cd /path/to/SocialAi
ls package.json # Should exist- Check Node.js version:
node --version # Must be 18.x or higher- Clear npm cache:
npm cache clean --force
npm install- Try with legacy peer deps:
npm install --legacy-peer-depsSymptoms:
createdb: command not found
psql: command not found
Solutions:
macOS:
brew install postgresql@14
brew services start postgresql@14Ubuntu/Debian:
sudo apt-get update
sudo apt-get install postgresql-14
sudo systemctl start postgresqlWindows:
- Download installer from https://www.postgresql.org/download/windows/
- Run installer and follow prompts
Symptoms:
Error: listen EADDRINUSE: address already in use :::3000
Solutions:
- Find and kill process using port:
# macOS/Linux
lsof -ti:3000 | xargs kill -9
# Windows
netstat -ano | findstr :3000
taskkill /PID <process_id> /F- Change port in
.env:
PORT=3001- Restart the application.
Symptoms:
Error: connect ECONNREFUSED 127.0.0.1:5432
Solutions:
- Check if PostgreSQL is running:
pg_isready
# If not: brew services start postgresql@14 # macOS
# If not: sudo systemctl start postgresql # Linux- Verify connection string in
.env:
DATABASE_URL=postgresql://postgres:password@localhost:5432/socialai- Check PostgreSQL logs:
# macOS
tail -f /usr/local/var/log/postgresql@14.log
# Linux
sudo tail -f /var/log/postgresql/postgresql-14-main.log- Test connection manually:
psql -U postgres -d socialai
# If this fails, your credentials or database name might be wrongSymptoms:
ERROR: database "socialai" does not exist
Solutions:
# Create database
createdb socialai
# Or using psql
psql -U postgres
CREATE DATABASE socialai;
\q
# Run schema
psql -U postgres -d socialai -f db/schema.sqlSymptoms:
ERROR: permission denied for table users
Solutions:
- Grant permissions:
psql -U postgres -d socialai
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO your_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO your_user;- Or recreate database as correct user:
dropdb socialai
createdb -O your_user socialai
psql -U your_user -d socialai -f db/schema.sqlSymptoms:
ERROR: relation "users" does not exist
Solutions:
# Run schema
psql -U postgres -d socialai -f db/schema.sql
# Verify tables exist
psql -U postgres -d socialai -c "\dt"Symptoms:
- API responses taking > 1 second
- Database CPU usage high
Solutions:
- Check for missing indexes:
-- Add index on frequently queried columns
CREATE INDEX idx_posts_user_id ON posts(user_id);
CREATE INDEX idx_posts_created_at ON posts(created_at DESC);
CREATE INDEX idx_external_posts_source ON external_posts(source);- Analyze slow queries:
-- Enable query logging
ALTER SYSTEM SET log_min_duration_statement = 1000; -- Log queries > 1s
SELECT pg_reload_conf();
-- View slow queries
SELECT query, calls, total_time, mean_time
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 10;- Run VACUUM:
VACUUM ANALYZE;Symptoms:
Error: Cannot find module 'express'
Solutions:
- Install dependencies:
cd node
npm install- Check for syntax errors:
node --check socialai.node.js- Check environment variables:
cat .env
# Ensure DATABASE_URL and other required vars are setSymptoms:
{"error": "Internal server error"}
Solutions:
- Check server logs:
npm run dev
# Look for error stack traces in output- Test database connection:
psql -U postgres -d socialai -c "SELECT 1;"- Check for missing environment variables:
echo $DATABASE_URL
# Should print connection string- Enable detailed error logging:
// In socialai.node.js
app.use((err, req, res, next) => {
console.error('Error:', err.stack); // Add this
res.status(500).json({ error: err.message });
});Symptoms:
Access to fetch at 'http://localhost:3000/api/users' from origin
'http://localhost:4321' has been blocked by CORS policy
Solutions:
- Check CORS configuration in
socialai.node.js:
app.use(cors({
origin: 'http://localhost:4321', // Must match frontend URL
credentials: true
}));- Update
.env:
CORS_ORIGIN=http://localhost:4321- Restart backend after changes.
Symptoms:
429 Too Many Requests
Solutions:
- Increase rate limit in database:
UPDATE settings
SET value = '{"requests_per_minute": 1000}'
WHERE key = 'rate_limit';- Or disable rate limiting temporarily:
// Comment out in socialai.node.js
// app.use(rateLimiter);Symptoms:
[Worker Manager] No workers started
Solutions:
- Check worker configuration in
socialai.node.js:
const workers = {
farcaster: { enabled: true, path: '../workers/farcaster.worker.js' },
// ... other workers
};- Verify worker files exist:
ls -la workers/*.worker.js- Check worker syntax:
node --check workers/farcaster.worker.jsSymptoms:
[Farcaster Worker] Error: ...
[Worker Manager] Restarting farcaster worker (attempt 1/3)
[Worker Manager] Max restart attempts reached for farcaster
Solutions:
- Check worker logs for errors:
npm run dev | grep "Farcaster Worker"- Test worker independently:
node workers/farcaster.worker.js- Check external service connectivity:
# For Farcaster worker
curl https://hub.farcaster.xyz- Add error handling:
// In worker file
try {
// Sync logic
} catch (error) {
console.error('[Worker] Error:', error);
// Don't crash, just log
}Symptoms:
- Worker shows as healthy
- But database not updating
Solutions:
- Check database permissions:
-- As postgres user
GRANT ALL ON TABLE external_posts TO your_user;- Verify API keys:
echo $FARCASTER_HUB_URL
echo $REDDIT_API_KEY
# Make sure they're set- Check sync interval:
// In worker file
setInterval(syncData, 5 * 60 * 1000); // Every 5 minutes- Manually trigger sync:
// Add to worker
syncData(); // Run immediately on startSymptoms:
[ERROR] Cannot find package 'astro'
Solutions:
- Install dependencies:
cd apps/public
npm install- Check Node.js version:
node --version # Must be 18+- Clear Astro cache:
rm -rf .astro
rm -rf dist
npm run devSymptoms:
Cannot find module '@angular/core'
Solutions:
- Install dependencies:
cd apps/admin
npm install- Check Angular CLI:
npm install -g @angular/cli
ng version- Clear Angular cache:
rm -rf .angular
rm -rf dist
npm startSymptoms:
- Home page works
- Other pages return 404
Solutions:
- Check file exists:
ls apps/public/src/pages/profile.astro- Check route configuration:
// In astro.config.mjs
export default defineConfig({
output: 'server', // For SSR
// or
output: 'static', // For static pages
});- Restart dev server.
Symptoms:
- Page renders but looks broken
- No CSS applied
Solutions:
- Check CSS import:
---
import '../styles/global.css';
---- Check file path:
ls apps/public/src/styles/global.css- Clear browser cache (Cmd+Shift+R or Ctrl+Shift+R).
Symptoms:
Failed to fetch
TypeError: NetworkError when attempting to fetch resource
Solutions:
- Check backend is running:
curl http://localhost:3000/health- Check API URL in frontend:
const API_URL = 'http://localhost:3000'; // Must match backend-
Check CORS (see Backend Issues above).
-
Check browser console for detailed errors (F12).
Symptoms:
- Pages taking > 3 seconds to load
Solutions:
- Check database query performance:
EXPLAIN ANALYZE SELECT * FROM posts LIMIT 100;- Add pagination:
const posts = await db.query(
'SELECT * FROM posts ORDER BY created_at DESC LIMIT $1 OFFSET $2',
[limit, offset]
);- Add caching:
// Simple in-memory cache
const cache = new Map();
const cached = cache.get(key);
if (cached && Date.now() - cached.time < 60000) {
return cached.data;
}- Optimize images:
# Use WebP format
# Reduce file sizes
# Add lazy loadingSymptoms:
FATAL ERROR: Reached heap limit
Solutions:
- Increase Node.js memory limit:
NODE_OPTIONS="--max-old-space-size=4096" npm run dev- Check for memory leaks:
// Monitor memory
setInterval(() => {
const used = process.memoryUsage();
console.log('Memory:', used.heapUsed / 1024 / 1024, 'MB');
}, 60000);- Optimize data fetching:
// Don't load all records
const posts = await db.query(
'SELECT * FROM posts LIMIT 100' // Add limit
);Symptoms:
- Server becomes unresponsive
- High CPU in Activity Monitor/Task Manager
Solutions:
- Identify bottleneck:
# Use Node.js profiler
node --prof node/socialai.node.js- Optimize database queries:
-- Add indexes
CREATE INDEX idx_posts_created_at ON posts(created_at DESC);- Add rate limiting:
// Limit concurrent requests
const limiter = rateLimit({
windowMs: 60000,
max: 100
});
app.use(limiter);Solutions:
- Immediately change database password:
ALTER USER postgres PASSWORD 'new_secure_password';- Update
.env:
DATABASE_URL=postgresql://postgres:new_secure_password@localhost:5432/socialai- Check
.gitignoreincludes.env:
echo ".env" >> .gitignore
git rm --cached .env # If accidentally committedSolutions:
- Check logs for unusual patterns:
# Backend logs
grep "ERROR" logs.txt
grep "429" logs.txt # Rate limit hits- Block IP addresses:
// In socialai.node.js
const blockedIPs = ['1.2.3.4'];
app.use((req, res, next) => {
if (blockedIPs.includes(req.ip)) {
return res.status(403).json({ error: 'Forbidden' });
}
next();
});- Enable stricter rate limiting.
Solutions:
- Sanitize user input:
const sanitizeHtml = require('sanitize-html');
app.post('/api/posts', async (req, res) => {
const content = sanitizeHtml(req.body.content);
// Use sanitized content
});- Set proper headers:
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"]
}
}
}));- GitHub Issues: https://github.com/SMSDAO/SocialAi/issues
- Discussions: https://github.com/SMSDAO/SocialAi/discussions
When reporting an issue, include:
-
Environment:
- OS version
- Node.js version
- PostgreSQL version
-
Steps to reproduce:
- What you did
- What you expected
- What actually happened
-
Logs:
- Backend logs
- Browser console errors
- Database errors
-
Screenshots (if applicable)
Last Updated: 2026-02-07