v2/docs/AUTOMATIC_ERROR_RECOVERY_v2.7.35.md
Implemented comprehensive automatic error recovery system for claude-flow init that handles the WSL better-sqlite3 ENOTEMPTY error without manual intervention.
src/utils/error-recovery.ts)Features:
Key Functions:
- isNpmCacheError(error): boolean
- isWSL(): boolean
- cleanNpmCache(): Promise<RecoveryResult>
- retryWithRecovery<T>(fn, options): Promise<T>
- recoverWSLErrors(): Promise<RecoveryResult>
- recoverInitErrors(error): Promise<RecoveryResult>
src/core/DatabaseManager.ts)Improvements:
initializeSQLiteWithRecovery() methodFlow:
Try SQLite → Error? → Warn + Fallback to JSON
Initialize → Error? → Retry with JSON (3x max)
src/cli/init/index.ts)Enhanced with:
retryWithRecovery()--force flag (5 attempts vs 3)User Experience:
npx claude-flow@alpha init --force
🔍 WSL environment detected
✅ WSL environment optimized
⚠️ Detected npm cache error (attempt 1/5)
🧹 Cleaning npm cache...
✅ Cache cleaned, retrying...
🔄 Retry attempt 1 after error recovery...
🎉 Project initialized successfully!
tests/unit/utils/error-recovery.test.ts)Tests:
Created/Updated:
docs/features/automatic-error-recovery.md - Comprehensive guidedocs/troubleshooting/wsl-better-sqlite3-error.md - Updated with auto-recovery infodocs/AUTOMATIC_ERROR_RECOVERY_v2.7.35.md - This document$ npx claude-flow@alpha init --force
[Error: ENOTEMPTY: directory not empty, rmdir '/home/user/.npm/_npx/xxx/node_modules/better-sqlite3']
# User had to manually:
$ npm cache clean --force
$ rm -rf ~/.npm/_npx
$ npx claude-flow@alpha init --force # Try again
$ npx claude-flow@alpha init --force
🔍 WSL environment detected
✅ WSL environment optimized
📁 Phase 1: Creating directory structure...
⚠️ Detected npm cache error (attempt 1/5)
🧹 Cleaning npm cache...
✅ npm cache cleaned
🗑️ Removing npx cache: /home/user/.npm/_npx
✅ npx cache removed
✅ Cache cleaned, retrying...
🔄 Retry attempt 1 after error recovery...
📁 Phase 1: Creating directory structure...
🎉 Project initialized successfully!
# No manual intervention needed!
if (isNpmCacheError(error)) {
1. Run `npm cache clean --force`
2. Remove `~/.npm/_npx` directory
3. Fix permissions (WSL: `chmod -R 755 ~/.npm`)
4. Retry with exponential backoff
}
if (isWSL()) {
1. Detect running from `/mnt/c/` (Windows mount) → Warn user
2. Check for build tools (gcc, python3) → Suggest install
3. Apply permission fixes
4. Clean cache with WSL-specific handling
}
if (sqliteInitFails) {
1. Try SQLite with recovery
2. On error → Warn user
3. Fallback to JSON provider
4. Retry initialization (3x max)
5. Success → Continue with JSON storage
}
if (!better-sqlite3Available) {
1. Attempt reinstall with retry
2. Clean cache before each retry
3. Verify installation after each attempt
4. Max 3 retries with exponential backoff
5. Fallback to JSON if all fail
}
interface RetryOptions {
maxRetries?: number; // 3 (normal) or 5 (--force)
delay?: number; // 1000ms initial delay
onRetry?: (attempt, error) => void;
cleanupFn?: () => Promise<void>;
}
interface RecoveryResult {
success: boolean; // Recovery succeeded?
action: string; // Action taken
message: string; // User-friendly message
recovered: boolean; // Was recovery needed?
}
/mnt/c/ (Windows filesystem)~/ (WSL filesystem)--force flag--force flagFROM ubuntu:22.04
# Install Node.js and build tools
RUN apt-get update && apt-get install -y \
curl \
build-essential \
python3 \
git
# Install Node.js 20
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs
# Create test user
RUN useradd -m -s /bin/bash testuser
USER testuser
WORKDIR /home/testuser
# Test command
CMD npx claude-flow@alpha init --force
# Build test image
docker build -t claude-flow-test -f Dockerfile.test .
# Run test
docker run -it claude-flow-test
# Test with volume mount
docker run -it -v $(pwd):/workspace -w /workspace claude-flow-test
# Simulate WSL environment
docker run -it -e SIMULATE_WSL=1 claude-flow-test
// Recovery success rate
const recoveryMetrics = {
totalErrors: 0,
recoveredErrors: 0,
successRate: 0,
avgRetries: 0,
cacheCleanups: 0,
wslOptimizations: 0,
sqliteToJsonFallbacks: 0
};
Closes:
Status: ✅ Implementation Complete - Ready for Testing Next: Docker validation and beta release