CorpusIQ

Troubleshooting Guide

Comprehensive guide to diagnosing and fixing common issues with CorpusIQ.

Table of Contents

Quick Diagnostics

Before diving deep, try these quick checks:

Health Check Script

# Run this diagnostic script
cd corpusiq-openai-sdk

# Check Python version
python --version

# Check if server starts
timeout 5 python -m corpusiq || echo "Server failed to start"

# Check endpoints (if running)
curl http://localhost:8000/ || echo "Server not responding"
curl http://localhost:8000/.well-known/oauth-protected-resource || echo "OAuth endpoint issue"

Common Quick Fixes

  1. Restart the server: Stop (Ctrl+C) and restart (python -m corpusiq)
  2. Check virtual environment: Ensure it’s activated
  3. Reinstall dependencies: pip install -e . --force-reinstall
  4. Check logs: Look for error messages in terminal output
  5. Clear cache: rm -rf __pycache__ in src directories

Installation Issues

Error: ModuleNotFoundError: No module named 'corpusiq'

Cause: Package not installed or virtual environment not activated.

Solutions:

# Verify virtual environment is activated
which python
# Should show path to .venv/bin/python

# If not activated:
source .venv/bin/activate  # macOS/Linux
# or
.venv\Scripts\activate     # Windows

# Reinstall package
pip install -e .

Error: Python version not supported

Cause: Python version is older than 3.10.

Solutions:

# Check Python version
python --version

# If too old, install Python 3.10+:
# macOS:
brew install python@3.11

# Ubuntu/Debian:
sudo apt install python3.11

# Then recreate virtual environment:
python3.11 -m venv .venv
source .venv/bin/activate
pip install -e .

Error: pip: command not found

Cause: pip not installed or not in PATH.

Solutions:

# Install pip:
python -m ensurepip --upgrade

# Or install Python with pip:
# macOS:
brew install python@3.11

# Ubuntu/Debian:
sudo apt install python3-pip

Error: Permission denied during installation

Cause: Trying to install system-wide without permissions.

Solutions:

# Don't use sudo with virtual environments!
# Instead, use virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install -e .

# If you must install system-wide (not recommended):
pip install --user -e .

Dependencies fail to install

Cause: Network issues, outdated pip, or conflicting packages.

Solutions:

# Upgrade pip first
pip install --upgrade pip setuptools wheel

# Try installing again
pip install -e .

# If still failing, install individually:
pip install fastapi uvicorn pydantic mcp

# Check for conflicts:
pip check

Server Issues

Server won’t start

Symptoms: Error immediately when running python -m corpusiq.

Diagnostic steps:

# 1. Check if port 8000 is already in use
lsof -i :8000  # macOS/Linux
netstat -ano | findstr :8000  # Windows

# 2. Try a different port
CORPUSIQ_PORT=8001 python -m corpusiq

# 3. Check environment variables
cat .env

# 4. Run in debug mode
CORPUSIQ_DEBUG_MODE=true python -m corpusiq

Common causes & solutions:

  1. Port already in use:

    # Kill existing process
    kill -9 $(lsof -t -i:8000)  # macOS/Linux
    # Or use a different port
    
  2. Invalid .env file:

    # Validate .env syntax
    cat .env
    # Ensure no spaces around = signs
    CORRECT=value
    # Not: WRONG = value
    
  3. Missing assets:

    # Check if widget exists
    ls assets/corpusiq.html
    # If missing, restore:
    git checkout assets/
    

Server crashes immediately

Symptoms: Server starts then crashes with error.

Diagnostic:

# Run with full logging
CORPUSIQ_LOG_LEVEL=DEBUG python -m corpusiq 2>&1 | tee server.log

# Check the last error in log
tail -50 server.log

Common issues:

  1. Import errors: Reinstall dependencies
  2. Configuration errors: Check .env file
  3. File permissions: Ensure read access to all files
  4. Memory issues: Check available RAM

Server runs but responds slowly

Symptoms: Server takes >5 seconds to respond.

Diagnostic:

# Check response time
time curl http://localhost:8000/

