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:

  1. engine.io destroyUpgrade conflict between multiple Socket.IO instances
  2. Node.js inspector port conflict (--port flag in @nx/js:node executor)
  3. NativeWsGateway lifecycle timing issue (OnApplicationBootstrap vs explicit call)
  4. 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


🔗 Related


Auto-generated by MCP Smart Consolidation