Context
Follow-up items from the code review of PR #39 (Socket.IO migration). These are non-blocking for the initial merge but should be addressed before the SSE deprecation cleanup.
Security
Error Handling
Data Integrity
Performance
Code Cleanup
Testing
References
Context
Follow-up items from the code review of PR #39 (Socket.IO migration). These are non-blocking for the initial merge but should be addressed before the SSE deprecation cleanup.
Security
/api/auth/session-tokenhardening — This endpoint exposes the HttpOnly cookie value as JSON, effectively downgrading its protection. Add CSRF protection or rate limiting. Consider restricting to desktop mode only (check Tauri user agent header).Error Handling
gateway-server.ts: ifconnectGatewayfails, every subsequentagent:executeretries the connection. Add exponential backoff or max retry count to avoid hammering the backend.connect_error+ auto-reconnect conflict —gateway.ts: the firstconnect_errorrejects the connect promise, but Socket.IO keeps reconnecting in the background. Consider disablingreconnectionfor the initial connect attempt, then enabling after first success.Data Integrity
_run_llm_turnexception —agent_handler.py: if an exception occurs between persisting the assistant message and setting status to IDLE, partial DB state remains. Add state consistency check in the error recovery path.a1b2c3d4e5f6is a hardcoded placeholder instead of an auto-generated hash. Regenerate withalembic revision --autogenerateto avoid conflicts with other migrations on main.Performance
gateway.ts:createLocalToolRegistry()loads Playwright browser tools on everyconnect()call (~1-2s). Cache the registry instance and reuse across reconnects.useAgentSocket—getSocketConfig()fetches/api/auth/session-tokenon everyensureConnectedcall. Cache the token and only refetch on 401.agent_handler.py:load_messages_from_dbon everytool:resultcould be slow for long sessions (500+ messages). Consider incremental loading.Code Cleanup
console.log("[LocalGateway]..."andconsole.log("[gateway-server]..."statements, or convert to a proper logger.extraHeaders: { Cookie: ... }—gateway.ts: theauth.tokenfield is sufficient; the cookie header is redundant.PAUSE_TOOLStotool_definitions.py—agent_handler.pyline 979 hardcodes{"ask_user_questions"}. Move alongsideLOCAL_TOOLSandREMOTE_TOOLS.tool:resultrelay —gateway-server.ts: validate thetool:resultpayload from browser before forwarding to cloud.socketio_server.py: log which auth path (disabled/token/JWT/cookie) succeeded for debugging.Testing
_run_llm_turnstreaming tests — Currently mocked entirely in unit tests; needs integration coverageReferences
plans/agent-websocket-protocol.mdplans/agent-websocket-implementation.mdplans/agent-websocket-scenarios.mdplans/agent-websocket-migration-checklist.md