{"record":{"id":"59852e41e7eb2bd9","repo":"mastra-ai/mastra","slug":"workspace-with-id-id-already-exists","errorCode":null,"errorMessage":"Workspace with id ${id} already exists","messagePattern":"Workspace with id (.+?) already exists","errorType":"http","errorClass":"HTTPException","httpStatus":409,"severity":"error","filePath":"packages/server/src/server/handlers/stored-workspaces.ts","lineNumber":196,"sourceCode":"\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,\n          authorId,\n          metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n          name,\n          description,\n          filesystem,\n          sandbox,\n          mounts,\n          search,","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-workspaces.ts#L178-L214","documentation":"The workspace creation handler checks workspaceStore.getById(id) before inserting and throws HTTPException 409 when a workspace with the same id already exists. IDs are caller-supplied, so re-creating a workspace with a previously used id collides with the stored record.","triggerScenarios":"POST to the stored-workspaces create endpoint with a body id that matches an existing workspace record in the workspaces storage domain.","commonSituations":"Re-running an idempotent provisioning script without a unique suffix; copy-pasting a create request in a retry loop after a timeout that actually succeeded; two clients choosing the same human-readable id.","solutions":["Use a different, unique id for the new workspace (e.g. prefix a UUID or timestamp).","Call getById or the list endpoint first to confirm the id is free before creating.","If the existing workspace is stale, delete it first, then re-create with the same id.","Handle HTTP 409 in the client and treat it as 'already exists' rather than retrying blindly."],"exampleFix":"// before\nawait createWorkspace({ id: 'my-workspace', name: 'My Workspace' });\n// after\nconst existing = await client.getWorkspace('my-workspace').catch(() => null);\nif (!existing) {\n  await createWorkspace({ id: 'my-workspace', name: 'My Workspace' });\n}","handlingStrategy":"try-catch","validationCode":"const existing = await client.getWorkspace(id).catch(() => null);\nif (existing) throw new Error(`Workspace ${id} already exists; pick another id`);","typeGuard":null,"tryCatchPattern":"try {\n  await client.createWorkspace({ id, name });\n} catch (e) {\n  if (e.status === 409) {\n    // id taken: regenerate or treat as already-provisioned\n    id = crypto.randomUUID();\n    await client.createWorkspace({ id, name });\n  } else throw e;\n}","preventionTips":["Generate ids (UUID/ULID) instead of human-chosen names.","Use create-or-get logic for idempotent provisioning scripts.","Check for existence before creating in retry loops."],"tags":["http-409","conflict","rest-api","storage"],"backgroundTag":"resource-already-exists","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}