Skip to content

[Bug]: Concurrent commands for the same site can fail with "Detached while handling command" #1114

@Henry-G-H-Huang

Description

@Henry-G-H-Huang

Description

Summary

Running multiple opencli commands concurrently for the same site can fail with:

Detached while handling command.

This appears to be caused by browser workspace reuse across commands for the same site.

Environment

  • opencli version: 1.7.5
  • Node.js version: v24.14.0
  • OS: Ubuntu 22.04.1 LTS (Jammy Jellyfish) on WSL2
  • Kernel: Linux 6.6.87.2-microsoft-standard-WSL2
  • Browser Bridge extension installed: yes
  • Extension version: 1.0.0
  • Extension compatibility range reported by daemon: >=1.7.0

Root Cause Analysis

From local investigation, this seems to happen because:

  1. execution.js creates browser sessions with a shared workspace key based only on site:
    workspace: site:${cmd.site}

  2. Command execution later closes the automation window:
    await page.closeWindow?.()

  3. When two commands for the same site run concurrently, they appear to share the same workspace/window.
    If one command finishes first and closes the window, the other command may still be in goto() or evaluate(), and then fails with:
    Detached while handling command

Relevant code path from local inspection:

  • dist/src/execution.js
  • browser session uses workspace: site:${cmd.site}
  • command completion calls page.closeWindow?.()

Suggested Fix

Use a unique workspace per command execution instead of sharing by site for one-shot adapter commands.
For example, instead of:
workspace: site:${cmd.site}
something like:
workspace: site:${cmd.site}:cmd:${process.pid}:${Date.now()}
or another per-execution unique identifier.
This would prevent concurrent commands from closing each other's automation window.

Notes

This is particularly important for AI-agent scenarios, where parallel tool execution is common and expected.

Steps to Reproduce

  1. Ensure the Browser Bridge extension is connected and opencli browser-backed commands work normally.
  2. Run two commands concurrently for the same site, for example:
    OPENCLI_DIAGNOSTIC=1 opencli alm story ST645503 --tasks --format json &
    OPENCLI_DIAGNOSTIC=1 opencli alm story ST645503 --tasks --format json &
    wait
  3. Observe that one command may succeed while the other fails.
  4. The failing command reports an error similar to:

Expected Behavior

Concurrent commands for the same site should not interfere with each other. Both commands should complete successfully.

OpenCLI Version

1.7.5

Node.js Version

22.x

Operating System

Linux

Logs / Screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions