{"record":{"id":"da38b3f7f03906d3","repo":"langchain-ai/deepagents","slug":"max-ptc-calls-must-be-1-or-none","errorCode":null,"errorMessage":"`max_ptc_calls` must be >= 1 or None","messagePattern":"`max_ptc_calls` must be >= 1 or None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/partners/quickjs/langchain_quickjs/middleware.py","lineNumber":260,"sourceCode":"        self,\n        *,\n        memory_limit: int = _DEFAULT_MEMORY_LIMIT,\n        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","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/quickjs/langchain_quickjs/middleware.py#L242-L278","documentation":"The REPL middleware validates at construction that `max_ptc_calls` is either `None` (unlimited/default budget behavior) or an integer >= 1, since a PTC call budget of zero or negative makes no sense. Invalid values raise `ValueError` immediately in `__init__`.","triggerScenarios":"`QuickJsMiddleware(max_ptc_calls=0)`, a negative number, or a value computed from config/env that resolves to 0 (e.g. `int(os.environ.get(\"MAX_PTC\", 0))`).","commonSituations":"Misreading the option as 'disable PTC' and setting 0 instead of None; an env var defaulting to 0; a config file with `max_ptc_calls: 0`.","solutions":["Pass `max_ptc_calls=None` to use the default/unlimited budget behavior, not 0.","Set a positive integer budget (>= 1) if you want to cap PTC calls.","Sanitize env/config input: coerce missing values to None rather than 0."],"exampleFix":"// before\nQuickJsMiddleware(max_ptc_calls=int(os.environ.get(\"MAX_PTC\", 0)))  # 0 -> ValueError\n\n// after\nraw = os.environ.get(\"MAX_PTC\")\nQuickJsMiddleware(max_ptc_calls=int(raw) if raw else None)","handlingStrategy":"validation","validationCode":"if max_ptc_calls is not None and max_ptc_calls < 1:\n    raise ValueError(\"max_ptc_calls must be >= 1 or None\")","typeGuard":"def is_valid_budget(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_ptc_calls=max_ptc_calls)\nexcept ValueError as e:\n    if \"max_ptc_calls\" in str(e):\n        mw = QuickJsMiddleware(max_ptc_calls=None)","preventionTips":["Use None, not 0, to express 'no cap'.","Coerce missing env vars to None instead of 0.","Validate limits at config-load time, before construction."],"tags":["validation","configuration","limits","ptc"],"backgroundTag":"invalid-configuration-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}