"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
fix(browser): preserve daemon-mode lane stickiness for sessionless callers (Codex P2)
apireno99d1182504fd
diff --git a/browser/agent-harness/HARNESS.md b/browser/agent-harness/HARNESS.mdindex 74a231068..7b194e1b7 100644--- a/browser/agent-harness/HARNESS.md+++ b/browser/agent-harness/HARNESS.md@@ -37,22 +37,28 @@ DOMShell is an npm package that exposes Chrome's Accessibility Tree via MCP:### Installation+**Requires `@apireno/domshell` 2.0.2 or newer.** The harness uses+`group_id="shared"` and `group_id="new"` keywords introduced in 2.0.2 to+declare lane intent explicitly (silences the deprecation warning that 2.0.2+added for omitted `group_id`; will become a hard error in DOMShell 3.0.0).+```bash-# Verify DOMShell is available (2.0.0 or newer required)-npx @apireno/domshell --version+npx @apireno/domshell --version # should report 2.0.2 or higher# Install Chrome extension# https://chromewebstore.google.com/detail/domshell```-**Minimum version: `@apireno/[email protected]`.** DOMShell 2.0.0 (May 2026)-consolidated the MCP tool surface from 38 per-command tools to a single-`domshell_execute` tool. The harness targets this consolidated tool, so no-opt-in `--granular` server flag is required.+The standard `npx @apireno/domshell` invocation pulls the latest published+version automatically; no manual pinning is required.++DOMShell 2.0.0 (May 2026) consolidated the MCP tool surface from 38+per-command tools to a single `domshell_execute` tool. The harness targets+this consolidated tool, so no opt-in `--granular` server flag is required.### MCP Tool-DOMShell 2.0.0+ exposes a single MCP tool:+DOMShell 2.0.2+ exposes a single MCP tool:| Tool | Description ||------|-------------|diff --git a/browser/agent-harness/cli_anything/browser/tests/test_domshell_backend.py b/browser/agent-harness/cli_anything/browser/tests/test_domshell_backend.pyindex 8c63f5967..868e06e6b 100644--- a/browser/agent-harness/cli_anything/browser/tests/test_domshell_backend.py+++ b/browser/agent-harness/cli_anything/browser/tests/test_domshell_backend.py@@ -1143,6 +1143,36 @@ def test_call_execute_passes_group_id_new_when_lane_is_none():assert sess.domshell_lane_id == "brand-new"+def test_call_execute_passes_group_id_shared_for_daemon_mode_without_session():+ """Daemon mode + no session: route to the default per-connection lane+ via ``group_id="shared"``. The daemon's persistent stdio connection+ keeps that lane sticky across calls, so direct callers like+ ``open_url(use_daemon=True)`` followed by ``ls(use_daemon=True)``+ share browser state without needing a Session object to carry a+ lane id.++ Migration note (PR #308 follow-up): the initial 2.0.2 migration+ commit (be62f843b5) passed ``group_id="new"`` in this case, which+ broke the daemon workflow by creating a fresh isolated lane per+ call. Caught by Codex P2. Fix re-routes daemon-no-session calls to+ ``"shared"``.+ """+ fake_tool = AsyncMock(return_value=_make_result("✓\n[lane: daemon-default]"))++ fake_mcp_session = AsyncMock()+ fake_mcp_session.call_tool = fake_tool++ # Simulate a live daemon session — the same path open_url / ls take+ # when called with use_daemon=True but no Session.+ with patch.object(backend, "_daemon_session", fake_mcp_session):+ import asyncio as _aio+ _aio.run(backend._call_execute("ls /", use_daemon=True, session=None))++ name, arguments = fake_tool.call_args.args+ assert name == "domshell_execute"+ assert arguments.get("group_id") == "shared"++def test_distinct_sessions_have_isolated_lanes():"""Two sessions track lanes independently — no cross-contamination."""s1 = Session()diff --git a/browser/agent-harness/cli_anything/browser/utils/domshell_backend.py b/browser/agent-harness/cli_anything/browser/utils/domshell_backend.pyindex 7f5624c76..b5f6f84e8 100644--- a/browser/agent-harness/cli_anything/browser/utils/domshell_backend.py+++ b/browser/agent-harness/cli_anything/browser/utils/domshell_backend.py@@ -499,21 +499,26 @@ async def _call_execute(global _daemon_session, _daemon_read, _daemon_writearguments: dict[str, Any] = {"command": command}- # Lane handling for non-daemon mode: every fresh stdio ClientSession- # would otherwise be assigned a brand-new lane, scattering `page open`- # / `fs ls` / etc. across disjoint browser state. So we name the lane- # explicitly on every call:- # • subsequent calls → group_id=<previously captured lane id>- # • very first call → group_id="new" — DOMShell creates a fresh- # isolated lane and returns its id in the [lane: ...] marker,- # which `_capture_lane` stores on the session for next time.- # DOMShell 2.0.2 deprecated omitting `group_id` entirely (emits a- # [DEPRECATION] warning in the reply; hard error in 3.0.0). Passing- # "new" on the first call matches our actual intent — we want our own- # private lane, not the shared one — and silences the deprecation- # warning across every REPL session.+ # Lane handling. DOMShell 2.0.2 deprecated omitting `group_id`+ # (emits a [DEPRECATION] warning in the reply; hard error in 3.0.0),+ # so we name the lane explicitly on every call. Three cases:+ # • subsequent calls (session has captured lane) → reuse that lane.+ # • non-daemon first call → group_id="new" — DOMShell creates a+ # fresh isolated lane and returns its id in the [lane: ...]+ # marker, which `_capture_lane` stores on the session for next+ # time.+ # • daemon-mode first call without a Session → group_id="shared"+ # — the daemon's persistent connection has its own default lane+ # that stays sticky across calls, so direct (sessionless) daemon+ # workflows like `open_url(use_daemon=True)` followed by+ # `ls(use_daemon=True)` share browser state naturally. Using+ # "new" here would mint a fresh isolated lane per call and lose+ # the page just opened (Codex P2 regression caught on the+ # initial 2.0.2 migration commit be62f843b5).if session is not None and getattr(session, "domshell_lane_id", None):arguments["group_id"] = session.domshell_lane_id+ elif use_daemon:+ arguments["group_id"] = "shared"else:arguments["group_id"] = "new"