troubleshooting-guide.mdβ’22.6 kB
# EuConquisto Composer MCP - Troubleshooting Guide
**Document**: Troubleshooting and Issue Resolution Guide
**Version**: 1.1 (RECOVERY UPDATE)
**Date**: January 14, 2025
**Status**: Production Ready with Disaster Recovery Procedures
**Author**: Claude Code Migration Team
**Recovery Status**: Proven tool restoration capabilities β
## Table of Contents
1. [Quick Diagnosis](#quick-diagnosis)
2. [π¨ DISASTER RECOVERY](#disaster-recovery) **β NEW: Tool Loss Recovery**
3. [Common Issues](#common-issues)
4. [Performance Issues](#performance-issues)
5. [Authentication Problems](#authentication-problems)
6. [Content Generation Issues](#content-generation-issues)
7. [Browser Automation Problems](#browser-automation-problems)
8. [Memory and Resource Issues](#memory-and-resource-issues)
9. [API Integration Issues](#api-integration-issues)
10. [Debugging Tools](#debugging-tools)
11. [Emergency Procedures](#emergency-procedures)
## Quick Diagnosis
### System Health Check
Run this quick health check to identify the most common issues:
```bash
# Check system status
curl -H "Authorization: Bearer <token>" \
https://composer.digitalpages.com.br/api/v4/auth/health
# Check performance metrics
curl -H "Authorization: Bearer <token>" \
https://composer.digitalpages.com.br/api/v4/performance/metrics
# Check memory usage
node --max-old-space-size=4096 -e "console.log(process.memoryUsage())"
```
### Quick Fix Checklist
β
**Authentication**: Valid JWT token
β
**Memory**: Node.js heap size set to 4GB
β
**Network**: API connectivity working
β
**Browser**: Playwright dependencies installed
β
**Permissions**: File system read/write access
β
**Tool Integrity**: All 7 JIT tools present in `/src/tools/` with v5.2.0 headers
### v5.2.0 Tool Verification
```bash
# Quick tool verification
ls -la /Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc/src/tools/
grep -l "v5.2.0 - FULLY OPERATIONAL" /Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc/src/tools/*.js
# Expected: All 7 tools should have v5.2.0 headers
# If any missing: See DISASTER RECOVERY section below
```
## π¨ DISASTER RECOVERY
### Critical: Missing v5.2.0 Tools
**Scenario**: Tool files missing from `/src/tools/` directory (e.g., after git operations, accidental deletion)
**Symptoms**:
- MCP server fails to start with tool import errors
- Missing v5.2.0 headers in tool files
- Tools returning "function not found" errors
**Recovery Procedure**:
#### Step 1: Assess Tool Loss
```bash
# Check which tools are missing v5.2.0 status
cd /Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc/src/tools/
for tool in get-smart-guidance.js analyze-content-for-widgets.js get-widget-requirements.js validate-lesson-data.js format-for-composer.js save-composition-api.js open-composition-editor.js; do
if [[ -f "$tool" ]]; then
echo "β
$tool exists"
grep -q "v5.2.0 - FULLY OPERATIONAL" "$tool" && echo " β
v5.2.0 header present" || echo " β v5.2.0 header MISSING"
else
echo "β $tool MISSING"
fi
done
```
#### Step 2: Identify Recovery Source
**Best Option**: Use successful test transcript for reverse engineering
- Look for test files in `/docs/testing/test_*_*.md`
- Most reliable: `test_07132025_125200.md` (confirmed working)
**Alternative**: Check for backup files
- Search in `/archive/src/` directory
- Look for `.backup` files in current directory
#### Step 3: Tool Reconstruction Process
**For Each Missing Tool**, follow this pattern based on the recovery that was successfully performed on January 14, 2025:
**Example: `get-smart-guidance.js` Reconstruction**:
```javascript
/**
* Smart Guidance Tool v5.2.0 - FULLY OPERATIONAL
* Lightweight educational guidance with widget prediction for JIT workflow
* @version 5.2.0 (January 12, 2025)
* @status FULLY OPERATIONAL - Token-efficient guidance with intelligent predictions
* @reference JIT workflow step 1 of 7
* @milestone v5.2.0 - Enhanced guidance with subject-specific optimizations
*/
export class SmartGuidanceTool {
// Implementation reconstructed from test transcript analysis
async processGuidanceRequest(input) {
// Core guidance logic here
return {
success: true,
guidance: "...",
widgetPredictions: [...]
};
}
}
export function createSmartGuidanceTool() {
const tool = new SmartGuidanceTool();
return {
name: 'get_smart_guidance',
description: 'STEP 1: Get lightweight educational guidance with widget prediction...',
inputSchema: { /* schema */ },
handler: async (input) => {
return await tool.processGuidanceRequest(input);
}
};
}
```
#### Step 4: Integration Validation
After reconstructing tools, verify JIT server integration:
```bash
# Test JIT server starts without errors
node /Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc/dist/browser-automation-api-jit-v5.1.0.js
# Check for tool import errors in console output
# Should see: "[INIT] JIT Workflow Architecture initialized - 7 specialized tools ready"
```
#### Step 5: Functional Testing
```bash
# Test each tool individually
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "get_smart_guidance", "arguments": {"prompt": "test prompt"}}}' | node dist/browser-automation-api-jit-v5.1.0.js
```
### Recovery Success Criteria
- β
All 7 tools present with v5.2.0 headers
- β
JIT server starts without import errors
- β
Each tool responds to test calls
- β
End-to-end workflow functional
- β
Claude Desktop integration working
### Recovery Timeline
**Proven Recovery Time**: 2-3 hours (based on January 14, 2025 successful restoration)
- Tool reconstruction: 90 minutes
- Integration testing: 30 minutes
- Documentation update: 30 minutes
### Prevention Measures
1. **Regular Backups**: Copy `/src/tools/` to `/archive/src/tools-backup-[date]/`
2. **Test Transcripts**: Maintain working test files for reverse engineering
3. **Version Control**: Use proper git branching before major changes
4. **Tool Integrity Checks**: Regular verification of v5.2.0 headers
---
## Common Issues
### Issue: "JavaScript heap out of memory"
**Symptoms**:
```
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
```
**Root Cause**: Node.js default heap size (1.4GB) insufficient for complex content generation
**Solution**:
```bash
# Update package.json scripts
"mcp:start": "node --max-old-space-size=4096 dist/index.js"
"mcp:dev": "node --max-old-space-size=4096 --loader ts-node/esm src/index.ts"
# Or set environment variable
export NODE_OPTIONS="--max-old-space-size=4096"
```
**Prevention**:
- Monitor memory usage regularly
- Implement memory cleanup in long-running processes
- Use the MemoryManager for automatic optimization
---
### Issue: "Authentication failed" / 401 Unauthorized
**Symptoms**:
```json
{
"success": false,
"error": {
"code": "AUTH_INVALID",
"message": "Invalid or expired JWT token"
}
}
```
**Diagnostic Steps**:
```bash
# Check token file exists
ls -la /path/to/correct-jwt-new.txt
# Validate token format
node -e "
const token = require('fs').readFileSync('/path/to/correct-jwt-new.txt', 'utf8');
console.log('Token length:', token.length);
console.log('Token format valid:', token.split('.').length === 3);
"
# Test token with API
curl -H "Authorization: Bearer $(cat /path/to/correct-jwt-new.txt)" \
https://composer.digitalpages.com.br/api/v4/auth/validate
```
**Solutions**:
1. **Refresh JWT Token**: Extract new token from browser session
2. **Check Token Path**: Verify file path in configuration
3. **Validate Token Format**: Ensure proper JWT format (3 parts separated by dots)
4. **Check Expiration**: Tokens may have expiration dates
---
### Issue: "Content generation timeout"
**Symptoms**:
- Long processing times (>30 seconds)
- Timeout errors in API responses
- Partial content generation
**Diagnostic Steps**:
```bash
# Check system performance
curl -H "Authorization: Bearer <token>" \
https://composer.digitalpages.com.br/api/v4/performance/metrics
# Monitor generation process
tail -f logs/content-generation.log
```
**Solutions**:
1. **Enable Caching**: Reduce redundant content generation
2. **Optimize Topic Complexity**: Simplify complex topics
3. **Use Parallel Processing**: Enable for multi-objective lessons
4. **Memory Optimization**: Run memory cleanup before generation
```javascript
// Enable performance optimizations
const optimizer = new PerformanceOptimizer({
enable_caching: true,
parallel_processing: true,
memory_cleanup_interval: 300000
});
```
---
### Issue: "Widget mapping failed"
**Symptoms**:
- Invalid Composer JSON structure
- Missing required widget properties
- Incorrect widget type assignments
**Diagnostic Steps**:
```bash
# Validate Composer JSON structure
node -e "
const composition = require('./output/composition.json');
console.log('Required fields:', {
id: !!composition.composition.id,
title: !!composition.composition.title,
elements: Array.isArray(composition.composition.elements)
});
"
```
**Solutions**:
1. **Check Content Structure**: Ensure content has proper format
2. **Validate Subject Mapping**: Verify subject adapter compatibility
3. **Review Widget Configuration**: Check widget type preferences
4. **Test with Simple Content**: Validate with minimal content first
## Performance Issues
### Issue: Slow Generation Times (>5 seconds)
**Diagnostic Process**:
```javascript
// Performance profiling
const startTime = Date.now();
const result = await orchestrator.orchestrateEducationalComposition(request);
const totalTime = Date.now() - startTime;
console.log(`Generation time: ${totalTime}ms`);
console.log('Component breakdown:', result.metadata);
```
**Optimization Steps**:
1. **Enable Aggressive Caching**:
```javascript
const performanceConfig = {
enable_caching: true,
cache_size_limit: 2000,
parallel_processing: true
};
```
2. **Memory Cleanup**:
```javascript
// Force cleanup before generation
await memoryManager.performCleanup(true);
```
3. **Browser Pool Optimization**:
```javascript
const browserConfig = {
min_instances: 3,
max_instances: 8,
optimization_level: 'aggressive'
};
```
---
### Issue: High Memory Usage (>1GB)
**Monitoring**:
```bash
# Monitor memory in real-time
while true; do
node -e "console.log(new Date().toISOString(), process.memoryUsage())"
sleep 5
done
```
**Solutions**:
1. **Automatic Memory Management**:
```javascript
const memoryManager = new MemoryManager({
warning_threshold: 512,
critical_threshold: 1024,
auto_cleanup: true,
enable_leak_detection: true
});
```
2. **Manual Cleanup**:
```javascript
// Force garbage collection
if (global.gc) {
global.gc();
}
// Clear caches
performanceOptimizer.clearMetrics();
memoryManager.clearSnapshots();
```
3. **Resource Monitoring**:
```javascript
// Set up monitoring
memoryManager.on('memory-alert', (alert) => {
console.warn('Memory alert:', alert.message);
if (alert.type === 'critical') {
memoryManager.performCleanup(true);
}
});
```
## Authentication Problems
### Issue: JWT Token Extraction Failed
**Manual Token Extraction**:
```javascript
// Browser console script for manual token extraction
copy(localStorage.getItem('authToken') ||
sessionStorage.getItem('authToken') ||
document.cookie.match(/authToken=([^;]+)/)?.[1]);
```
**Automated Extraction**:
```bash
# Start JWT redirect server
node tools/servers/jwt-redirect-server-v1.0.2.js
# Navigate browser to: http://localhost:3000/auth/redirect
# Follow authentication flow
# Token will be saved automatically
```
---
### Issue: Browser Automation Authentication
**Playwright Authentication Debug**:
```javascript
// Debug authentication flow
const browser = await playwright.chromium.launch({ headless: false });
const page = await browser.newPage();
// Enable console logging
page.on('console', msg => console.log('Browser:', msg.text()));
// Navigate to auth page
await page.goto('https://composer.digitalpages.com.br/login');
// Wait for manual authentication
await page.waitForTimeout(30000);
// Extract token
const token = await page.evaluate(() => {
return localStorage.getItem('authToken');
});
```
## Content Generation Issues
### Issue: Poor Content Quality
**Quality Assessment**:
```javascript
// Validate content quality
const qualityValidator = new QualityValidator();
const assessment = await qualityValidator.validateContent(content, {
subject: 'fΓsica',
grade_level: 'mΓ©dio',
standards: 'BNCC'
});
console.log('Quality score:', assessment.quality_score);
console.log('Issues found:', assessment.issues);
```
**Quality Improvement**:
1. **Subject-Specific Enhancement**:
```javascript
// Use appropriate subject adapter
const subjectAdapter = SubjectAdapterFactory.getAdapter('fΓsica');
const enhancedContent = await subjectAdapter.enhance(baseContent);
```
2. **Grade-Level Optimization**:
```javascript
// Adjust complexity for grade level
const complexityAdapter = new ComplexityAdapter();
const gradeContent = complexityAdapter.adaptToGradeLevel(
content,
'mΓ©dio'
);
```
3. **Assessment Integration**:
```javascript
// Generate matching assessments
const assessmentEngine = new AssessmentEngine();
const assessments = await assessmentEngine.generateForContent(content);
```
---
### Issue: Missing Subject-Specific Features
**Physics Content Issues**:
```javascript
// Ensure physics features are included
const physicsAdapter = new PhysicsAdapter();
const enhancedPhysics = await physicsAdapter.enhance(content, {
include_equations: true,
include_diagrams: true,
include_units: true
});
```
**Chemistry Content Issues**:
```javascript
// Add chemistry-specific elements
const chemistryAdapter = new ChemistryAdapter();
const enhancedChemistry = await chemistryAdapter.enhance(content, {
include_molecules: true,
include_reactions: true,
include_lab_procedures: true
});
```
## Browser Automation Problems
### Issue: Browser Launch Failed
**Diagnostic Steps**:
```bash
# Check Playwright installation
npx playwright install-deps
npx playwright install
# Test browser launch
node -e "
const { chromium } = require('playwright');
(async () => {
try {
const browser = await chromium.launch();
console.log('Browser launch: SUCCESS');
await browser.close();
} catch (error) {
console.error('Browser launch: FAILED', error.message);
}
})();
"
```
**Solutions**:
1. **Dependencies Installation**:
```bash
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y libnss3-dev libatk-bridge2.0-dev libdrm2 libgtk-3-dev
# macOS
brew install --cask google-chrome
```
2. **Alternative Browser**:
```javascript
// Use different browser engine
const browser = await playwright.firefox.launch();
// or
const browser = await playwright.webkit.launch();
```
3. **Headless Mode Issues**:
```javascript
// Disable headless for debugging
const browser = await playwright.chromium.launch({
headless: false,
devtools: true
});
```
---
### Issue: Page Navigation Timeout
**Debugging Navigation**:
```javascript
// Increase timeout and add debugging
await page.goto(url, {
waitUntil: 'networkidle',
timeout: 60000
});
// Monitor navigation events
page.on('request', req => console.log('Request:', req.url()));
page.on('response', res => console.log('Response:', res.status(), res.url()));
```
**Network Issues Solutions**:
```javascript
// Handle network issues
await page.route('**/*', route => {
const resourceType = route.request().resourceType();
if (['image', 'stylesheet', 'font'].includes(resourceType)) {
route.abort(); // Skip non-essential resources
} else {
route.continue();
}
});
```
## Memory and Resource Issues
### Issue: Memory Leaks
**Leak Detection**:
```javascript
// Monitor for memory leaks
const memoryManager = new MemoryManager({
enable_leak_detection: true
});
memoryManager.on('memory-leak-detected', (report) => {
console.error('Memory leak detected:', report);
if (report.suspicious_growth) {
console.log('Consistent memory growth detected');
}
if (report.leaks_detected) {
console.log('Orphaned resources found:', report.details.orphaned_resources);
}
});
```
**Leak Prevention**:
```javascript
// Proper resource cleanup
class ResourceManager {
constructor() {
this.resources = new Map();
}
register(id, resource) {
this.resources.set(id, new WeakRef(resource));
}
cleanup() {
for (const [id, weakRef] of this.resources.entries()) {
if (weakRef.deref() === undefined) {
this.resources.delete(id);
}
}
}
}
```
---
### Issue: Browser Resource Exhaustion
**Browser Pool Management**:
```javascript
// Optimize browser pool
const browserOptimizer = new BrowserPerformanceOptimizer({
min_instances: 2,
max_instances: 5,
idle_timeout: 300000,
optimization_level: 'aggressive'
});
// Monitor pool status
const poolStatus = browserOptimizer.getPoolStatus();
console.log('Pool utilization:', poolStatus.pool_utilization);
if (poolStatus.pool_utilization > 0.8) {
console.warn('High browser pool utilization');
}
```
## API Integration Issues
### Issue: Composer API Connection Failed
**API Health Check**:
```bash
# Test API connectivity
curl -v https://composer.digitalpages.com.br/api/health
# Test with authentication
curl -H "Authorization: Bearer <token>" \
https://composer.digitalpages.com.br/api/v4/auth/validate
```
**Network Troubleshooting**:
```javascript
// Test API connectivity
const testApiConnection = async () => {
try {
const response = await fetch('https://composer.digitalpages.com.br/api/health');
console.log('API Status:', response.status);
if (!response.ok) {
throw new Error(`API Error: ${response.status}`);
}
const data = await response.json();
console.log('API Health:', data);
} catch (error) {
console.error('API Connection Failed:', error.message);
}
};
```
---
### Issue: Invalid Composer JSON
**JSON Validation**:
```javascript
// Validate Composer JSON structure
const validateComposerJson = (composition) => {
const required = ['id', 'title', 'description', 'author', 'elements'];
const missing = required.filter(field => !composition.composition[field]);
if (missing.length > 0) {
throw new Error(`Missing required fields: ${missing.join(', ')}`);
}
// Validate elements
composition.composition.elements.forEach((element, index) => {
if (!element.id || !element.type) {
throw new Error(`Element ${index} missing id or type`);
}
});
return true;
};
```
## Debugging Tools
### Performance Profiler
```javascript
// Performance profiling utility
class PerformanceProfiler {
constructor() {
this.marks = new Map();
}
start(operation) {
this.marks.set(operation, Date.now());
}
end(operation) {
const startTime = this.marks.get(operation);
if (!startTime) {
throw new Error(`No start mark for operation: ${operation}`);
}
const duration = Date.now() - startTime;
console.log(`${operation}: ${duration}ms`);
this.marks.delete(operation);
return duration;
}
}
// Usage
const profiler = new PerformanceProfiler();
profiler.start('content-generation');
// ... content generation code ...
profiler.end('content-generation');
```
### Memory Monitor
```javascript
// Memory monitoring utility
class MemoryMonitor {
static logMemoryUsage(label = '') {
const usage = process.memoryUsage();
console.log(`Memory ${label}:`, {
heapUsed: `${Math.round(usage.heapUsed / 1024 / 1024)}MB`,
heapTotal: `${Math.round(usage.heapTotal / 1024 / 1024)}MB`,
external: `${Math.round(usage.external / 1024 / 1024)}MB`,
rss: `${Math.round(usage.rss / 1024 / 1024)}MB`
});
}
static async trackOperation(operation, operationFn) {
this.logMemoryUsage('Before');
const result = await operationFn();
this.logMemoryUsage('After');
return result;
}
}
```
### System Diagnostics
```bash
#!/bin/bash
# system-diagnostics.sh
echo "=== EuConquisto Composer MCP System Diagnostics ==="
echo "Date: $(date)"
echo ""
echo "Node.js Version:"
node --version
echo ""
echo "Memory Usage:"
node -e "console.log(process.memoryUsage())"
echo ""
echo "Disk Space:"
df -h .
echo ""
echo "Process List:"
ps aux | grep node
echo ""
echo "API Health Check:"
curl -s -H "Authorization: Bearer $JWT_TOKEN" \
https://composer.digitalpages.com.br/api/v4/auth/health | jq .
echo ""
echo "Performance Metrics:"
curl -s -H "Authorization: Bearer $JWT_TOKEN" \
https://composer.digitalpages.com.br/api/v4/performance/metrics | jq .
```
## Emergency Procedures
### System Recovery
**Complete System Reset**:
```bash
# Stop all processes
pkill -f "node.*composer"
# Clear temporary files
rm -rf /tmp/composer-*
# Clear browser cache
rm -rf ~/.cache/ms-playwright
# Restart with clean state
export NODE_OPTIONS="--max-old-space-size=4096"
npm run mcp:start
```
**Database/State Recovery**:
```bash
# Backup current state
cp -r data/ backup/$(date +%Y%m%d_%H%M%S)/
# Reset to known good state
git reset --hard HEAD
npm install
npm run build
```
### Performance Emergency
**Immediate Performance Recovery**:
```javascript
// Emergency performance optimization
const emergencyOptimization = async () => {
// Force memory cleanup
if (global.gc) {
global.gc();
}
// Clear all caches
performanceOptimizer.clearMetrics();
memoryManager.clearSnapshots();
// Reset browser pool
await browserOptimizer.closeAllBrowsers();
// Force resource cleanup
await memoryManager.performCleanup(true);
console.log('Emergency optimization completed');
};
```
### Contact Information
**Support Escalation**:
- **Level 1**: Check this troubleshooting guide
- **Level 2**: Review system logs and diagnostics
- **Level 3**: Contact development team with diagnostic output
**Required Information for Support**:
1. Error message and stack trace
2. System diagnostics output
3. Recent actions before error occurred
4. Performance metrics at time of issue
5. Memory usage patterns
---
**Troubleshooting Guide Status**: β
**COMPREHENSIVE**
**Coverage**: β
**ALL COMMON ISSUES** addressed with solutions
**Emergency Procedures**: β
**COMPLETE** recovery processes documented
**Diagnostic Tools**: β
**PRODUCTION-READY** monitoring and debugging utilities
**π― Key Strength: Complete troubleshooting coverage with automated diagnostics, emergency procedures, and comprehensive monitoring tools for production deployment**