Error: Setup wizard reports Docker is not installed.
Solution: Install Docker Desktop:
Verify with: docker --version
Error: Setup wizard reports port 8001 is already in use.
Solution:
# Find what's using port 8001
lsof -i :8001
# Stop existing Piper Morgan instance
docker-compose down
Error: Setup wizard cannot connect to database.
Solution:
# Start database
docker-compose up -d db
# Wait 10 seconds
sleep 10
# Try setup again
python main.py setup
Error: Setup wizard rejects OpenAI API key.
Causes:
sk-)Solution:
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer YOUR_KEY"
Error: Setup wizard rejects Anthropic API key.
Solution:
sk-ant-Error: AttributeError: module 'asyncio' has no attribute 'timeout'
Cause: Python version < 3.11
Solution:
# Check Python version
python --version
# If < 3.11, install Python 3.11+
pyenv install 3.11.9
pyenv local 3.11.9
# Verify fix
python -c "import asyncio; asyncio.timeout(1.0); print('✅ Fixed')"
Error: Container tests fail with version errors
Solution:
# Rebuild with Python 3.11 base
docker-compose build --no-cache
docker-compose run app python --version # Verify 3.11+
Error: GitHub Actions fail with Python compatibility
Solution: Workflows updated to use Python 3.11 - clear cache and retry
# Check workflow configuration
cat .github/workflows/test.yml | grep "python-version"
# Should show: python-version: '3.11'
Problem: Virtual environment created with wrong Python version
Solution:
# Remove old virtual environment
rm -rf venv
# Create new with Python 3.11
python3.11 -m venv venv
source venv/bin/activate
# Verify version
python --version # Should show 3.11.x
Problem: Package installation fails with version conflicts
Solution:
# Deactivate and reactivate virtual environment
deactivate
source venv/bin/activate
# Upgrade pip
python -m pip install --upgrade pip
# Install dependencies
pip install -r requirements.txt
Problem: IDE not recognizing Python 3.11
Solution:
VS Code:
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)PyCharm:
./venv/bin/pythonProblem: Tests fail with Python compatibility warnings
Solution:
# Run with Python 3.11 specific checks
python -W error::DeprecationWarning -m pytest tests/
# Check for version-specific issues
python -c "import sys; print(f'Python {sys.version}')"
Problem: Async tests fail with timeout or context errors
Solution:
# Verify asyncio.timeout availability
python -c "import asyncio; asyncio.timeout(1.0); print('✅ asyncio.timeout available')"
# Run async tests with proper event loop
pytest tests/ -v --asyncio-mode=auto
Problem: Docker build fails with Python version errors
Solution:
# Check Dockerfile Python version
grep "FROM python" services/orchestration/Dockerfile
# Should show: FROM python:3.11-slim-buster
# Rebuild with no cache
docker-compose build --no-cache
Problem: Container fails to start or crashes
Solution:
# Check container logs
docker-compose logs app
# Verify container Python version
docker-compose exec app python --version
# Check container dependencies
docker-compose exec app python -c "import fastapi, sqlalchemy; print('✅ Dependencies OK')"
Problem: CI/CD workflows fail with Python version errors
Solution:
# Check workflow configuration
cat .github/workflows/test.yml | grep -A 5 -B 5 "python-version"
# Verify workflow syntax
python3 -c "import yaml; yaml.safe_load(open('.github/workflows/test.yml'))"
Problem: CI/CD cache causing version conflicts
Solution: Clear GitHub Actions cache or update cache keys
# Check cache configuration in workflows
- name: Cache Python dependencies
uses: actions/cache@v3
with:
key: $-pip-3.11-$
Problem: Async operations are slower than expected
Solution:
# Verify Python 3.11 performance features
python -c "
import asyncio
import time
async def test_performance():
start = time.time()
async with asyncio.timeout(1.0):
await asyncio.sleep(0.1)
print(f'Async operation took: {time.time() - start:.3f}s')
asyncio.run(test_performance())
"
Problem: High memory usage in async operations
Solution: Check for proper resource cleanup
# Ensure proper async context management
async def proper_resource_usage():
async with asyncio.timeout(5.0):
async with some_resource() as resource:
result = await resource.operation()
return result
python --versionpython -c "import asyncio; asyncio.timeout(1.0)"echo $VIRTUAL_ENVpip list | grep -E "(fastapi|sqlalchemy|pytest)"docker-compose exec app python --version#!/bin/bash
# validation.sh - Quick environment validation
echo "=== Environment Validation ==="
echo "Python version: $(python --version)"
echo "Virtual environment: $VIRTUAL_ENV"
python -c "import asyncio; asyncio.timeout(1.0); print('✅ asyncio.timeout available')"
python -c "import fastapi, sqlalchemy, pytest; print('✅ Key dependencies available')"
echo "=== Validation Complete ==="
Run this script regularly to ensure your environment is properly configured.
This guide addresses common issues encountered during Piper Morgan development and deployment. Issues are organized by category with step-by-step resolution procedures.
Symptoms:
docker-compose up -d failsResolution:
# Check for port conflicts
lsof -i :5432 # PostgreSQL
lsof -i :6379 # Redis
lsof -i :8000 # ChromaDB
# Stop conflicting services
brew services stop postgresql # If Homebrew PostgreSQL running
sudo systemctl stop redis # If system Redis running
# Clean up Docker state
docker-compose down --volumes
docker system prune -f
docker-compose up -d
# Verify services
docker-compose ps
Common Causes:
Symptoms:
ModuleNotFoundError for local servicesResolution:
# Ensure virtual environment activated
source venv/bin/activate
# Verify Python path includes project root
python -c "import sys; print('\n'.join(sys.path))"
# Reinstall dependencies
pip install -r requirements.txt
# Add project root to PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
# Verify imports work
python -c "from services.domain.models import Project; print('OK')"
Symptoms:
None values for API keysResolution:
# Check .env file exists and is readable
ls -la .env
cat .env | grep -v "^#" | head -5 # Don't expose keys
# Verify load_dotenv() calls
grep -r "load_dotenv" services/
# Test environment loading
python -c "
from dotenv import load_dotenv
import os
load_dotenv()
print('ANTHROPIC_API_KEY set:', bool(os.getenv('ANTHROPIC_API_KEY')))
"
Critical Fix Pattern:
# Always add at top of modules using os.getenv()
from dotenv import load_dotenv
load_dotenv() # BEFORE any os.getenv() calls
import os
api_key = os.getenv('ANTHROPIC_API_KEY')
Symptoms:
Diagnosis:
# Check LLM service status
curl -X POST http://localhost:8001/api/v1/intent \
-H "Content-Type: application/json" \
-d '{"message": "test classification"}'
# Enable debug logging
export LOG_LEVEL=DEBUG
Resolution:
Symptoms:
sqlalchemy.exc.OperationalErrorResolution:
# Check PostgreSQL container
docker logs piper-postgres
# Test database connection
python -c "
import asyncio
from sqlalchemy.ext.asyncio import create_async_engine
async def test():
engine = create_async_engine('postgresql+asyncpg://piper:dev_changeme@localhost/piper_morgan')
async with engine.begin() as conn:
result = await conn.execute('SELECT 1')
print('DB connection OK:', result.scalar())
await engine.dispose()
asyncio.run(test())
"
# Initialize database schema
python -c "
import asyncio
from services.database.session import init_database
asyncio.run(init_database())
"
Symptoms:
Diagnosis:
# Check ChromaDB status
curl http://localhost:8000/api/v1/version
# Verify document ingestion
python -c "
import chromadb
client = chromadb.HttpClient(host='localhost', port=8000)
collection = client.get_collection('pm_knowledge')
print('Document count:', collection.count())
"
Resolution:
Symptoms:
Diagnosis:
# Check FastAPI startup logs
docker logs piper-api # If containerized
# OR
python main.py # Direct startup
# Verify routes registered
curl http://localhost:8001/docs # OpenAPI docs
Common Causes:
Symptoms:
Resolution:
# Test with valid request format
curl -X POST http://localhost:8001/api/v1/intent \
-H "Content-Type: application/json" \
-d '{
"message": "Create a ticket for login bug",
"session_id": "test-123"
}'
# Check API documentation
open http://localhost:8001/docs
Symptoms:
Diagnosis:
# Check application logs
tail -f logs/app.log
# Enable detailed error tracking
export LOG_LEVEL=DEBUG
export SHOW_ERROR_DETAILS=true
Common Causes:
Symptoms:
RuntimeError: This event loop is already runningResolution:
# Ensure proper async test setup
import pytest
@pytest.mark.asyncio
async def test_async_function():
result = await async_function()
assert result is not None
# Configure pytest.ini
[tool.pytest.ini_options]
asyncio_mode = "auto"
Symptoms:
Resolution:
# Use isolated test database
@pytest.fixture
async def test_db():
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield engine
await engine.dispose()
Symptoms:
Resolution:
# Proper mock setup
from unittest.mock import Mock, AsyncMock
@pytest.fixture
def mock_llm_client():
client = Mock()
client.complete = AsyncMock(return_value="test response")
return client
# Verify mock calls
def test_with_mock(mock_llm_client):
# ... test code ...
mock_llm_client.complete.assert_called_once()
Symptoms:
Diagnosis:
# Profile API performance
time curl -X POST http://localhost:8001/api/v1/intent \
-H "Content-Type: application/json" \
-d '{"message": "list projects"}'
# Check database query performance
export LOG_LEVEL=DEBUG # Shows SQL queries
Optimization Steps:
Symptoms:
Monitoring:
# Monitor container memory
docker stats
# Python memory profiling
pip install memory-profiler
python -m memory_profiler your_script.py
Symptoms:
Best Practices:
# Create feature branch
git checkout -b feature/pm-XXX-description
# Regular commits with clear messages
git commit -m "PM-009: Add project context resolution
- Implement ProjectContext class
- Add session memory for project tracking
- Update workflow factory integration"
# Sync with main regularly
git fetch origin
git rebase origin/main
Symptoms:
Prevention:
# Pre-commit checks
grep -r "create.*workflow" services/ # Check patterns
mypy services/ # Type checking
pytest # All tests pass
import structlog
logger = structlog.get_logger()
# Add context to all log entries
logger.info(
"processing_intent",
intent_id=intent.id,
category=intent.category.value,
confidence=intent.confidence,
user_id=session_id
)
# Drop into debugger on errors
import pdb; pdb.set_trace()
# Or use ipdb for better interface
import ipdb; ipdb.set_trace()
# VS Code debugging
# Set breakpoints in IDE and run with debugger
# System health
curl http://localhost:8001/api/v1/health
# Individual service checks
curl http://localhost:8000/api/v1/version # ChromaDB
curl http://localhost:8088/ # Temporal UI
# Nuclear option - reset everything
docker-compose down --volumes
docker system prune -a -f
rm -rf data/ # Clears all persistent data
docker-compose up -d
# Reinitialize
python -c "
import asyncio
from services.database.session import init_database
asyncio.run(init_database())
"
# Re-upload knowledge base
python scripts/upload_docs.py # If exists
# Backup before major changes
docker exec piper-postgres pg_dump -U piper piper_morgan > backup.sql
# Restore from backup
docker exec -i piper-postgres psql -U piper piper_morgan < backup.sql
Check these locations:
logs/app.logdocker-compose logs [service]/var/log/ (production)# Service status overview
docker-compose ps
# Resource usage
docker stats --no-stream
# Network connectivity
docker-compose exec api ping postgres
# Database inspection
docker-compose exec postgres psql -U piper -d piper_morgan -c "\dt"
# Weekly cleanup
docker system prune -f
docker-compose pull # Update images
# Monthly tasks
pip list --outdated # Check for updates
brew update && brew upgrade # Update system tools
# Add health checks to critical services
@app.get("/health")
async def health_check():
return {
"status": "healthy",
"timestamp": datetime.now(),
"services": {
"database": await check_database(),
"chromadb": await check_chromadb(),
"redis": await check_redis()
}
}
Last Updated: June 21, 2025