{"record":{"id":"1fe6875c308c1ca7","repo":"mastra-ai/mastra","slug":"this-name-version-with-id-input-id-already","errorCode":null,"errorMessage":"${this.name}: version with id ${input.id} already exists","messagePattern":"(.+?): version with id (.+?) already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/filesystem-versioned.ts","lineNumber":604,"sourceCode":"    const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);\n\n    return {\n      [listKey]: entities.slice(offset, offset + perPage),\n      total: entities.length,\n      page,\n      perPage: perPageForResponse,\n      hasMore: offset + perPage < entities.length,\n    };\n  }\n\n  // ==========================================================================\n  // Version Methods (in-memory + git history)\n  // ==========================================================================\n\n  async createVersion(input: TVersion): Promise<TVersion> {\n    await this.ensureGitHistory();\n    if (this.versions.has(input.id)) {\n      throw new Error(`${this.name}: version with id ${input.id} already exists`);\n    }\n\n    const parentId = (input as Record<string, unknown>)[this.parentIdField] as string;\n\n    // Check for duplicate (parentId, versionNumber) pair\n    for (const v of this.versions.values()) {\n      if ((v as Record<string, unknown>)[this.parentIdField] === parentId && v.versionNumber === input.versionNumber) {\n        throw new Error(`${this.name}: version number ${input.versionNumber} already exists for entity ${parentId}`);\n      }\n    }\n\n    const version: TVersion = {\n      ...input,\n      createdAt: new Date(),\n    } as TVersion;\n\n    this.versions.set(input.id, structuredClone(version));\n    return structuredClone(version);","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/filesystem-versioned.ts#L586-L622","documentation":"createVersion ensures git history is initialized, then rejects a version whose id is already present in the versions map. Version records are immutable history entries, so duplicates are treated as a programming/data error rather than an idempotent re-write.","triggerScenarios":"Calling createVersion with a TVersion whose id already exists in the store; replaying an event/import that contains an already-persisted version record.","commonSituations":"Re-running an import/migration script; id generated from entity id + versionNumber colliding after a retry; two workers creating the same version concurrently.","solutions":["List existing versions and skip creation when the id is already present.","Generate a unique version id (e.g. uuid) instead of deriving it deterministically.","Catch the error and treat it as success if your flow is intentionally idempotent."],"exampleFix":"// before\nawait store.createVersion({ id: `${entityId}-v${n}`, ... });\n// after\nconst existing = await store.listVersions({ [parentIdField]: entityId });\nif (!existing.versions.some(v => v.id === `${entityId}-v${n}`)) {\n  await store.createVersion({ id: `${entityId}-v${n}`, ... });\n}","handlingStrategy":"try-catch","validationCode":"const versions = await store.listVersions({ [parentIdField]: entityId });\nif (versions.versions.some(v => v.id === newVersion.id)) return; // already imported","typeGuard":null,"tryCatchPattern":"try {\n  await store.createVersion(version);\n} catch (e) {\n  if (String(e.message).includes('already exists')) return; // idempotent skip\n  throw e;\n}","preventionTips":["Use uuids for version ids instead of deterministic composite keys.","Make version-creating scripts idempotent by skipping known ids.","Guard concurrent writers with a per-entity lock."],"tags":["storage","versioning","duplicate-key"],"backgroundTag":"duplicate-version-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}