{"record":{"id":"581a59fca0492901","repo":"multica-ai/multica","slug":"workspace-not-found-581a59","errorCode":null,"errorMessage":"workspace not found","messagePattern":"workspace not found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"server/internal/realtime/hub.go","lineNumber":774,"sourceCode":"\t\treturn false\n\t}\n\treturn true\n}\n\nfunc writeWSAuthErrorAndClose(conn *websocket.Conn, payload []byte, attrs ...any) {\n\twriteWSAuthFrame(conn, payload, \"auth_error\", attrs...)\n\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) {","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/realtime/hub.go#L756-L792","documentation":"HTTP 404 from the realtime WebSocket upgrade handler when no workspace_id query param was supplied, a workspace_slug was given instead, and the slug resolver (e.g. a DB lookup mapping slug → workspace UUID) returned an error. The slug does not resolve to any workspace: it is unknown, mistyped, or the lookup itself failed; the handler collapses both to a single 404 'workspace not found'.","triggerScenarios":"GET /ws?workspace_slug=does-not-exist (typo, deleted workspace, wrong organization scope); slug resolver DB error; slug containing URL-unsafe characters that mangle the lookup.","commonSituations":"Workspace renamed or deleted between page load and socket connect; user pastes an old invite link with a stale slug; per-workspace DB routing looking in the wrong shard.","solutions":["Verify the slug against the workspace list API (GET /api/workspaces) and correct it.","Prefer workspace_id (the UUID) when known — it skips slug resolution entirely.","If the workspace was renamed, refresh the page/client so it picks up the new slug or the ID.","If the resolver logs an error, check DB connectivity/permissions on the server."],"exampleFix":"// before: connect by a possibly stale slug\nnew WebSocket(\"ws://host/ws?workspace_slug=\" + slug)\n\n// after: resolve the id once and connect by id\nconst ws = await api.workspaces.list()\nconst id = ws.find(w => w.slug === slug)?.id\nif (id) new WebSocket(\"ws://host/ws?workspace_id=\" + id)","handlingStrategy":"validation","validationCode":"// resolve slug → id via the REST API before opening the socket\nwsList, err := api.ListWorkspaces(ctx)\nif err != nil { return err }\nvar id string\nfor _, w := range wsList { if w.Slug == slug { id = w.ID; break } }\nif id == \"\" { return fmt.Errorf(\"unknown workspace slug: %s\", slug) }","typeGuard":"func hasWorkspaceTarget(idParam, slug string) bool { return idParam != \"\" || slug != \"\" }","tryCatchPattern":"conn, resp, err := dialer.Dial(url, nil)\nif err != nil && resp != nil && resp.StatusCode == 404 {\n    // slug stale: re-resolve via REST, then reconnect with workspace_id once\n}","preventionTips":["Prefer workspace_id (UUID) over slug for machine clients.","Re-resolve slugs after workspace rename/delete events.","Handle 404 on socket connect by refreshing workspace metadata, not by looping."],"tags":["websocket","workspace","http-404","slug"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}