{"record":{"id":"6303ef6664d9eda1","repo":"mastra-ai/mastra","slug":"scorer-definition-with-id-scorerdefinition-id-a","errorCode":null,"errorMessage":"Scorer definition with id ${scorerDefinition.id} already exists","messagePattern":"Scorer definition with id (.+?) already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/scorer-definitions/inmemory.ts","lineNumber":49,"sourceCode":"  async dangerouslyClearAll(): Promise<void> {\n    this.db.scorerDefinitions.clear();\n    this.db.scorerDefinitionVersions.clear();\n  }\n\n  // ==========================================================================\n  // Scorer Definition CRUD Methods\n  // ==========================================================================\n\n  async getById(id: string): Promise<StorageScorerDefinitionType | null> {\n    const scorer = this.db.scorerDefinitions.get(id);\n    return scorer ? this.deepCopyScorer(scorer) : null;\n  }\n\n  async create(input: { scorerDefinition: StorageCreateScorerDefinitionInput }): Promise<StorageScorerDefinitionType> {\n    const { scorerDefinition } = input;\n\n    if (this.db.scorerDefinitions.has(scorerDefinition.id)) {\n      throw new Error(`Scorer definition with id ${scorerDefinition.id} already exists`);\n    }\n\n    const now = new Date();\n    const newScorer: StorageScorerDefinitionType = {\n      id: scorerDefinition.id,\n      status: 'draft',\n      activeVersionId: undefined,\n      authorId: scorerDefinition.authorId,\n      organizationId: scorerDefinition.organizationId,\n      projectId: scorerDefinition.projectId,\n      metadata: scorerDefinition.metadata,\n      createdAt: now,\n      updatedAt: now,\n    };\n\n    this.db.scorerDefinitions.set(scorerDefinition.id, newScorer);\n\n    // Extract config fields from the flat input (everything except scorer-record fields)","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/scorer-definitions/inmemory.ts#L31-L67","documentation":"The in-memory scorer-definitions storage create() throws when a scorer definition with the same id is already stored. Scorer definition ids are unique primary keys; the store rejects duplicates rather than overwriting so existing versions/status remain intact.","triggerScenarios":"Calling storage.scorerDefinitions.create({ scorerDefinition: { id: 's1', ... } }) when 's1' already exists; re-running seeding (e.g. seedAgent which calls create internally) against a populated store; retrying a create that already succeeded.","commonSituations":"Test setup running twice in the same process; importing scorer definitions from a file with fixed ids; hot-reload re-executing registration code with the same module-level ids.","solutions":["Generate unique ids (crypto.randomUUID()) for each new scorer definition.","Check existence first (list/get) and skip creation if the id is present.","Catch the error and treat it as idempotent success if the definition is unchanged.","Use a fresh storage instance or clear the store between seed runs."],"exampleFix":"// before\nawait storage.scorerDefinitions.create({ scorerDefinition: { id: 'helpfulness', ... } });\n// after\nconst existing = await storage.scorerDefinitions.list();\nif (!existing.scorers.some(s => s.id === 'helpfulness')) {\n  await storage.scorerDefinitions.create({ scorerDefinition: { id: 'helpfulness', ... } });\n}","handlingStrategy":"validation","validationCode":"const { scorers } = await storage.scorerDefinitions.list({ perPage: false });\nif (scorers.some(s => s.id === scorerDefinition.id)) {\n  throw new Error(`scorer definition ${scorerDefinition.id} already exists`);\n}","typeGuard":"function isUniqueScorerId(scorers: { id: string }[], id: string): boolean {\n  return !scorers.some(s => s.id === id);\n}","tryCatchPattern":"try {\n  return await storage.scorerDefinitions.create({ scorerDefinition });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Scorer definition with id') && e.message.includes('already exists')) {\n    return; // idempotent seed\n  }\n  throw e;\n}","preventionTips":["Generate scorer definition ids with crypto.randomUUID() when uniqueness doesn't matter semantically.","Guard seed/registration code with an existence check so re-runs are no-ops.","Use a fresh in-memory storage instance per test file.","Avoid module-level fixed ids that collide on hot reload."],"tags":["storage","duplicate-key","scorer-definitions","in-memory"],"backgroundTag":"duplicate-resource-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}