{"record":{"id":"471372da8c518c7a","repo":"FoundationAgents/MetaGPT","slug":"function-timed-out-after-self-role-timeout-secon","errorCode":null,"errorMessage":"Function timed out after {self.role_timeout} seconds","messagePattern":"Function timed out after (.+?) seconds","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"metagpt/ext/sela/experimenter.py","lineNumber":55,"sourceCode":"}}\n```\n\"\"\"\n\n\nclass TimeoutException(Exception):\n    pass\n\n\ndef async_timeout():\n    def decorator(func):\n        async def wrapper(self, *args, **kwargs):\n            try:\n                result = await asyncio.wait_for(func(self, *args, **kwargs), timeout=self.role_timeout)\n            except asyncio.TimeoutError:\n                text = f\"Function timed out after {self.role_timeout} seconds\"\n                mcts_logger.error(text)\n                self.save_state()\n                raise TimeoutException(text)\n            return result\n\n        return wrapper\n\n    return decorator\n\n\nclass Experimenter(DataInterpreter):\n    node_id: str = \"0\"\n    start_task_id: int = 1\n    state_saved: bool = False\n    role_dir: str = SERDESER_PATH.joinpath(\"team\", \"environment\", \"roles\", \"Experimenter\")\n    role_timeout: int = 1000\n\n    def get_node_name(self):\n        return f\"Node-{self.node_id}\"\n\n    def get_next_instruction(self):","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/sela/experimenter.py#L37-L73","documentation":"TimeoutException raised by the @async_timeout decorator on Experimenter roles when the wrapped coroutine exceeds self.role_timeout seconds (asyncio.wait_for). State is saved and the exception propagates so the MCTS search can treat the node as failed rather than hang forever.","triggerScenarios":"A DataInterpreter/Experimenter run (code generation + execution loop) that does not finish within role_timeout, e.g. long LLM calls, retries, or generated code stuck in slow execution.","commonSituations":"Default role_timeout too small for big datasets or slow LLM endpoints; network latency to the LLM provider; a runaway generated script.","solutions":["Increase role_timeout in the experiment config / Experimenter(..., role_timeout=N)","Reduce dataset size or task complexity so the experiment finishes sooner","Check LLM provider latency and API quota — repeated slow calls are the usual cause"],"exampleFix":"# before\ndi = Experimenter(node_id=\"0\", role_timeout=300)\n\n# after\ndi = Experimenter(node_id=\"0\", role_timeout=1200)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from metagpt.ext.sela.experimenter import TimeoutException\ntry:\n    score = await di.run(...)\nexcept TimeoutException:\n    score = None  # mark node as failed, continue search","preventionTips":["Size role_timeout to your dataset and LLM latency (start large, then tune down)","Monitor slow experiments and prune nodes that repeatedly time out"],"tags":["sela","timeout","mcts","async"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}