# Check server logs for slow operations
CORPUSIQ_LOG_LEVEL=DEBUG python -m corpusiq

Solutions:

  1. Increase resources: More RAM/CPU
  2. Reduce load: Lower rate limits
  3. Optimize queries: Cache frequently accessed data
  4. Check network: Ensure fast connection to data sources

Connection Issues

ChatGPT can’t connect to server

Symptoms: “Unable to reach server” or timeout errors in ChatGPT.

Step-by-step diagnosis:

# 1. Verify server is running
curl http://localhost:8000/
# Should return: {"status": "ok", ...}

# 2. Verify tunnel is working
# Visit the tunnel URL in browser
open https://your-tunnel-url.com

# 3. Check CORS configuration
curl -H "Origin: https://chat.openai.com" \
     -H "Access-Control-Request-Method: POST" \
     -H "Access-Control-Request-Headers: Content-Type" \
     -X OPTIONS \
     https://your-tunnel-url.com/mcp

# Should include CORS headers in response

Common causes:

  1. Server not running:

    ps aux | grep corpusiq
    # If no output, start server
    python -m corpusiq
    
  2. Tunnel not active:

    # Restart tunnel
    cloudflared tunnel --url http://localhost:8000
    # or
    ngrok http 8000
    
  3. Wrong URL in ChatGPT:

    • Must be HTTPS (not HTTP)
    • Must match tunnel URL exactly
    • No trailing slash
  4. CORS not configured:

    # In .env, ensure:
    CORPUSIQ_CORS_ALLOW_ORIGINS_CSV=https://chat.openai.com
    
    # Restart server after changes
    
  5. Firewall blocking:

    • Check firewall allows outbound HTTPS
    • Check tunnel service isn’t blocked
    • Try different network

Tunnel keeps disconnecting

Symptoms: Connection works briefly then fails.

Solutions:

  1. Cloudflare Tunnel:

    # Use authenticated tunnel (more stable)
    cloudflared tunnel login
    cloudflared tunnel create corpusiq
    cloudflared tunnel route dns corpusiq your-subdomain.yourdomain.com
    cloudflared tunnel run corpusiq --url http://localhost:8000
    
  2. ngrok:

    # Use authenticated ngrok (more stable)
    ngrok authtoken YOUR_TOKEN
    ngrok http 8000
    
  3. Alternative: Deploy to cloud platform for stable URL


SSL/TLS errors

Symptoms: “Certificate error” or “SSL handshake failed”.

Solutions:

  1. Tunnel-provided HTTPS: Use tunnel’s HTTPS URL (handles SSL for you)
  2. Custom domain: Ensure valid SSL certificate
    # Check certificate
    openssl s_client -connect your-domain.com:443
    
  3. Let’s Encrypt: Use certbot for free SSL
    certbot certonly --standalone -d your-domain.com
    

Search Issues

Search returns no results

Diagnostics:

# 1. Check if connectors are truly connected
curl http://localhost:8000/debug/tools
# (requires DEBUG_MODE=true)

# 2. Test search directly
curl -X POST http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": "1",
    "method": "tools/call",
    "params": {
      "name": "corpus_search",
      "arguments": {"query": "test", "maxResults": 5}
    }
  }'

Common causes:

  1. No connectors connected:

    • Open connectors interface
    • Verify status shows “Connected” (green)
    • Reconnect if needed
  2. Empty data sources:

    • Verify data exists in connected sources
    • Check date ranges (some sources need recent data)
  3. OAuth tokens expired:

    • Disconnect and reconnect connector
    • Reauthenticate with OAuth
  4. Query too specific:

    • Try broader search terms
    • Remove date/time constraints
    • Search fewer terms
  5. API rate limits:

    • Wait a few minutes
    • Check data source API status

Search returns irrelevant results

Solutions:

  1. Be more specific:

    # Instead of: "report"
    # Try: "Q4 financial report 2024"
    
  2. Use exact phrases:

    # Use quotes: "project phoenix status update"
    
  3. Exclude terms:

    # Use minus: "budget -draft"
    
  4. Specify source:

    # "Search my Gmail for..."
    # "Find in my Drive..."
    

