Skip to content

perf(browser): consolidate per-wrapper asyncio.run() calls into a single inner async function #339

Description

@apireno

Each wrapper (`ls`, `cat`, `click`, `type_text`, `grep`, etc.) in `cli_anything/browser/utils/domshell_backend.py` currently calls `asyncio.run(_call_execute(...))` 2–4 times in sequence (anchor → operation → restore for split-and-check wrappers; up to 4 calls for `type_text`'s focus/type sequence). Each call creates and tears down its own event loop.

Recommendation: refactor each wrapper to wrap an `async def _impl(): ...` in a single `asyncio.run(...)` so the loop is created once per wrapper invocation. Behavior unchanged; cleaner foundation for any future async-native API.

Scope:

  • 10ish wrappers in `domshell_backend.py`
  • No CLI-level changes needed (wrappers remain sync)
  • Existing tests should pass without modification

Surfaced by: Copilot R4 on PR #308 commit `5790651` and addressed via R4 cleanup commit `a87647e` deferring this item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    existing-cli-fixFixes or improves an existing CLI harness

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions