mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-12 20:57:42 +02:00
[eric] browser: fail fast with an honest message when the card's webview is gone
This commit is contained in:
@@ -394,6 +394,41 @@ def test_ghost_completion_is_reported_as_error_not_completed(monkeypatch):
|
||||
assert SK.find_skill("docs.google.com", "Submit the form") is None
|
||||
|
||||
|
||||
def test_dead_browser_card_aborts_fast_without_spinning(monkeypatch):
|
||||
# The measured waste: a sub-agent dispatched to a released card retried the
|
||||
# dead webview for many turns. Now a gone card must abort fast (a couple of
|
||||
# turns, not the whole budget) and report the precise reason.
|
||||
import backend.apps.agents.browser.browser_skills as SK
|
||||
SK.clear()
|
||||
BH._browser_history.clear()
|
||||
# the model would happily keep clicking for 8 turns if we let it
|
||||
primary = FakeLLM(
|
||||
[Resp([_rp("click"), _tu("BrowserClick", selector=f".s{i}")]) for i in range(8)]
|
||||
+ [Resp([Blk("text", "done")], stop_reason="end_turn")]
|
||||
)
|
||||
aux = FakeAux()
|
||||
_install(monkeypatch, primary, aux)
|
||||
|
||||
async def _card_gone(request_id, action, browser_id, params, tab_id=""):
|
||||
return {"error": f"Browser card '{browser_id}' not found or not an Electron webview"}
|
||||
monkeypatch.setattr(BA.ws_manager, "send_browser_command", _card_gone, raising=False)
|
||||
captured = {}
|
||||
orig = BA.ws_manager.send_to_session
|
||||
|
||||
async def _cap(session_id, event, payload):
|
||||
if event == "agent:status":
|
||||
captured["status"] = payload.get("status")
|
||||
return await orig(session_id, event, payload)
|
||||
monkeypatch.setattr(BA.ws_manager, "send_to_session", _cap, raising=False)
|
||||
|
||||
r = asyncio.run(BA.run_browser_agent(
|
||||
task="Click submit", browser_id="b1", model="sonnet", initial_url=DOC_URL,
|
||||
))
|
||||
assert len(primary.calls) <= 3, "a dead card must fail fast, not spin the whole budget"
|
||||
assert captured.get("status") == "error"
|
||||
assert "no longer open" in r["summary"].lower()
|
||||
|
||||
|
||||
def test_perception_is_frontloaded_into_first_turn(monkeypatch):
|
||||
# With a known start URL, the agent should prefetch the element list + page
|
||||
# text and put them in the FIRST user message, so the model can act on turn 1
|
||||
|
||||
@@ -5,6 +5,7 @@ from backend.apps.agents.browser.browser_loop import (
|
||||
_STAGNATION_MAX,
|
||||
_looks_like_failure,
|
||||
advance_stagnation,
|
||||
card_is_unavailable,
|
||||
completion_is_honest,
|
||||
is_unproductive,
|
||||
stagnation_exhausted,
|
||||
@@ -151,3 +152,11 @@ def test_completion_honest_when_some_errors_but_an_action_landed():
|
||||
log = [_err("BrowserClick"), _err("BrowserClick"), _ok("BrowserClickIndex", "Clicked Submit")]
|
||||
honest, reason = completion_is_honest(log)
|
||||
assert honest
|
||||
|
||||
|
||||
def test_card_is_unavailable_only_for_unrecoverable_errors():
|
||||
# a gone card is unrecoverable (fail fast); a missing selector is not (route around)
|
||||
assert card_is_unavailable({"error": "Browser card 'b1' not found or not an Electron webview"})
|
||||
assert card_is_unavailable({"error": "No dashboard is connected. Open the dashboard to use browser tools."})
|
||||
assert not card_is_unavailable({"error": "Element not found: '.submit'"})
|
||||
assert not card_is_unavailable({"text": "ok", "url": "http://x"})
|
||||
|
||||
Reference in New Issue
Block a user