Search is slow

Symptoms: Takes >5 seconds to return results.

Causes & solutions:

  1. Many connectors: More sources = more time

    • Disable unused connectors
    • Search specific sources
  2. Large result sets:

    • Reduce maxResults
    • Be more specific in query
  3. Slow data source APIs:

    • Check API status pages
    • Try again during off-peak hours
  4. Server resources:

    • Upgrade server RAM/CPU
    • Use faster hosting

Connector Issues

Can’t add connector

Symptoms: Connector addition fails or hangs.

Diagnostics:

# Check OAuth endpoints
curl http://localhost:8000/.well-known/oauth-authorization-server

# Check logs during connection attempt
tail -f server.log

Solutions:

  1. OAuth misconfigured:

    • Verify OAuth provider settings in .env
    • Check callback URLs match
    • Ensure OAuth app is active
  2. Popup blocked:

    • Allow popups for ChatGPT domain
    • Try different browser
  3. Network issues:

    • Check internet connection
    • Verify firewall allows OAuth redirects

Connector shows “Error” status

Symptoms: Red error indicator on connector.

Steps to fix:

# 1. Check server logs
grep -i error server.log

# 2. Check API credentials
# Verify OAuth tokens are valid

# 3. Test API directly
# (depends on connector type)

Common fixes:

  1. Expired token:

    • Disconnect connector
    • Reconnect to reauthenticate
  2. API quota exceeded:

    • Wait for quota reset
    • Check API dashboard
  3. Permission revoked:

    • Check data source settings
    • Ensure CorpusIQ still has access
  4. Service outage:

    • Check service status page
    • Wait for service to recover

Connector shows “Connecting” forever

Symptoms: Yellow status never changes to green.

Solutions:

  1. Refresh page: Sometimes status doesn’t update
  2. Check OAuth callback: Ensure redirect succeeded
  3. Review logs: Look for errors during connection
  4. Reconnect: Remove and re-add connector

Authentication Issues

401 Unauthorized errors

Symptoms: All requests return 401.

Causes:

  1. Production mode without OAuth:

    # For testing, disable auth:
    CORPUSIQ_DEBUG_MODE=true
    
    # For production, implement OAuth
    # See DEPLOYMENT.md
    
  2. Invalid token:

    • Check token format
    • Verify token hasn’t expired
    • Validate with OAuth provider
  3. Wrong authorization header:

    # Correct format:
    Authorization: Bearer your-token-here
    
    # Not: Authorization: your-token-here
    

OAuth flow fails

Symptoms: Redirect doesn’t work or shows error.

Diagnostics:

# Check OAuth configuration
cat .env | grep OAUTH

# Test OAuth endpoints
curl http://localhost:8000/.well-known/oauth-authorization-server
curl http://localhost:8000/.well-known/oauth-protected-resource

Solutions:

  1. Callback URL mismatch:

    • Update OAuth app settings
    • Match exactly with ChatGPT callback
  2. Invalid OAuth provider:

    • Verify provider URLs are accessible
    • Check provider is operational
  3. Scope issues:

    • Ensure required scopes are enabled
    • Check user has permissions

Performance Issues

High CPU usage

Diagnostics:

# Check CPU usage
top -p $(pgrep -f corpusiq)

# Profile the application
python -m cProfile -m corpusiq > profile.txt

Solutions:

  1. Too many requests: Implement rate limiting
  2. Inefficient queries: Optimize data source calls
  3. Memory leaks: Restart server, update code
  4. Upgrade resources: More CPU cores

High memory usage

Diagnostics:

# Check memory
ps aux | grep corpusiq

# Monitor over time
watch -n 5 'ps aux | grep corpusiq'

Solutions:

  1. Large result sets: Reduce maxResults
  2. Caching issues: Clear cache, restart server
  3. Memory leak: Update to latest version
  4. Upgrade RAM: Add more memory

Rate limit errors (429)

Symptoms: “Rate limit exceeded” errors.

Solutions:

# Increase rate limit in .env
CORPUSIQ_RATE_LIMIT_REQUESTS_PER_MINUTE=120

