{"record":{"id":"10474a7c5283efce","repo":"langchain-ai/deepagents","slug":"task-call-limiter-not-initialized","errorCode":null,"errorMessage":"task call limiter not initialized","messagePattern":"task call limiter not initialized","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/partners/quickjs/langchain_quickjs/_repl.py","lineNumber":628,"sourceCode":"        try:\n            return await asyncio.wrap_future(future)\n        except asyncio.CancelledError:\n            future.cancel()\n            raise\n\n    def _register_task_bridge(self) -> None:\n        \"\"\"Install the async host function backing top-level `task()`.\"\"\"\n        ctx = self._require_ctx()\n\n        async def _bridge(raw_input: Any = None) -> Any:\n            state = self._ptc_state\n            if state is None:\n                msg = \"task bridge called outside active eval\"\n                raise ConcurrentEvalError(msg)\n            task_calls = self._task_calls\n            if task_calls is None:\n                msg = \"task call limiter not initialized\"\n                raise RuntimeError(msg)\n\n            payload = _normalize_tool_input(raw_input)\n            async with task_calls:\n                try:\n                    result = await self._ainvoke_task_on_outer_loop(\n                        payload,\n                        state=state,\n                    )\n                except GraphInterrupt:\n                    raise\n                except Exception as e:\n                    # Subagent dispatches are part of the eval language, not\n                    # PTC calls. Surface their validation/runtime failures as\n                    # eval errors without changing normal `tools.*` semantics.\n                    raise _TaskBridgeError(e) from e\n            return coerce_tool_output_for_ptc(result)\n\n        ctx.register(_TASK_FUNCTION_NAME, _bridge, is_async=True)","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/quickjs/langchain_quickjs/_repl.py#L610-L646","documentation":"The task bridge raises this RuntimeError when `_task_calls` (the asyncio.Semaphore limiting concurrent subagent dispatches per REPL thread) is None even though an eval is active. The semaphore is allocated in `_ainit` only when `subagents_enabled` is true; its absence means the task bridge was registered without the limiter ever being created — an inconsistent internal state.","triggerScenarios":"An active eval's bridge finds `self._task_calls is None` — e.g. `_register_task_bridge` ran but `_ainit` never allocated the semaphore (subagent flag changed after init), or init was partially executed/failed midway.","commonSituations":"Custom subclass or patching that registers the task bridge without enabling subagents, exceptions during `_ainit` after bridge registration, or concurrency bugs where state was cleared/reset mid-eval.","solutions":["Report/fix the initialization ordering so `_task_calls` is allocated whenever the task bridge is registered","Recreate the REPL to get a consistent `_ainit`","Ensure nothing resets `_task_calls` to None while evals can run"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# Python side sanity check after constructing the REPL\nif repl._subagents_enabled:\n    assert repl._task_calls is not None, 'task limiter missing after init'","typeGuard":null,"tryCatchPattern":"try:\n    result = await task(payload)\nexcept (RuntimeError,) as e:\n    if 'limiter not initialized' in str(e):\n        raise InconsistentReplState('recreate the REPL') from e\n    raise","preventionTips":["Do not toggle subagent flags after REPL construction","Handle _ainit failures by discarding the REPL instance","Never reset internal state (_task_calls) while evals run"],"tags":["quickjs","task-bridge","initialization"],"backgroundTag":"eval-lifecycle-violation","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}