Bugfix: What caused the persistent 'VITTO WebSocket error: Unexpecte...
Documentation for Sessions
🐛 Bugfix: What caused the persistent 'VITTO WebSocket error: Unexpecte...
Date: 2026-02-06
Time: 21:02:49 UTC
Session: editor2-97.7
Agent: backend
Confidence: 100%
Status: ✅ Documented
📋 Decision Context
Question:
What caused the persistent 'VITTO WebSocket error: Unexpected server response: 400' on ws://localhost:3001/ws?
Task: Fix VITTO WebSocket 400 error on backend-ai-api
🎯 Decision Made
Chosen:
Node.js inspector port conflict (--port flag in @nx/js:node executor)
Options Considered:
- engine.io destroyUpgrade conflict between multiple Socket.IO instances
- Node.js inspector port conflict (--port flag in @nx/js:node executor)
- NativeWsGateway lifecycle timing issue (OnApplicationBootstrap vs explicit call)
- CORS or origin rejection at HTTP level
💭 Reasoning
The true root cause was in tools/scripts/dev-serve.js which passed --port=3001 to npx nx serve backend-ai-api. For backend apps using @nx/js:node executor, --port sets the Node.js INSPECTOR port (like --inspect=3001), NOT the application port. The app port comes from process.env.AI_API_PORT. This caused the Node.js debugger to bind to localhost:3001 on the loopback interface BEFORE the NestJS app could bind to *:3001. When VITTO connected to ws://localhost:3001/ws, DNS resolved to the loopback address first, hitting the inspector which responded with HTTP 400 'WebSockets request was expected' (inspector expects Chrome DevTools Protocol, not app WebSocket). The fix: add backend: true to APP_PORT_MAP entries for backend apps and skip the --port flag for them. The inspector now defaults to port 9229.
📁 Files Involved
tools/scripts/dev-serve.jsapis/backend-ai-api/src/main.tsapis/backend-ai-api/src/app/mcp-gateway/native-ws.gateway.ts
🔗 Related
- Decision ID:
dev_1770411769170_0cepyet - Session: 97
- Workspace: editor2
Auto-generated by MCP Smart Consolidation