# Or wait 60 seconds before retry

# For high-traffic deployments, use Redis:
# See DEPLOYMENT.md for Redis rate limiting

Widget Issues

Widget doesn’t display

Diagnostics:

# Check if HTML file exists
ls -la assets/corpusiq.html

# Check file contents
head assets/corpusiq.html

# Check server logs for widget loading
grep widget server.log

Solutions:

  1. Missing file:

    git checkout assets/corpusiq.html
    
  2. File permissions:

    chmod 644 assets/corpusiq.html
    
  3. CORS issue:

    • Check CORS headers in response
    • Verify origin is allowed
  4. Browser console errors:

    • Open browser dev tools
    • Check console for errors
    • Check network tab for failed requests

Widget loads but buttons don’t work

Solutions:

  1. JavaScript errors:

    • Check browser console
    • Clear browser cache
    • Try different browser
  2. CORS blocking requests:

    • Verify CORS allows POST requests
    • Check preflight OPTIONS requests succeed
  3. Widget version mismatch:

    • Pull latest code
    • Clear cache
    • Restart server

Configuration Issues

Environment variables not working

Symptoms: Changes to .env have no effect.

Common mistakes:

# ❌ Wrong: spaces around =
KEY = value

# ✅ Correct: no spaces
KEY=value

# ❌ Wrong: quotes around everything
KEY="value"

# ✅ Correct: only if value has spaces
KEY=value with spaces needs quotes
KEY="value with spaces"

# ❌ Wrong: not restarting server
# ✅ Correct: always restart after .env changes

Verification:

# Check if variables are loaded
python -c "from corpusiq.settings import Settings; print(Settings())"

CORS not working

Symptoms: Browser shows CORS errors.

Fix:

# In .env:
CORPUSIQ_CORS_ALLOW_ORIGINS_CSV=https://chat.openai.com

# For testing multiple origins:
CORPUSIQ_CORS_ALLOW_ORIGINS_CSV=https://chat.openai.com,https://other-domain.com

# Restart server

Verify:

curl -H "Origin: https://chat.openai.com" \
     -H "Access-Control-Request-Method: POST" \
     -X OPTIONS \
     http://localhost:8000/mcp

# Should show Access-Control-Allow-Origin header

Debugging Tips

Enable debug logging

# In .env:
CORPUSIQ_DEBUG_MODE=true
CORPUSIQ_LOG_LEVEL=DEBUG

# Restart server
python -m corpusiq

# Or run with environment variable:
CORPUSIQ_LOG_LEVEL=DEBUG python -m corpusiq

Capture full logs

# Redirect output to file
python -m corpusiq 2>&1 | tee server.log

# View logs in real-time
tail -f server.log

# Search logs
grep -i error server.log
grep -i warning server.log

Test individual components

# Test Python imports
python -c "from corpusiq import app; print('OK')"

# Test MCP server
python -c "from corpusiq.mcp_server import _load_widget_html; print('OK')"

# Test settings
python -c "from corpusiq.settings import Settings; s = Settings(); print(s)"

Network debugging

# Test local server
curl -v http://localhost:8000/

# Test through tunnel
curl -v https://your-tunnel-url.com/

# Test MCP endpoint
curl -v -X POST https://your-tunnel-url.com/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":"1","method":"tools/list"}'

Browser debugging

  1. Open Developer Tools (F12)
  2. Check Console tab for errors
  3. Check Network tab for failed requests
  4. Check Application tab for storage issues

Getting Help

If you’ve tried everything and still have issues:

  1. Check existing issues: https://github.com/CorpusIQ/corpusiq-openai-sdk/issues

  2. Create a new issue with:

    • Clear problem description
    • Steps to reproduce
    • Environment details (OS, Python version, etc.)
    • Relevant log excerpts
    • What you’ve already tried
  3. Ask in Discussions: https://github.com/CorpusIQ/corpusiq-openai-sdk/discussions

Still Stuck?

See also:


Last Updated: January 2026
Help improve this guide: If you solved a problem not covered here, please contribute!