{"record":{"id":"07e37e79c52fbcad","repo":"multica-ai/multica","slug":"workspace-id-or-workspace-slug-required","errorCode":null,"errorMessage":"workspace_id or workspace_slug required","messagePattern":"workspace_id or workspace_slug required","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/internal/realtime/hub.go","lineNumber":781,"sourceCode":"\tconn.Close()\n}\n\n// HandleWebSocket upgrades an HTTP connection to WebSocket with cookie or\n// first-message auth.\nfunc HandleWebSocket(hub *Hub, mc MembershipChecker, pr PATResolver, resolveSlug SlugResolver, w http.ResponseWriter, r *http.Request) {\n\tworkspaceID := r.URL.Query().Get(\"workspace_id\")\n\tif workspaceID == \"\" {\n\t\tif slug := r.URL.Query().Get(\"workspace_slug\"); slug != \"\" && resolveSlug != nil {\n\t\t\tresolved, err := resolveSlug(r.Context(), slug)\n\t\t\tif err != nil {\n\t\t\t\thttp.Error(w, `{\"error\":\"workspace not found\"}`, http.StatusNotFound)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tworkspaceID = resolved\n\t\t}\n\t}\n\tif workspaceID == \"\" {\n\t\thttp.Error(w, `{\"error\":\"workspace_id or workspace_slug required\"}`, http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tvar userID string\n\tif cookie, err := r.Cookie(auth.AuthCookieName); err == nil && cookie.Value != \"\" {\n\t\tuid, errMsg := authenticateToken(cookie.Value, pr, r.Context())\n\t\tif errMsg != \"\" {\n\t\t\thttp.Error(w, errMsg, http.StatusUnauthorized)\n\t\t\treturn\n\t\t}\n\t\tif !mc.IsMember(r.Context(), uid, workspaceID) {\n\t\t\thttp.Error(w, `{\"error\":\"not a member of this workspace\"}`, http.StatusForbidden)\n\t\t\treturn\n\t\t}\n\t\tuserID = uid\n\t}\n\n\tconn, err := upgrader.Upgrade(w, r, nil)","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/realtime/hub.go#L763-L799","documentation":"HTTP 400 from the realtime WebSocket upgrade handler when the request carries neither workspace_id nor workspace_slug query parameters. The hub is strictly per-workspace — every socket is bound to one workspace's event stream — so it refuses to upgrade a connection that does not name one. resolveSlug being nil also leaves the slug path inert, falling through to this 400.","triggerScenarios":"Opening ws://host/ws with no query params; passing the workspace in a header or body (ignored); a slug supplied while resolveSlug is nil (server wiring without slug support); parameter typo like workspaceid.","commonSituations":"Frontend builds the socket URL without appending the query string; migration from a global socket API to per-workspace sockets; copy-paste from old client code.","solutions":["Append ?workspace_id=<uuid> (or ?workspace_slug=<slug>) to the WebSocket URL.","If using a slug, confirm the server wires a slug resolver; otherwise resolve the ID client-side first.","Check for typos/casing in the parameter name."],"exampleFix":"// before\nconst sock = new WebSocket(`ws://${host}/ws`)\n\n// after\nconst sock = new WebSocket(`ws://${host}/ws?workspace_id=${workspaceId}`)","handlingStrategy":"validation","validationCode":"function wsUrl(host: string, workspaceId: string): string {\n  if (!workspaceId) throw new Error('workspaceId required for websocket')\n  return `ws://${host}/ws?workspace_id=${encodeURIComponent(workspaceId)}`\n}","typeGuard":"function canConnect(workspaceId?: string, slug?: string): boolean {\n  return Boolean(workspaceId && workspaceId.trim()) || Boolean(slug && slug.trim())\n}","tryCatchPattern":"conn, resp, err := dialer.Dial(url, nil)\nif err != nil && resp != nil && resp.StatusCode == 400 {\n    // missing workspace param: fix URL construction, do not retry as-is\n}","preventionTips":["Build socket URLs through a helper that requires a workspace target.","Assert on required query params in one place client-side.","Watch for param-name typos (workspaceid vs workspace_id) in code review."],"tags":["websocket","workspace","http-400","query-params"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}