Bug: loading a history entry that predates state.interacted_element fails validation in the branch written to support it

Author: LesereingrapeCreated Sep 19, 2026Updated Sep 27, 2026

Browser Use Version

0.13.10 (also on current main, d8110c5)

Bug Description, Steps to Reproduce, Screenshots

AgentHistoryList.load_from_dict() has a branch whose stated purpose is to tolerate "incomplete or legacy history entries" (browser_use/agent/views.py:674) — when a stored state has no interacted_element key, it inserts one before validation (browser_use/agent/views.py:681-684).

The value it inserts is None, but BrowserStateHistory.interacted_element is a required list[DOMInteractedElement | None] | list[None] (browser_use/browser/views.py:122), so the value the compat branch injects is exactly the value pydantic rejects. Any history entry that predates the field therefore raises ValidationError on load instead of loading: the compatibility branch cannot succeed for the only input it exists for.

_load_rust_history() in browser_use/beta/service.py:4060-4062 repeats the same fill for the same model and fails the same way.

Reproduce with a payload that has no browser, no network and no LLM — a history entry whose state lacks the key:

history = AgentHistoryList.load_from_dict(
    {"history": [{"model_output": None, "result": [],
                  "state": {"url": "https://example.com", "title": "Example", "tabs": []}}]},
    AgentOutput,
)

Observed (verified locally against a source checkout of main):

pydantic_core._pydantic_core.ValidationError: 2 validation errors for AgentHistoryList
history.0.state.interacted_element.list[nullable[DOMInteractedElement]]
  Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]
history.0.state.interacted_element.list[none]
  Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]

The same payload with "interacted_element": [] already present loads fine, which is what shows the missing-key branch — not the payload — is at fault. Real entry point: Agent.load() calls AgentHistoryList.load_from_file() (browser_use/agent/service.py:3903), so resuming from an older history file aborts with a validation error about a field the caller never supplied.

grep -rn "load_from_dict\|load_from_file" tests/ returns nothing, so no test exercises either loader.

Failing Python Code

python
import sys
sys.path.insert(0, "path/to/browser-use")  # source checkout at main

from browser_use.agent.views import AgentHistoryList, AgentOutput

legacy_state = {"url": "https://example.com", "title": "Example", "tabs": []}
data = {"history": [{"model_output": None, "result": [], "state": dict(legacy_state)}]}

# raises ValidationError; adding "interacted_element": [] to the state loads fine
print(len(AgentHistoryList.load_from_dict(data, AgentOutput).history))

LLM Model

Not applicable — the failure happens before any model call.

Operating System & Browser Versions

Not applicable — pure Python, no browser session involved.

Full DEBUG Log Output

No log output; the exception propagates out of AgentHistoryList.load_from_dict → AgentHistoryList.model_validate.