{"record":{"id":"1373ca3caf72c8b8","repo":"mastra-ai/mastra","slug":"factory-message-preparebinding-must-be-a-boolean","errorCode":null,"errorMessage":"Factory message prepareBinding must be a boolean.","messagePattern":"Factory message prepareBinding must be a boolean\\.","errorType":"validation","errorClass":"FactoryRuleValidationError","httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/rules/validation.ts","lineNumber":326,"sourceCode":"        ...(value.cancelInFlight === true ? { cancelInFlight: true } : {}),\n      };\n    }\n    case 'sendMessage': {\n      assertExactKeys(\n        value,\n        ['type', 'idempotencyKey', 'role', 'message', 'priority', 'idleBehavior', 'prepareBinding'],\n        'Factory send message decision',\n      );\n      const priority =\n        value.priority === undefined\n          ? undefined\n          : enumValue(value.priority, ['medium', 'high', 'urgent'] as const, 'Factory message priority');\n      const idleBehavior =\n        value.idleBehavior === undefined\n          ? undefined\n          : enumValue(value.idleBehavior, ['persist', 'wake'] as const, 'Factory message idle behavior');\n      if (value.prepareBinding !== undefined && typeof value.prepareBinding !== 'boolean') {\n        throw new FactoryRuleValidationError('Factory message prepareBinding must be a boolean.');\n      }\n      return {\n        type,\n        ...commonCommitFields(value),\n        role: boundedString(value.role, 'Factory message role', MAX_ROLE_LENGTH, IDENTIFIER_RE),\n        message: boundedString(value.message, 'Factory message', MAX_MESSAGE_LENGTH),\n        ...(priority ? { priority } : {}),\n        ...(idleBehavior ? { idleBehavior } : {}),\n        ...(value.prepareBinding === true ? { prepareBinding: true } : {}),\n      };\n    }\n    case 'notify': {\n      assertExactKeys(value, ['type', 'idempotencyKey', 'title', 'body', 'level'], 'Factory notify decision');\n      const body = optionalBoundedString(value.body, 'Factory notification body', MAX_MESSAGE_LENGTH);\n      const level =\n        value.level === undefined\n          ? undefined\n          : enumValue(value.level, ['info', 'warning', 'error'] as const, 'Factory notification level');","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/rules/validation.ts#L308-L344","documentation":"The optional prepareBinding flag on a message decision must be a strict boolean when present. It gates whether the message is prepared/bound for a session, so non-boolean values would make the dispatcher's truthiness branching ambiguous and are rejected.","triggerScenarios":"Emitting a FactoryCommitDecision of the message type with value.prepareBinding defined but not typeof 'boolean' — e.g. prepareBinding: 'yes', 1, or null from parsed config or interpolated templates.","commonSituations":"YAML/JSON rule configuration where the flag arrives as a string; JavaScript rule authors using 1/0; environment-variable-driven rules where all values are strings.","solutions":["Coerce the incoming value to a strict boolean (=== true or === 'true') before emitting, or omit the field entirely with undefined.","Replace null with undefined — null is a defined, non-boolean value and will throw.","Validate/parse rule config with a schema (zod/yup) that enforces boolean at load time."],"exampleFix":"// before\nprepareBinding: options.prepareBinding // 'true' from YAML\n// after\nprepareBinding: options.prepareBinding === undefined ? undefined : options.prepareBinding === true","handlingStrategy":"type-guard","validationCode":"function checkPrepareBinding(d) {\n  if (d.prepareBinding !== undefined && typeof d.prepareBinding !== 'boolean') {\n    throw new Error('prepareBinding must be boolean or omitted');\n  }\n}","typeGuard":"function hasValidPrepareBinding(d: { prepareBinding?: unknown }): d is { prepareBinding?: boolean } {\n  return d.prepareBinding === undefined || typeof d.prepareBinding === 'boolean';\n}","tryCatchPattern":"try {\n  commitDecision(decision);\n} catch (e) {\n  if (e instanceof FactoryRuleValidationError && /prepareBinding must be a boolean/.test(e.message)) {\n    const { prepareBinding, ...rest } = decision;\n    return commitDecision({ ...rest, prepareBinding: prepareBinding === true });\n  }\n  throw e;\n}","preventionTips":["Use zod/yup boolean schemas on rule config before constructing decisions.","Omit the field (undefined) instead of passing null.","Keep decision construction in typed code paths where prepareBinding: boolean is enforced by the compiler."],"tags":["validation","type-mismatch","factory-rules"],"backgroundTag":"expected-boolean-got-string","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}