ruvnet / ruvnet/ruflo

Hive-Mind Resume Function Not Working - Multiple Async/Await Issue

Open
#550 1 comment 0 reactions 0 assignees View on GitHub
already-fixed
Dominant language
TypeScript
Stars
72.7k
Forks
8.6k
Avg merge
2d 23h
Merged PRs (30d)
83

Description

## Description
The `claude-flow hive-mind resume` command is broken due to multiple async/await inconsistencies and incomplete in-memory mode support in the session manager. Users experience errors like `sessions.forEach is not a function` and failed session resumption.

## Environment
- **OS**: Linux/Windows/macOS (affects all platforms)
- **Node.js**: All versions
- **Package**: claude-code-flow v2.0.0-alpha.70

## Steps to Reproduce
1. Run `npx claude-flow hive-mind spawn "test session"`
2. Pause the session with Ctrl+C
3. Run `npx claude-flow hive-mind sessions` → Error: `sessions.forEach is not a function`
4. Run `npx claude-flow hive-mind resume ` → Session not found or silent failure

## Expected Behavior
- Sessions should list correctly showing paused sessions
- Resume command should successfully restore paused sessions
- Both SQLite and in-memory modes should work

## Actual Behavior
- `sessions` command fails with `forEach is not a function`
- Resume command fails silently or with "Session not found" errors
- In-memory mode sessions cannot be resumed (only database operations implemented)

## Root Cause Analysis

### 🔴 **Critical Issue 1**: Missing `await` in `resumeSession()`
**File**: `src/cli/simple-commands/hive-mind/session-manager.js`
```javascript
// BROKEN - Line ~331
async resumeSession(sessionId) {
const session = this.getSession(sessionId); // ❌ Missing await\!
// Should be: const session = await this.getSession(sessionId);
```

### 🔴 **Critical Issue 2**: Missing `await` in `showSessions()`
**File**: `src/cli/simple-commands/hive-mind.js` (Line ~2423)
```javascript
// BROKEN - User already identified this
const sessions = sessionManager.getActiveSessions(); // ❌ Missing await\!
// Should be: const sessions = await sessionManager.getActiveSessions();
```

### 🔴 **Critical Issue 3**: `resumeSession()` Missing In-Memory Mode Support
The `resumeSession()` method only contains SQLite database operations but no in-memory mode handling. When SQLite is unavailable, the system defaults to in-memory mode, but resume operations fail because they try to execute database queries on in-memory sessions.

### 🔴 **Critical Issue 4**: Missing `await` in `getActiveSessionsWithProcessInfo()`
```javascript
// BROKEN
getActiveSessionsWithProcessInfo() {
const sessions = this.getActiveSessions(); // ❌ Missing await
}
// Should be async method with await
```

## Proposed Solution

### Fix 1: Add Missing `await` Keywords
```javascript
// In session-manager.js
async resumeSession(sessionId) {
const session = await this.getSession(sessionId); // ✅ Add await
// ... rest of method
}

// In hive-mind.js
async function showSessions(flags) {
const sessions = await sessionManager.getActiveSessions(); // ✅ Add await
// ... rest of method
}

// Fix getActiveSessionsWithProcessInfo
async getActiveSessionsWithProcessInfo() {
const sessions = await this.getActiveSessions(); // ✅ Add await and async
// ... rest of method
}
```

### Fix 2: Add In-Memory Mode Support to `resumeSession()`
```javascript
async resumeSession(sessionId) {
const session = await this.getSession(sessionId);
if (\!session) {
throw new Error(`Session ${sessionId} not found`);
}

console.log(`Resuming session ${sessionId} from status: ${session.status}`);

if (this.isInMemory) {
// ✅ ADD IN-MEMORY MODE HANDLING
const sessionData = this.memoryStore.sessions.get(sessionId);
if (sessionData) {
sessionData.status = 'active';
sessionData.resumed_at = new Date().toISOString();
sessionData.updated_at = new Date().toISOString();
}

await this.logSessionEvent(sessionId, 'info', 'Session resumed', null, {
pausedDuration: session.paused_at ? new Date() - new Date(session.paused_at) : null,
});

return session;
} else {
// EXISTING DATABASE CODE (keep as-is)
const stmt = this.db.prepare(`
UPDATE sessions
SET status = 'active', resumed_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`);
stmt.run(sessionId);
// ... rest of existing database code
}
}
```

## Files That Need Changes
- `src/cli/simple-commands/hive-mind/session-manager.js`
- `src/cli/simple-commands/hive-mind.js`
- Any other files calling `getActiveSessionsWithProcessInfo()` without await

## Testing Checklist
- [ ] `hive-mind sessions` lists sessions without errors
- [ ] `hive-mind resume ` works with SQLite database
- [ ] `hive-mind resume ` works with in-memory mode
- [ ] Resume properly restores session state
- [ ] Error handling for invalid session IDs
- [ ] Both interactive and direct session ID resume work

## Impact
- **Severity**: High - Core functionality completely broken
- **Users Affected**: All users trying to use hive-mind resume functionality
- **Workaround**: None currently available

## Additional Context
This appears to be a refactoring issue where methods were converted to async but not all callers were updated to use `await`. The in-memory fallback mode was also not fully implemented for resume operations.

**Reporter**: Analysis conducted via deep code investigation
**Priority**: P1 - Critical functionality broken

Contributor guide

Open the contributing guide

Research direction

Start with src/cli/simple-commands/hive-mind/session-manager.js and src/cli/simple-commands/hive-mind.js, then reproduce the issue with the listed hive-mind spawn, sessions, and resume commands. Check the async callers and in-memory and SQLite paths; done means sessions list successfully and resume restores valid sessions in both modes, including invalid IDs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.