{"record":{"id":"f3be542b7c0ec924","repo":"mastra-ai/mastra","slug":"factory-transition-reenter-must-be-a-boolean","errorCode":null,"errorMessage":"Factory transition reenter must be a boolean.","messagePattern":"Factory transition reenter must be a boolean\\.","errorType":"validation","errorClass":"FactoryRuleValidationError","httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/rules/validation.ts","lineNumber":229,"sourceCode":"  if (typeof type !== 'string') throw new FactoryRuleValidationError('Factory rule decision type is required.');\n\n  switch (type) {\n    case 'reject': {\n      assertExactKeys(value, ['type', 'code', 'reason'], 'Factory reject decision');\n      return {\n        type,\n        code: enumValue(value.code, REJECTION_CODES, 'Factory rejection code'),\n        reason: boundedString(value.reason, 'Factory rejection reason', MAX_REASON_LENGTH),\n      };\n    }\n    case 'transition': {\n      assertExactKeys(\n        value,\n        ['type', 'idempotencyKey', 'board', 'stage', 'message', 'reenter'],\n        'Factory transition decision',\n      );\n      if (value.reenter !== undefined && typeof value.reenter !== 'boolean') {\n        throw new FactoryRuleValidationError('Factory transition reenter must be a boolean.');\n      }\n      let message: { text: string; role?: string } | undefined;\n      if (value.message !== undefined) {\n        if (!isPlainObject(value.message)) {\n          throw new FactoryRuleValidationError('Factory transition message must be an object.');\n        }\n        assertExactKeys(value.message, ['text', 'role'], 'Factory transition message');\n        const role =\n          value.message.role === undefined\n            ? undefined\n            : boundedString(value.message.role, 'Factory transition message role', MAX_ROLE_LENGTH, IDENTIFIER_RE);\n        message = {\n          text: boundedString(value.message.text, 'Factory transition message text', MAX_MESSAGE_LENGTH),\n          ...(role ? { role } : {}),\n        };\n      }\n      return {\n        type,","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/rules/validation.ts#L211-L247","documentation":"For a 'transition' decision, the optional reenter field must be a boolean: it controls whether the target stage may be re-entered if already active. If reenter is defined but not true/false, this error is thrown by validateFactoryRuleDecision.","triggerScenarios":"decision({ type: 'transition', ..., reenter: 'yes' }), reenter: 1, reenter: null (null is defined and not boolean), or a truthy/falsy expression not coerced to boolean.","commonSituations":"Passing user/config string flags ('true'/'false') straight through; using 0/1 from a database column; null from an optional binding where undefined was intended.","solutions":["Coerce to boolean explicitly: reenter: Boolean(flag), or pass true/false literals","Convert string flags with flag === 'true'","Replace null with undefined (omit the key) when reenter is not applicable","Type the decision object as the library's FactoryRuleDecision input type so TypeScript catches it"],"exampleFix":"// before\ndecision({ type: 'transition', ..., reenter: opts.reenter ?? null })\n// after\ndecision({ type: 'transition', ..., reenter: Boolean(opts.reenter) })","handlingStrategy":"validation","validationCode":"function assertReenter(d) {\n  if (d?.reenter !== undefined && typeof d.reenter !== 'boolean') {\n    throw new TypeError('transition decision reenter must be boolean');\n  }\n}","typeGuard":"const hasValidReenter = (v): v is { reenter?: boolean } =>\n  (v as any)?.reenter === undefined || typeof (v as any).reenter === 'boolean';","tryCatchPattern":"try {\n  return decision(d);\n} catch (e) {\n  if (e instanceof FactoryRuleValidationError && e.message === 'Factory transition reenter must be a boolean.') {\n    logger.error('Bad reenter value', { reenter: d.reenter });\n    return decision({ ...d, reenter: Boolean(d.reenter) });\n  }\n  throw e;\n}","preventionTips":["Coerce flags with Boolean() before building the decision","Parse string config flags with flag === 'true'","Use undefined instead of null for absent values","Type decision inputs with the library's exported types"],"tags":["validation","factory-rules","type-error"],"backgroundTag":"schema-validation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}