{"record":{"id":"e7d63f01039b9075","repo":"mastra-ai/mastra","slug":"no-versions-found-for-workspace-id","errorCode":null,"errorMessage":"No versions found for workspace ${id}","messagePattern":"No versions found for workspace (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/workspaces/inmemory.ts","lineNumber":139,"sourceCode":"      ...(activeVersionId !== undefined && { activeVersionId }),\n      ...(status !== undefined && { status: status as StorageWorkspaceType['status'] }),\n      ...(metadata !== undefined && {\n        metadata: { ...existingConfig.metadata, ...metadata },\n      }),\n      updatedAt: new Date(),\n    };\n\n    // Auto-set status to 'published' when activeVersionId is set, only if status is not explicitly provided\n    if (activeVersionId !== undefined && status === undefined) {\n      updatedConfig.status = 'published';\n    }\n\n    // If config fields are being updated, create a new version\n    if (hasConfigUpdate) {\n      // Get the latest version to use as base\n      const latestVersion = await this.getLatestVersion(id);\n      if (!latestVersion) {\n        throw new Error(`No versions found for workspace ${id}`);\n      }\n\n      // Extract config from latest version\n      const {\n        id: _versionId,\n        workspaceId: _workspaceId,\n        versionNumber: _versionNumber,\n        changedFields: _changedFields,\n        changeMessage: _changeMessage,\n        createdAt: _createdAt,\n        ...latestConfig\n      } = latestVersion;\n\n      // Merge updates into latest config\n      const newConfig = {\n        ...latestConfig,\n        ...configFields,\n      };","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/workspaces/inmemory.ts#L121-L157","documentation":"Thrown by update() when a config-field change requires creating a new workspace version, but getLatestVersion(id) returns nothing. Every workspace created through create() seeds an initial version, so this means the workspace has versions missing entirely. It protects the version-diff invariant: a new version must be based on the previous one's config.","triggerScenarios":"Calling update({ id, ...configField }) where the workspace exists but no version rows exist for it (e.g. versions were deleted directly, seeded only via raw db.workspaces map manipulation, or created against a backend that lost version rows); combining metadata-only updates is fine — only config updates hit this path.","commonSituations":"Manually deleting workspace_versions rows in a database while keeping the workspace row; test fixtures that inject workspace configs without seeding a v1 version; upgrading across versions of storage schemas where version rows were not migrated.","solutions":["Recreate the workspace via storage.workspaces.create() so a fresh initial version is seeded, then apply your update","Seed an initial version with createVersion({ id, workspaceId: id, versionNumber: 1, config: existingConfig, ... }) before updating config fields","Restore the deleted version rows from backup or migration tooling","Check whether a test fixture inserted workspaces directly into storage bypassing create()"],"exampleFix":"// before\nawait storage.workspaces.update({ id: id, name: 'Renamed' }); // throws when no versions exist\n// after\nconst latest = await storage.workspaces.getLatestVersion(id);\nif (!latest) {\n  const cfg = await storage.workspaces.getWorkspaceById(id);\n  await storage.workspaces.createVersion({ id: crypto.randomUUID(), workspaceId: id, versionNumber: 1, config: cfg.config, createdAt: new Date() });\n}\nawait storage.workspaces.update({ id: id, name: 'Renamed' });","handlingStrategy":"validation","validationCode":"const latest = await storage.workspaces.getLatestVersion(id);\nif (!latest) throw new Error(`Workspace ${id} has no versions; seed an initial version before config updates`);","typeGuard":null,"tryCatchPattern":"try {\n  await storage.workspaces.update({ id, ...configUpdates });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('No versions found for workspace')) {\n    // seed initial version from current config, then retry the update once\n  } else throw err;\n}","preventionTips":["Only create workspaces via create(), never by inserting raw config rows","Include a seeded v1 version in fixtures and migrations","Don't delete version rows without re-seeding an initial version","Add a health check that every workspace has at least one version"],"tags":["storage","workspace","versioning","in-memory"],"backgroundTag":"missing-parent-record","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}