{"record":{"id":"e1a92eb0d7194865","repo":"FoundationAgents/MetaGPT","slug":"rollouts-must-be-greater-than-2-if-there-is-no-tre","errorCode":null,"errorMessage":"Rollouts must be greater than 2 if there is no tree to load","messagePattern":"Rollouts must be greater than 2 if there is no tree to load","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/sela/search/tree_search.py","lineNumber":434,"sourceCode":"        rollouts = args.rollouts\n        from_scratch = args.from_scratch\n        role, root = initialize_di_root_node(state, reflection=reflection)\n        self.root_node = root\n        self.instruction_generator = InstructionGenerator(\n            state=state, use_fixed_insights=self.use_fixed_insights, from_scratch=from_scratch\n        )\n        await self.instruction_generator.initialize()\n\n        tree_loaded = False\n        if load_tree:\n            tree_loaded = self.load_tree()\n            mcts_logger.log(\"MCTS\", f\"Number of simulations: {self.get_num_simulations()}\")\n            mcts_logger.log(\"MCTS\", f\"Tree loaded: {tree_loaded}\")\n\n        if not tree_loaded:\n            rollouts -= 2  # 2 rollouts for the initial tree\n            if rollouts < 0:\n                raise ValueError(\"Rollouts must be greater than 2 if there is no tree to load\")\n            self.children[root] = []\n            reward = await self.simulate(root, role)\n            self.backpropagate(root, reward)\n            node, reward = await self.expand_and_simulate(root)\n            # self.backpropagate(node, reward)\n            self.save_node_order(root.id)\n            self.save_node_order(node.id)\n        else:\n            root = self.root_node\n            self.load_node_order()\n\n        for _ in range(rollouts):  # number of rollouts\n            mcts_logger.log(\"MCTS\", f\"Start the next rollout {_+1}\")\n            node = self.select(root)\n            if node.is_terminal():\n                if node.raw_value == 0:\n                    reward = await self.simulate(node)\n                else:","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/sela/search/tree_search.py#L416-L452","documentation":"Raised by MCTS tree search when no tree could be loaded from disk and the requested rollout count is too small: rollouts is decremented by 2 because two rollouts are consumed to build the initial tree (simulate root + expand_and_simulate), and a negative remainder is rejected. Effectively rollouts must be >= 2 (message says greater than 2; rollouts < 2 after subtracting triggers it).","triggerScenarios":"Starting a fresh search (no saved tree JSON in the tree save path) with --rollouts 0 or 1; or load_tree failing silently (missing/corrupt tree file) while a small rollout count is used.","commonSituations":"Smoke-testing with a tiny rollout count; wrong tree save/load directory so an existing tree is not found; deleted tree files.","solutions":["Increase --rollouts to at least 3 (2 are consumed for initial tree construction)","Verify the tree file path in args so a previously saved tree is actually loaded","For quick tests, keep rollouts small but >= 3 on a fresh tree"],"exampleFix":"# before\n--rollouts 1\n\n# after\n--rollouts 10","handlingStrategy":"validation","validationCode":"MIN_ROLLOUTS = 3\nif not tree_exists(load_tree_path) and rollouts < MIN_ROLLOUTS:\n    raise SystemExit(\"increase --rollouts to >= 3 for a fresh tree\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep rollouts >= 3 for cold-start searches","Persist and correctly point to the saved tree between runs so rollouts are not re-spent on initialization"],"tags":["sela","mcts","validation","configuration"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}