[eric] browser: claim only the user-picked card, not every dashboard card (fix 5cf6e2a)

This commit is contained in:
ciregenz
2026-06-12 20:06:56 -07:00
parent dcfa475ec1
commit a1f390ef0f
3 changed files with 7 additions and 27 deletions
+5 -12
View File
@@ -62,7 +62,6 @@ from backend.apps.agents.manager.prompt.prompt_context import (
_build_connected_tools_context,
_build_mcp_registry_summary,
_compose_system_prompt,
_get_pre_selected_browser_ids,
_resolve_attached_skills,
_resolve_forced_tools,
_resolve_mode,
@@ -218,9 +217,6 @@ class AgentManager:
def _build_selected_app_context(self, selected_app_output_ids: list[str] | None) -> str | None:
return _build_selected_app_context(selected_app_output_ids)
def _get_pre_selected_browser_ids(self, dashboard_id: str | None) -> list[str]:
return _get_pre_selected_browser_ids(dashboard_id)
def _build_mcp_registry_summary(self, allowed_tools: list[str], active_mcps: list[str]) -> str | None:
return _build_mcp_registry_summary(allowed_tools, active_mcps, get_all_tool_names)
@@ -1153,14 +1149,11 @@ class AgentManager:
os.path.dirname(__file__), "browser_agent_mcp_server.py"
)
backend_port = os.environ.get("OPENSWARM_PORT", "8324")
# The browser the user picked in select-mode must be driven, not duplicated.
# Put their selection FIRST so the dispatch claims it for the task; keep the
# rest of the dashboard's cards in the list so their host/no-renavigate
# semantics still hold. Without the user's selection here the sub-agent fell
# back to host-based auto-create and opened its own browser.
_user_sel = [b for b in (selected_browser_ids or []) if b]
_all_bids = self._get_pre_selected_browser_ids(session.dashboard_id)
pre_selected_bids = _user_sel + [b for b in _all_bids if b not in _user_sel]
# Only the card the user actually picked in select-mode gets claimed for the
# task, so the sub drives that one instead of opening its own duplicate. Passing
# EVERY dashboard card here (the old behavior) made the sub force-grab a random,
# usually-parked card and never navigate it, which broke the bulk of browser tasks.
pre_selected_bids = [b for b in (selected_browser_ids or []) if b]
from backend.auth import get_auth_token as _get_auth_token
_auth_tok = _get_auth_token()
mcp_servers["openswarm-browser-agent"] = {
+2 -1
View File
@@ -2328,7 +2328,8 @@ async def run_browser_agents(
model=model,
dashboard_id=dashboard_id,
pre_selected=is_pre_selected,
initial_url=_nav_url if _nav_url and browser_id not in pre_selected else None,
# an explicit url means "go here" even on the user's picked card; with none, a picked card stays on the page they parked it
initial_url=_nav_url if _nav_url and (url or browser_id not in pre_selected) else None,
parent_session_id=parent_session_id,
)
finally:
@@ -233,20 +233,6 @@ def _build_selected_app_context(selected_app_output_ids: list[str] | None) -> st
)
def _get_pre_selected_browser_ids(dashboard_id: str | None) -> list[str]:
"""Return browser_ids of all browser cards currently on the dashboard."""
if not dashboard_id:
return []
try:
from backend.apps.dashboards.dashboards import _load as load_dashboard
dashboard = load_dashboard(dashboard_id)
except Exception:
return []
raw = dashboard.model_dump(mode="json")
browser_cards = raw.get("layout", {}).get("browser_cards", {})
return [card.get("browser_id", "") for card in browser_cards.values() if card.get("browser_id")]
def _build_mcp_registry_summary(allowed_tools: list[str], active_mcps: list[str], get_all_tool_names: Callable[[], list[str]]) -> str | None:
"""Compact registry of installed MCP servers, one line per server.