{"record":{"id":"e19cc5db174a319c","repo":"mem0ai/mem0","slug":"mem0-telemetry-must-be-a-boolean-value","errorCode":null,"errorMessage":"MEM0_TELEMETRY must be a boolean value.","messagePattern":"MEM0_TELEMETRY must be a boolean value\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"mem0/memory/telemetry.py","lineNumber":23,"sourceCode":"import random\nimport sys\nimport threading\n\nfrom posthog import Posthog\n\nimport mem0\nfrom mem0.memory.setup import get_or_create_user_id\n\nMEM0_TELEMETRY = os.environ.get(\"MEM0_TELEMETRY\", \"True\")\nPROJECT_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\"\nHOST = \"https://us.i.posthog.com\"\nFEATURE_FLAGS_REQUEST_TIMEOUT_SECONDS = 0.5\n\nif isinstance(MEM0_TELEMETRY, str):\n    MEM0_TELEMETRY = MEM0_TELEMETRY.lower() in (\"true\", \"1\", \"yes\")\n\nif not isinstance(MEM0_TELEMETRY, bool):\n    raise ValueError(\"MEM0_TELEMETRY must be a boolean value.\")\n\nlogging.getLogger(\"posthog\").setLevel(logging.CRITICAL + 1)\nlogging.getLogger(\"urllib3\").setLevel(logging.CRITICAL + 1)\n_logger = logging.getLogger(__name__)\n\n\n# Default sampling rate for hot-path OSS events. Lifecycle events always fire at 100%.\n# Override via MEM0_TELEMETRY_SAMPLE_RATE env var.\n_DEFAULT_SAMPLE_RATE = 0.1\n\n\ndef _parse_sample_rate(raw):\n    \"\"\"Parse MEM0_TELEMETRY_SAMPLE_RATE env var. Never raises.\"\"\"\n    try:\n        value = float(raw)\n    except (TypeError, ValueError):\n        _logger.debug(\"MEM0_TELEMETRY_SAMPLE_RATE %r is not a number, defaulting to %s\", raw, _DEFAULT_SAMPLE_RATE)\n        return _DEFAULT_SAMPLE_RATE","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/memory/telemetry.py#L5-L41","documentation":"Raised at import time of mem0.memory.telemetry when the MEM0_TELEMETRY environment variable, after the str-to-bool conversion, is not a bool. In practice os.environ.get() always returns a str (or the default 'True'), and any string is coerced via `value.lower() in ('true','1','yes')`, so this ValueError is effectively unreachable through the environment variable — it fires only if MEM0_TELEMETRY is programmatically set to a non-str/non-bool object before import (e.g. monkeypatching or mutating os.environ with an int). Because it triggers on import, it breaks every mem0 import, not just telemetry calls.","triggerScenarios":"Patching mem0.memory.telemetry.MEM0_TELEMETRY or os.environ['MEM0_TELEMETRY'] with a non-string value (e.g. 1 as int, or a Mock) before importing mem0; test harnesses that inject raw values into os.environ; exotic environments that expose env values as non-strings.","commonSituations":"Test suites monkeypatching telemetry settings aggressively; CI configurations that inject typed values into the environment; developers surprised that any invalid-looking value like MEM0_TELEMETRY=off does NOT raise (it silently becomes False) while a non-string type does.","solutions":["Set MEM0_TELEMETRY as a plain string ('true'/'false', '1'/'0', 'yes'/'no'); any other string silently disables telemetry rather than raising","If you are patching in tests, patch the module attribute after import, or use string values in os.environ","Remove programmatic writes of non-string values into os.environ before importing mem0"],"exampleFix":"# before\nos.environ[\"MEM0_TELEMETRY\"] = 1  # non-string -> ValueError at import\nimport mem0\n\n# after\nos.environ[\"MEM0_TELEMETRY\"] = \"1\"  # plain string\nimport mem0","handlingStrategy":"validation","validationCode":"import os\nval = os.environ.get(\"MEM0_TELEMETRY\", \"True\")\nassert isinstance(val, str), \"MEM0_TELEMETRY must be a string env value\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set env vars as strings, including in test monkeypatching","Patch module attributes after import rather than injecting typed env values","Know that invalid strings (e.g. 'off') silently disable telemetry instead of raising"],"tags":["telemetry","environment","import-time","configuration"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}