{"record":{"id":"8e399402e27efc5d","repo":"mermaid-js/mermaid","slug":"a-same-participant-should-only-be-defined-in-one-b","errorCode":null,"errorMessage":"A same participant should only be defined in one Box: ${old.name} can't be in '${old.box.name}' and in '${this.state.records.currentBox.name}' at the same time.","messagePattern":"A same participant should only be defined in one Box: (.+?) can't be in '(.+?)' and in '(.+?)' at the same time\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagrams/sequence/sequenceDb.ts","lineNumber":185,"sourceCode":"      if (!metadata.includes('\\n')) {\n        yamlData = '{\\n' + metadata + '\\n}';\n      } else {\n        yamlData = metadata + '\\n';\n      }\n      doc = yaml.load(yamlData, { schema: yaml.JSON_SCHEMA }) as ParticipantMetaData;\n    }\n    type = doc?.type ?? type;\n\n    // If alias is provided in metadata and description is not already set, use the alias\n    if (doc?.alias && (!description || description.text === name)) {\n      description = { text: doc.alias, wrap: description?.wrap, type };\n    }\n\n    const old = this.state.records.actors.get(id);\n    if (old) {\n      // If already set and trying to set to a new one throw error\n      if (this.state.records.currentBox && old.box && this.state.records.currentBox !== old.box) {\n        throw new Error(\n          `A same participant should only be defined in one Box: ${old.name} can't be in '${old.box.name}' and in '${this.state.records.currentBox.name}' at the same time.`\n        );\n      }\n\n      // Don't change the box if already\n      assignedBox = old.box ? old.box : this.state.records.currentBox;\n      old.box = assignedBox;\n\n      // Don't allow description nulling\n      if (old && name === old.name && description == null) {\n        return;\n      }\n    }\n\n    // Don't allow null descriptions, either\n    if (description?.text == null) {\n      description = { text: name, type };\n    }","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagrams/sequence/sequenceDb.ts#L167-L203","documentation":"Inside sequence addActor(), when an actor id already exists and BOTH the existing record and the current pending context have a Box, and they are different Box objects, mermaid refuses to relocate the participant. A participant is allowed to live in only one Box, so the conflict is reported with both Box names.","triggerScenarios":"Defining `box A` then `participant Bob`, later opening `box B` and referencing `Bob` again (or declaring Bob inside box B); autolink/properties calls that re-add an existing participant while a different currentBox is active.","commonSituations":"Refactoring a sequence diagram and moving participants between boxes without removing the old declaration; large diagrams where the same actor is referenced from multiple sections each wrapped in a different box; autogenerated diagrams that emit redundant participant lines.","solutions":["Declare the participant in exactly one box and reference it elsewhere without re-declaring.","Remove the earlier `participant Bob` (or its box) before re-declaring under a new box.","Move all messages for that participant under the single box it belongs to.","Use `AS` aliasing if you genuinely need two participants that share a display name in different boxes."],"exampleFix":"// before\nbox A\n  participant Bob\nbox B\n  participant Bob  // conflict\n\n// after — keep Bob in one box only\nbox A\n  participant Bob\nbox B\n  participant Bob2 as Bob","handlingStrategy":"validation","validationCode":"// Track participant box ownership while building diagram text\nconst ownerBox = new Map();\nfunction declare(box, id) {\n  if (ownerBox.has(id) && ownerBox.get(id) !== box) {\n    throw new Error(`${id} already in box ${ownerBox.get(id)}`);\n  }\n  ownerBox.set(id, box);\n}","typeGuard":"const isBoxConflictError = (e): boolean =>\n  e instanceof Error && /should only be defined in one Box/.test(e.message);","tryCatchPattern":"try {\n  await mermaid.run({ nodes: [el] });\n} catch (e) {\n  if (e instanceof Error && /should only be defined in one Box/.test(e.message)) {\n    // surface the two box names parsed from the message and ask the user to merge\n  } else { throw e; }\n}","preventionTips":["Declare each participant in exactly one box.","Use `AS` aliasing if the same display name is needed in another box.","Lint sequence diagrams for participants appearing under multiple box blocks."],"tags":["sequence","participant","box","conflict","validation"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}