Problem
During CodeAct execution, the script pane received ui_state=None, so any code block iterating over ui_state (e.g., for i in range(len(ui_state))) crashes with TypeError: object of type 'NoneType' has no len() (droidrun/agent/codeact/codeact_agent.py:422). The executor reads the snapshot from ctx.store.get("ui_state"), but handle_llm_input never persisted the latest accessibility tree to the store, only to events.
-
Minimal Repro: Run a CodeAct agent by running droidrun with the following prompt (the same one with which I initially encountered this error):
open the webbrowser then go to options -> history and produce a file with all page titles and their urls of pages visited.
The generated code will likely attempt something like for i in range(len(ui_state)) immediately after observing the UI. The executor fails with the quoted TypeError even if valid data is present in events.
Proposed Fix
After fetching device state and updating shared_state, persist the a11y_tree (the UI accessibility dump) into the workflow store:
await ctx.store.set("ui_state", a11y_tree)
Add this immediately after populating shared_state in handle_llm_input (line 310).
This mirrors how screenshots are handled (by persisting them to the workflow store at line 295) and ensures ctx.store.get("ui_state") in execute_code always returns the latest list, preventing NoneType crashes. It maintains the contract between perception and execution steps so code can safely iterate the UI snapshot.
Summary
CodeActAgent.handle_llm_input should store the freshly-fetched a11y_tree in the workflow store right after updating shared_state. This ensures that execute_code always receives a proper UI state, fixing the dataflow bug that led to the TypeError.
Problem
During CodeAct execution, the script pane received
ui_state=None, so any code block iterating overui_state(e.g.,for i in range(len(ui_state))) crashes withTypeError: object of type 'NoneType' has no len()(droidrun/agent/codeact/codeact_agent.py:422). The executor reads the snapshot fromctx.store.get("ui_state"), buthandle_llm_inputnever persisted the latest accessibility tree to the store, only to events.Minimal Repro: Run a CodeAct agent by running droidrun with the following prompt (the same one with which I initially encountered this error):
The generated code will likely attempt something like
for i in range(len(ui_state))immediately after observing the UI. The executor fails with the quoted TypeError even if valid data is present in events.Proposed Fix
After fetching device state and updating
shared_state, persist thea11y_tree(the UI accessibility dump) into the workflow store:Add this immediately after populating
shared_stateinhandle_llm_input(line 310).This mirrors how screenshots are handled (by persisting them to the workflow store at line 295) and ensures
ctx.store.get("ui_state")inexecute_codealways returns the latest list, preventingNoneTypecrashes. It maintains the contract between perception and execution steps so code can safely iterate the UI snapshot.Summary
CodeActAgent.handle_llm_inputshould store the freshly-fetcheda11y_treein the workflow store right after updatingshared_state. This ensures thatexecute_codealways receives a proper UI state, fixing the dataflow bug that led to theTypeError.