{"record":{"id":"2a18688743be8843","repo":"FoundationAgents/MetaGPT","slug":"invalid-click-action-step","errorCode":null,"errorMessage":"Invalid click action {step}","messagePattern":"Invalid click action (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/utils/a11y_tree.py","lineNumber":31,"sourceCode":"\n    seen_ids = set()\n    accessibility_tree = []\n    for node in resp[\"nodes\"]:\n        if node[\"nodeId\"] not in seen_ids:\n            accessibility_tree.append(node)\n            seen_ids.add(node[\"nodeId\"])\n    return accessibility_tree\n\n\nasync def execute_step(step: str, page: Page, browser_ctx: BrowserContext, accessibility_tree: list):\n    step = step.strip()\n    func = step.split(\"[\")[0].strip() if \"[\" in step else step.split()[0].strip()\n    if func == \"None\":\n        return \"\"\n    elif func == \"click\":\n        match = re.search(r\"click ?\\[(\\d+)\\]\", step)\n        if not match:\n            raise ValueError(f\"Invalid click action {step}\")\n        element_id = match.group(1)\n        await click_element(page, get_backend_node_id(element_id, accessibility_tree))\n    elif func == \"hover\":\n        match = re.search(r\"hover ?\\[(\\d+)\\]\", step)\n        if not match:\n            raise ValueError(f\"Invalid hover action {step}\")\n        element_id = match.group(1)\n        await hover_element(page, get_backend_node_id(element_id, accessibility_tree))\n    elif func == \"type\":\n        # add default enter flag\n        if not (step.endswith(\"[0]\") or step.endswith(\"[1]\")):\n            step += \" [1]\"\n\n        match = re.search(r\"type ?\\[(\\d+)\\] ?\\[(.+)\\] ?\\[(\\d+)\\]\", step)\n        if not match:\n            raise ValueError(f\"Invalid type action {step}\")\n        element_id, text, enter_flag = (\n            match.group(1),","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/utils/a11y_tree.py#L13-L49","documentation":"ValueError from execute_step in metagpt/utils/a11y_tree.py: the step string starts with 'click' but does not match the expected grammar `click [N]` where N is one or more digits (regex `click ?\\[(\\d+)\\]`). The action word is recognized but its argument is malformed, so the browser action is rejected before executing.","triggerScenarios":"Steps like 'click [ok]' (non-numeric id), 'click[12' (missing bracket), 'click []', or 'click 12' without brackets — anything where the click regex fails to match.","commonSituations":"LLM web agent emits free-form or hallucinated element ids instead of numeric node ids from the accessibility tree; prompt format drift between model output and the strict grammar; copy-paste of steps from a different browser-agent framework.","solutions":["Emit steps in the exact form `click [12]` using numeric nodeIds taken from the printed accessibility tree","Validate agent output with the regex re.search(r'click ?\\[(\\d+)\\]', step) before calling execute_step","Tighten the agent prompt/action space so only well-formed actions are generated"],"exampleFix":"# before\nawait execute_step(\"click [submit_button]\", page, ctx, tree)  # ValueError\n# after\nawait execute_step(\"click [42]\", page, ctx, tree)  # 42 = nodeId from a11y tree","handlingStrategy":"validation","validationCode":"import re\nif not re.search(r\"click ?\\[(\\d+)\\]\", step):\n    raise SystemExit(f\"malformed click step: {step!r}; expected 'click [id]'\")","typeGuard":"def is_valid_click(step: str) -> bool:\n    import re\n    return bool(re.fullmatch(r\"click ?\\[\\d+\\]\", step.strip()))","tryCatchPattern":"try:\n    await execute_step(step, page, ctx, tree)\nexcept ValueError:\n    step = f\"click [{node_id}]\"  # regenerate from a known-good nodeId\n    await execute_step(step, page, ctx, tree)","preventionTips":["Constrain the agent's action space to the exact grammar in prompts","Only use numeric nodeIds observed in the accessibility tree","Validate/normalize steps before dispatching to the browser"],"tags":["browser","a11y","agent","validation","format"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}