{"record":{"id":"d7c9bbe37b02b05b","repo":"mastra-ai/mastra","slug":"mode-mode-id-transitionsto-cannot-reference-i","errorCode":null,"errorMessage":"Mode \"${mode.id}\" transitionsTo cannot reference itself","messagePattern":"Mode \"(.+?)\" transitionsTo cannot reference itself","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agent-controller/agent-controller.ts","lineNumber":81,"sourceCode":"\n  for (const mode of modes) {\n    if (modeIds.has(mode.id)) {\n      throw new Error(`Duplicate mode id \"${mode.id}\" found when creating the AgentController`);\n    }\n\n    modeIds.add(mode.id);\n\n    const modeRecord = mode as unknown as { id: string; tools?: unknown; additionalTools?: unknown };\n    if (modeRecord.tools && modeRecord.additionalTools) {\n      throw new Error(\n        `Mode \"${modeRecord.id}\" cannot set both \"tools\" and \"additionalTools\" - choose replace OR augment`,\n      );\n    }\n  }\n\n  for (const mode of modes) {\n    if (mode.transitionsTo === mode.id) {\n      throw new Error(`Mode \"${mode.id}\" transitionsTo cannot reference itself`);\n    }\n    if (mode.transitionsTo && !modeIds.has(mode.transitionsTo)) {\n      throw new Error(`Mode \"${mode.id}\" transitionsTo references unknown mode \"${mode.transitionsTo}\"`);\n    }\n  }\n}\n\n/**\n * Build a user-facing message for a non-success stream finish reason.\n *\n * Anthropic's classifier blocks / model refusals (e.g. `claude-fable-5`) surface\n * through the AI SDK as a `content-filter` finish reason, with details on\n * `providerMetadata.anthropic.stopDetails`. Without explicit handling these\n * runs end on an empty assistant message with no error, so the run appears to\n * silently stop. Returning a message here lets the controller finalize the run\n * into an explicit terminal error state.\n */\n/**","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent-controller/agent-controller.ts#L63-L99","documentation":"A mode's transitionsTo defines which mode the controller switches to after that mode completes. Since self-transitions would create an infinite loop with no progress, validateModes rejects any mode whose transitionsTo equals its own id at construction time.","triggerScenarios":"Creating an AgentController where a mode is declared as e.g. { id: 'plan', transitionsTo: 'plan', ... } — usually from templated/generated configs that default transitionsTo to the current mode id.","commonSituations":"Auto-generating mode configs from a map where each mode's transitionsTo defaulted to itself; misunderstanding transitionsTo as 'stay in this mode when done'; refactoring renames that collided ids.","solutions":["Point transitionsTo at a different mode id, or omit it to use the default flow","If looping behavior is needed, alternate between two modes or re-enter the mode via the runtime API instead of a self-transition","Validate generated configs before passing them to the constructor"],"exampleFix":"// before\n{ id: 'plan', transitionsTo: 'plan' }\n// after\n{ id: 'plan', transitionsTo: 'execute' }","handlingStrategy":"validation","validationCode":"function assertNoSelfTransitions(modes: { id: string; transitionsTo?: string }[]): void {\n  for (const m of modes) {\n    if (m.transitionsTo === m.id) throw new Error(`Mode \"${m.id}\" cannot transition to itself`);\n  }\n}\nassertNoSelfTransitions(config.modes);","typeGuard":null,"tryCatchPattern":"try {\n  new AgentController(config);\n} catch (e) {\n  if ((e as Error).message.includes('transitionsTo cannot reference itself')) {\n    // fix or remove the self-referencing transitionsTo, then reconstruct\n  }\n}","preventionTips":["Never default transitionsTo to the mode's own id in generators","Treat mode graphs as DAGs; lint for cycles before construction","Omit transitionsTo when the next step equals the current mode"],"tags":["configuration","agent-controller","state-machine","self-reference"],"backgroundTag":"cyclic-transition-configuration","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}