{"record":{"id":"4fc7380f2a9d4a20","repo":"FoundationAgents/MetaGPT","slug":"invalid-hover-action-step","errorCode":null,"errorMessage":"Invalid hover action {step}","messagePattern":"Invalid hover action (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/utils/a11y_tree.py","lineNumber":37,"sourceCode":"            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),\n            match.group(2),\n            match.group(3),\n        )\n        if enter_flag == \"1\":\n            text += \"\\n\"\n        await click_element(page, get_backend_node_id(element_id, accessibility_tree))","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/utils/a11y_tree.py#L19-L55","documentation":"ValueError from execute_step: the step starts with 'hover' but fails the regex `hover ?\\[(\\d+)\\]`, i.e. the bracketed element id is missing, non-numeric, or malformed. Same grammar contract as click: the numeric id must reference a nodeId present in the accessibility tree.","triggerScenarios":"Steps like 'hover [menu]', 'hover[3' , 'hover' with no argument, or a step whose id is a name rather than a nodeId.","commonSituations":"Agent outputs semantic element names instead of numeric node ids; truncated step strings from token limits; prompts that never show the hover grammar.","solutions":["Format the step as `hover [N]` with N a numeric nodeId from the accessibility tree","Pre-validate with re.search(r'hover ?\\[(\\d+)\\]', step) before calling execute_step","Include concrete hover examples in the agent's action-space prompt"],"exampleFix":"# before\nawait execute_step(\"hover [nav menu]\", page, ctx, tree)  # ValueError\n# after\nawait execute_step(\"hover [7]\", page, ctx, tree)  # 7 = nodeId from a11y tree","handlingStrategy":"validation","validationCode":"import re\nif not re.search(r\"hover ?\\[(\\d+)\\]\", step):\n    raise SystemExit(f\"malformed hover step: {step!r}; expected 'hover [id]'\")","typeGuard":"def is_valid_hover(step: str) -> bool:\n    import re\n    return bool(re.fullmatch(r\"hover ?\\[\\d+\\]\", step.strip()))","tryCatchPattern":"try:\n    await execute_step(step, page, ctx, tree)\nexcept ValueError:\n    step = f\"hover [{node_id}]\"\n    await execute_step(step, page, ctx, tree)","preventionTips":["Show hover grammar examples in the agent prompt","Reject non-numeric element references at parse time","Regenerate malformed actions from a fresh accessibility-tree observation"],"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"}