{"record":{"id":"25404d53a50d9fdb","repo":"mastra-ai/mastra","slug":"could-not-derive-workspace-id-from-name-please-pr","errorCode":null,"errorMessage":"Could not derive workspace ID from name. Please provide an explicit id.","messagePattern":"Could not derive workspace ID from name\\. Please provide an explicit id\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/stored-workspaces.ts","lineNumber":188,"sourceCode":"    requestContext,\n  }) => {\n    try {\n      const storage = mastra.getStorage();\n\n      if (!storage) {\n        throw new HTTPException(500, { message: 'Storage is not configured' });\n      }\n\n      const workspaceStore = await storage.getStore('workspaces');\n      if (!workspaceStore) {\n        throw new HTTPException(500, { message: 'Workspaces storage domain is not available' });\n      }\n\n      // Derive ID from name if not explicitly provided\n      const id = providedId || toSlug(name);\n\n      if (!id) {\n        throw new HTTPException(400, {\n          message: 'Could not derive workspace ID from name. Please provide an explicit id.',\n        });\n      }\n\n      // Check if workspace with this ID already exists\n      const existing = await workspaceStore.getById(id);\n      if (existing) {\n        throw new HTTPException(409, { message: `Workspace with id ${id} already exists` });\n      }\n\n      // Force authorId from the authenticated caller; ignore any body-provided value.\n      // No caller (auth not configured) leaves authorId undefined so legacy\n      // single-user setups continue to behave as today.\n      const authorId = getCallerAuthorId(requestContext) ?? undefined;\n\n      await workspaceStore.create({\n        workspace: {\n          id,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-workspaces.ts#L170-L206","documentation":"On create, the workspace id defaults to the caller-provided id or toSlug(name). If neither yields a non-empty slug (empty/whitespace name whose slugification produces ''), the handler throws this 400. It refuses to invent an id so records stay addressable.","triggerScenarios":"POST /api/stored/workspaces with no id and a name like '   ' or '///' (only characters stripped by slugification), producing an empty derived id.","commonSituations":"Programmatic creation with a name built from user input that ends up empty; forms submitting whitespace-only names; locale/emoji-only names depending on toSlug behavior; template code passing name: '' .","solutions":["Pass an explicit id in the request body alongside name","Send a non-empty name containing alphanumeric characters so toSlug yields a usable slug","Trim/validate name client-side before submitting","Retry with corrected payload — this is a deterministic 400, not transient"],"exampleFix":"// before\nawait createWorkspace({ name: '   ' }); // slugifies to ''\n// after\nawait createWorkspace({ name: 'Research Sandbox', id: 'research-sandbox' });","handlingStrategy":"validation","validationCode":"import { toSlug } from '@mastra/core'; // or local equivalent\nexport function resolveWorkspaceId(id?: string, name?: string): string {\n  const derived = id || toSlug(name ?? '');\n  if (!derived) throw new Error('Provide an explicit id or a non-empty alphanumeric name');\n  return derived;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await createStoredWorkspace({ name });\n} catch (e: any) {\n  if (e.status === 400 && String(e.message).includes('Could not derive workspace ID')) {\n    return createStoredWorkspace({ name, id: slugify(name.trim()) || crypto.randomUUID() });\n  }\n  throw e;\n}","preventionTips":["Always send an explicit id for programmatic creation","Trim and sanity-check user-supplied names before submit","Ensure names contain alphanumeric characters toSlug can keep","Treat id derivation as a client concern: compute and validate the slug locally first"],"tags":["validation","http-400","workspaces","identifiers"],"backgroundTag":"invalid-identifier","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}