Merge pull request #189 from ruvnet/fix/logger-memory-usage

fix: add workarounds for ruv-swarm v1.0.8 logger error
This commit is contained in:
rUv authored and GitHub committed 2025-07-09 15:12:44 -04:00
commit 5e2db27b4e
8 files changed
+368 -3

No files matched your search

+12
View File
@@ -822,6 +822,18 @@ npx --y claude-flow@alpha init --force
---
## Star History
<a href="https://www.star-history.com/#ruvnet/claude-flow&Date">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=ruvnet/claude-flow&type=Date&theme=dark" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=ruvnet/claude-flow&type=Date" />
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ruvnet/claude-flow&type=Date" />
</picture>
</a>
---
**Built with ❤️ by [rUv](https://github.com/ruvnet) | Powered by Revolutionary AI**
*v2.0.0 Alpha - The Future of AI Orchestration*
+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/sh
# Claude-Flow Smart Dispatcher - Detects and uses the best available runtime
VERSION="2.0.0-alpha.27"
VERSION="2.0.0-alpha.37"
# Determine the correct path based on how the script is invoked
if [ -L "$0" ]; then
+29
View File
@@ -0,0 +1,29 @@
FROM node:20-alpine
# Install necessary packages
RUN apk add --no-cache git bash
# Create test directory
WORKDIR /test
# Copy package.json to test npm install
COPY package.json .
# Test installing the alpha version
RUN npm install -g claude-flow@2.0.0-alpha.37
# Test the wrapper script
COPY scripts/ruv-swarm-safe.js /usr/local/lib/node_modules/claude-flow/scripts/
# Create a test script
RUN echo '#!/bin/bash\n\
echo "Testing claude-flow MCP server..."\n\
claude-flow mcp start &\n\
sleep 5\n\
echo "MCP server test completed"\n\
pkill -f "claude-flow mcp"\n\
echo "\nTesting ruv-swarm safe wrapper..."\n\
timeout 10s node /usr/local/lib/node_modules/claude-flow/scripts/ruv-swarm-safe.js || true\n\
echo "\nAll tests completed"' > test.sh && chmod +x test.sh
CMD ["./test.sh"]
+48
View File
@@ -0,0 +1,48 @@
# Known Issues
## ruv-swarm v1.0.8 Logger Error
### Issue
When running `npx ruv-swarm mcp start`, you may encounter:
```
❌ Uncaught Exception: logger.logMemoryUsage is not a function
```
### Impact
- The error occurs after successful initialization
- The MCP server continues to work despite the error
- This is a non-critical error that doesn't affect functionality
### Workaround
Use claude-flow's integrated MCP server instead:
```bash
# Option 1: Use claude-flow MCP server (recommended)
npx claude-flow@alpha mcp start
# Option 2: Configure claude-flow with MCP integration
claude mcp add claude-flow npx claude-flow@alpha mcp start
```
### Fix Status
- **Affected Version**: ruv-swarm v1.0.8
- **Status**: Known issue in external package
- **Claude-Flow**: Provides integrated MCP server as alternative
### Technical Details
The error occurs because ruv-swarm attempts to call `logger.logMemoryUsage()` in a monitoring interval, but the method isn't properly bound to the logger instance in certain contexts.
## Anthropic API 500 Errors
### Issue
When Anthropic's API experiences issues, you may see:
```
API Error: 500 {"type":"error","error":{"type":"api_error","message":"Internal server error"}}
```
### Workaround
1. Check https://status.anthropic.com/ for service status
2. Use `--claude` flag to generate commands without API calls
3. Use `--executor` for local execution
See issue #183 for more details.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "claude-flow",
"version": "2.0.0-alpha.36",
"version": "2.0.0-alpha.37",
"description": "Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)",
"main": "cli.mjs",
"bin": {
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env node
/**
* Safe wrapper for ruv-swarm MCP server
* Handles known logger issue in v1.0.8
*/
import { spawn } from 'child_process';
import { createInterface } from 'readline';
console.log('🚀 Starting ruv-swarm MCP server with error handling...');
const ruvSwarmProcess = spawn('npx', ['ruv-swarm', 'mcp', 'start'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
MCP_MODE: 'stdio',
LOG_LEVEL: 'WARN'
}
});
// Forward stdin to ruv-swarm
process.stdin.pipe(ruvSwarmProcess.stdin);
// Handle stdout (JSON-RPC messages)
ruvSwarmProcess.stdout.pipe(process.stdout);
// Handle stderr with filtering
const rlErr = createInterface({
input: ruvSwarmProcess.stderr,
crlfDelay: Infinity
});
let errorHandled = false;
rlErr.on('line', (line) => {
// Filter out the known logger error
if (line.includes('logger.logMemoryUsage is not a function')) {
if (!errorHandled) {
console.error('⚠️ Known ruv-swarm v1.0.8 logger issue detected - continuing normally');
console.error('💡 This error does not affect functionality');
errorHandled = true;
}
return;
}
// Forward other stderr output
process.stderr.write(line + '\n');
});
// Handle process exit
ruvSwarmProcess.on('exit', (code, signal) => {
if (code !== null && code !== 0) {
console.error(`\n❌ ruv-swarm exited with code ${code}`);
console.error('💡 Try using: npx claude-flow@alpha mcp start');
}
process.exit(code || 0);
});
// Handle errors
ruvSwarmProcess.on('error', (error) => {
console.error('❌ Failed to start ruv-swarm:', error.message);
console.error('💡 Try using: npx claude-flow@alpha mcp start');
process.exit(1);
});
// Handle termination signals
process.on('SIGTERM', () => {
ruvSwarmProcess.kill('SIGTERM');
});
process.on('SIGINT', () => {
ruvSwarmProcess.kill('SIGINT');
});
+1 -1
View File
@@ -3,7 +3,7 @@
* Provides clear, actionable command documentation
*/
export const VERSION = '2.0.0';
export const VERSION = '2.0.0-alpha.37';
export const MAIN_HELP = `
🌊 Claude-Flow v${VERSION} - Enterprise-Grade AI Agent Orchestration Platform
+202
View File
@@ -0,0 +1,202 @@
/**
* Wrapper for ruv-swarm MCP server to handle logger issues
* This wrapper ensures compatibility and handles known issues in ruv-swarm
*/
import { spawn } from 'child_process';
import { createInterface } from 'readline';
export class RuvSwarmWrapper {
constructor(options = {}) {
this.options = {
silent: options.silent || false,
autoRestart: options.autoRestart !== false,
maxRestarts: options.maxRestarts || 3,
restartDelay: options.restartDelay || 1000,
...options
};
this.process = null;
this.restartCount = 0;
this.isShuttingDown = false;
}
async start() {
if (this.process) {
throw new Error('RuvSwarm MCP server is already running');
}
return new Promise((resolve, reject) => {
try {
// Spawn ruv-swarm MCP server
this.process = spawn('npx', ['ruv-swarm', 'mcp', 'start'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
// Ensure stdio mode for MCP
MCP_MODE: 'stdio',
// Set log level to reduce noise
LOG_LEVEL: 'WARN'
}
});
let initialized = false;
let initTimeout;
// Handle stdout (JSON-RPC messages)
const rlOut = createInterface({
input: this.process.stdout,
crlfDelay: Infinity
});
rlOut.on('line', (line) => {
try {
const message = JSON.parse(line);
// Check for initialization
if (message.method === 'server.initialized' && !initialized) {
initialized = true;
clearTimeout(initTimeout);
resolve({
process: this.process,
stdout: this.process.stdout,
stdin: this.process.stdin
});
}
// Forward JSON-RPC messages
process.stdout.write(line + '\n');
} catch (err) {
// Not JSON, ignore
}
});
// Handle stderr (logs and errors)
const rlErr = createInterface({
input: this.process.stderr,
crlfDelay: Infinity
});
rlErr.on('line', (line) => {
// Filter out known harmless errors
if (line.includes('logger.logMemoryUsage is not a function')) {
// This is a known issue in ruv-swarm v1.0.8
// The server continues to work despite this error
if (!this.options.silent) {
console.error('⚠️ Known ruv-swarm logger issue detected (continuing normally)');
}
return;
}
// Filter out initialization messages if silent
if (this.options.silent) {
if (line.includes('✅') || line.includes('🧠') || line.includes('📊')) {
return;
}
}
// Forward other stderr output
if (!this.options.silent) {
process.stderr.write(line + '\n');
}
});
// Handle process errors
this.process.on('error', (error) => {
if (!initialized) {
clearTimeout(initTimeout);
reject(new Error(`Failed to start ruv-swarm: ${error.message}`));
} else {
console.error('RuvSwarm process error:', error);
this.handleProcessExit(error.code || 1);
}
});
// Handle process exit
this.process.on('exit', (code, signal) => {
if (!initialized) {
clearTimeout(initTimeout);
reject(new Error(`RuvSwarm exited before initialization: code ${code}, signal ${signal}`));
} else {
this.handleProcessExit(code || 0);
}
});
// Set initialization timeout
initTimeout = setTimeout(() => {
if (!initialized) {
this.stop();
reject(new Error('RuvSwarm initialization timeout'));
}
}, 30000); // 30 second timeout
} catch (error) {
reject(error);
}
});
}
handleProcessExit(code) {
this.process = null;
if (this.isShuttingDown) {
return;
}
console.error(`RuvSwarm MCP server exited with code ${code}`);
// Auto-restart if enabled and under limit
if (this.options.autoRestart && this.restartCount < this.options.maxRestarts) {
this.restartCount++;
console.log(`Attempting to restart RuvSwarm (attempt ${this.restartCount}/${this.options.maxRestarts})...`);
setTimeout(() => {
this.start().catch(err => {
console.error('Failed to restart RuvSwarm:', err);
});
}, this.options.restartDelay);
}
}
async stop() {
this.isShuttingDown = true;
if (!this.process) {
return;
}
return new Promise((resolve) => {
const killTimeout = setTimeout(() => {
console.warn('RuvSwarm did not exit gracefully, forcing kill...');
this.process.kill('SIGKILL');
}, 5000);
this.process.on('exit', () => {
clearTimeout(killTimeout);
this.process = null;
resolve();
});
// Send graceful shutdown signal
this.process.kill('SIGTERM');
});
}
isRunning() {
return this.process !== null && !this.process.killed;
}
}
// Export a function to start ruv-swarm with error handling
export async function startRuvSwarmMCP(options = {}) {
const wrapper = new RuvSwarmWrapper(options);
try {
const result = await wrapper.start();
console.log('✅ RuvSwarm MCP server started successfully');
return { wrapper, ...result };
} catch (error) {
console.error('❌ Failed to start RuvSwarm MCP server:', error.message);
throw error;
}
}