{"record":{"id":"fbb63e592b30ed91","repo":"langchain-ai/deepagents","slug":"max-snapshot-bytes-must-be-1-or-none","errorCode":null,"errorMessage":"`max_snapshot_bytes` must be >= 1 or None","messagePattern":"`max_snapshot_bytes` must be >= 1 or None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/partners/quickjs/langchain_quickjs/middleware.py","lineNumber":263,"sourceCode":"        timeout: float = _DEFAULT_TIMEOUT,\n        max_ptc_calls: int | None = _DEFAULT_MAX_PTC_CALLS,\n        tool_name: str = _DEFAULT_TOOL_NAME,\n        max_result_chars: int = _DEFAULT_MAX_RESULT_CHARS,\n        capture_console: bool = True,\n        subagents: bool = True,\n        ptc: PTCOption | None = None,\n        mode: PersistenceMode | None = None,\n        max_snapshot_bytes: int | None = None,\n        snapshot_signing_key: str | bytes | None = None,\n    ) -> None:\n        \"\"\"Initialize REPL middleware state and build the exposed eval tool.\"\"\"\n        super().__init__()\n        if max_ptc_calls is not None and max_ptc_calls < 1:\n            msg = \"`max_ptc_calls` must be >= 1 or None\"\n            raise ValueError(msg)\n        if max_snapshot_bytes is not None and max_snapshot_bytes < 1:\n            msg = \"`max_snapshot_bytes` must be >= 1 or None\"\n            raise ValueError(msg)\n        self._memory_limit = memory_limit\n        self._timeout = timeout\n        self._max_ptc_calls = max_ptc_calls\n        self._tool_name = tool_name\n        self._max_result_chars = max_result_chars\n        self._capture_console = capture_console\n        self._subagents = subagents\n        self._ptc = ptc\n        self._mode = _resolve_mode(mode=mode)\n        self._max_snapshot_bytes = (\n            memory_limit if max_snapshot_bytes is None else max_snapshot_bytes\n        )\n        self._snapshot_signing_key = (\n            normalize_signing_key(snapshot_signing_key)\n            if snapshot_signing_key is not None\n            else None\n        )\n        self._registry = _Registry(","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/quickjs/langchain_quickjs/middleware.py#L245-L281","documentation":"The REPL middleware validates at construction that `max_snapshot_bytes` is `None` or an integer >= 1, because a zero/negative snapshot size cap is meaningless. Invalid values raise `ValueError` immediately in `__init__`.","triggerScenarios":"`QuickJsMiddleware(max_snapshot_bytes=0)` or a negative value, commonly from `int(os.environ.get(\"MAX_SNAPSHOT\", 0))` or a config default of 0.","commonSituations":"Trying to 'disable' snapshots with 0 instead of None; unset env vars coerced to 0; unit-test fixtures that pass 0 by mistake.","solutions":["Pass `max_snapshot_bytes=None` to use the default behavior, not 0.","Set a positive byte cap (>= 1) if you want to limit snapshot sizes.","Coerce empty/missing env values to None rather than 0."],"exampleFix":"// before\nQuickJsMiddleware(max_snapshot_bytes=int(os.environ.get(\"MAX_SNAPSHOT_BYTES\", 0)))\n\n// after\nraw = os.environ.get(\"MAX_SNAPSHOT_BYTES\")\nQuickJsMiddleware(max_snapshot_bytes=int(raw) if raw else None)","handlingStrategy":"validation","validationCode":"if max_snapshot_bytes is not None and max_snapshot_bytes < 1:\n    raise ValueError(\"max_snapshot_bytes must be >= 1 or None\")","typeGuard":"def is_valid_byte_cap(v) -> bool:\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 1)","tryCatchPattern":"try:\n    mw = QuickJsMiddleware(max_snapshot_bytes=max_snapshot_bytes)\nexcept ValueError as e:\n    if \"max_snapshot_bytes\" in str(e):\n        mw = QuickJsMiddleware(max_snapshot_bytes=None)","preventionTips":["Use None to disable/default the cap, never 0.","Sanitize env-derived integer caps (missing -> None).","Validate all byte-size options together at config load."],"tags":["validation","configuration","limits","snapshots"],"backgroundTag":"invalid-configuration-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}