File size: 2,000 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# πŸ› Bug Fixes - autonomousRouter.ts & MCPIntegration.ts

**Date:** 2025-11-24  
**Status:** βœ… Fixed

---

## Bug 1: Race Condition in `setWebSocketServer()` βœ… FIXED

**Issue:**
- `setWebSocketServer()` function checked `if (agent)` but `agent` was declared AFTER the function
- If `setWebSocketServer()` was called before `initAutonomousAgent()`, the check would always fail
- Agent would be created with `null` wsServer

**Fix:**
- Moved `agent` declaration BEFORE `setWebSocketServer()` function
- Now the check works correctly regardless of initialization order
- Agent will receive wsServer when it's set, even if set before initialization

**Location:** `apps/backend/src/mcp/autonomousRouter.ts:20-37`

---

## Bug 2: Inconsistent `stmt.all()` Usage βœ… VERIFIED CORRECT

**Issue:**
- Line 198: `stmt.all(limit)` - passes single parameter
- Line 230: `stmt.all()` - no parameters
- Pattern inconsistent with other codebase usage

**Analysis:**
- After reviewing codebase, `stmt.all(limit)` is correct for sqlite3
- The database interface shows `all: (...params)` accepts variadic parameters
- Single parameter `stmt.all(limit)` works correctly
- No changes needed - code is correct

**Location:** `apps/backend/src/mcp/autonomousRouter.ts:198, 230`

---

## Bug 3: `operation` Parameter Not Used in MCP Routing βœ… FIXED

**Issue:**
- `query()` function accepts `op` parameter but never uses it
- Routing only uses `toolName`, so different operations are indistinguishable
- All operations on same tool route identically

**Fix:**
- Added `operation: op` to payload when routing through `mcpRegistry.route()`
- MCP tool handlers can now access `payload.operation` to distinguish operations
- Enables proper operation-based routing

**Location:** `apps/backend/src/mcp/autonomous/MCPIntegration.ts:48-58`

---

## Testing

βœ… Build passes  
βœ… No linting errors  
βœ… Race condition fixed  
βœ… Operation parameter included in routing

---

**Status:** βœ… All bugs fixed and verified