{"record":{"id":"3d1488481641eafa","repo":"mermaid-js/mermaid","slug":"it-is-not-possible-to-have-actors-with-the-same-id","errorCode":null,"errorMessage":"It is not possible to have actors with the same id, even if one is destroyed before the next is created. Use 'AS' aliases to simulate the behavior","messagePattern":"It is not possible to have actors with the same id, even if one is destroyed before the next is created\\. Use 'AS' aliases to simulate the behavior","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/sequence/sequenceDb.ts","lineNumber":583,"sourceCode":"          this.state.records.messages.push({\n            id: this.state.records.messages.length.toString(),\n            from: undefined,\n            to: undefined,\n            message: {\n              start: param.sequenceIndex,\n              step: param.sequenceIndexStep,\n              visible: param.sequenceVisible,\n            },\n            wrap: false,\n            type: param.signalType,\n          });\n          break;\n        case 'addParticipant':\n          this.addActor(param.actor, param.actor, param.description, param.draw, param.config);\n          break;\n        case 'createParticipant':\n          if (this.state.records.actors.has(param.actor)) {\n            throw new Error(\n              \"It is not possible to have actors with the same id, even if one is destroyed before the next is created. Use 'AS' aliases to simulate the behavior\"\n            );\n          }\n          this.state.records.lastCreated = param.actor;\n          this.addActor(param.actor, param.actor, param.description, param.draw, param.config);\n          this.state.records.createdActors.set(param.actor, this.state.records.messages.length);\n          break;\n        case 'destroyParticipant':\n          this.state.records.lastDestroyed = param.actor;\n          this.state.records.destroyedActors.set(param.actor, this.state.records.messages.length);\n          break;\n        case 'activeStart':\n          this.addSignal(param.actor, undefined, undefined, param.signalType);\n          break;\n        case 'centralConnection':\n          this.addSignal(param.actor, undefined, undefined, param.signalType);\n          break;\n        case 'centralConnectionReverse':","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/sequence/sequenceDb.ts#L565-L601","documentation":"On the `createParticipant` message command, if the actor id already exists in the actors map, mermaid throws even if the actor was previously destroyed. Ids are immutable identities for the whole diagram; destroy only hides the lifeline, it does not free the id. The message suggests `AS` aliases as the supported workaround.","triggerScenarios":"Using `create ParticipantX` when `ParticipantX` was already declared or created earlier in the diagram, regardless of an intervening `destroy ParticipantX`.","commonSituations":"Modeling a resource that is created/destroyed/recreated and reusing the same name; renaming a participant but forgetting the original still exists; generated diagrams that emit `create` on every loop iteration.","solutions":["Use a distinct id with `AS`, e.g. `create ParticipantX2 as ParticipantX`.","Remove the earlier declaration/creation of that id if you truly want a fresh participant.","Avoid `create` for an actor that already exists; just send a message to it.","If recreating, alias each incarnation separately so each id is unique."],"exampleFix":"// before\nparticipant Alice\ncreate Alice   // id reuse -> throws\n\n// after — alias the new incarnation\nparticipant Alice\ncreate Alice2 as Alice","handlingStrategy":"validation","validationCode":"// Ensure the id is unused before emitting `create`\nif (actors.has(id)) {\n  throw new Error(`Cannot create '${id}': id already exists; use an AS alias`);\n}","typeGuard":"const isCreateDuplicateError = (e): boolean =>\n  e instanceof Error && /actors with the same id/.test(e.message);","tryCatchPattern":"try {\n  await mermaid.run({ nodes: [el] });\n} catch (e) {\n  if (e instanceof Error && /actors with the same id/.test(e.message)) {\n    // suggest an AS alias for the recreation\n  } else { throw e; }\n}","preventionTips":["Treat actor ids as unique for the whole diagram, even after destroy.","Use `AS` to alias recreated incarnations.","Avoid `create` for already-declared participants."],"tags":["sequence","participant","create","duplicate-id","validation"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}