𝗠𝘆 𝗧𝘄𝗼 𝗔𝗜 𝗧𝗮𝘀𝗸𝘀 𝗞𝗲𝗽𝘁 𝗙𝗶𝗴𝗵𝘁𝗶𝗻𝗴 𝗳𝗼𝗿 𝘁𝗵𝗲 𝗦𝗮𝗺𝗲 𝗠𝗼𝘂𝘀𝗲

Parallel agent demos look great. They fail the moment two tasks try to use the same mouse.

One task logs into a site. Another opens a browser. A third task asks for a status update. Suddenly, the system clicks the wrong place or cancels the wrong run. This is not a logic error. It is resource contention.

I learned this while building CliGate, my local control plane for desktop automation.

Parallelism works for code. You can run a weather lookup while a runtime session works. A background summary does not need to block anything.

The desktop is different. You have one physical keyboard, one mouse, and one screen. If two agents try to own that surface, they sabotage each other.

My first instinct was to cancel the old task when a new one arrived. This was wrong. A user asking "how far did it get?" should not kill a login flow.

I stopped treating concurrency as a prompt problem. It is a resource problem.

I implemented three simple rules:

  • Independent tasks run in parallel.
  • Tasks needing the desktop must queue.
  • Cancellation only happens when a user asks for it.

In CliGate, desktop input works like a lease. A task that uses the mouse becomes the desktop holder. Other tasks must wait.

The new logic follows this flow:

  • A new task arrives.
  • Does it need the desktop?
  • If no, run it in parallel.
  • If yes and the desktop is free, take it.
  • If yes and the desktop is busy, queue it.
  • Only cancel if the user says stop.

Retries often make desktop automation worse. If a second task keeps trying to grab the mouse, it increases interference. Instead of retrying harder, the assistant should say: "The desktop is busy. I am in the queue. I will start when it is free."

This turns a failure into predictable behavior.

I also added a hard rule: an agent cannot cancel its own active run. This prevents the agent from panic-clicking its own off switch.

Bad AI behavior often comes from trying to be too clever. Users need something much simpler:

  • Run tasks that do not conflict.
  • Queue tasks that conflict over physical resources.
  • Answer status questions from the status logs.
  • Stop when the user says stop.

If you build AI tools that touch the desktop, remember this: parallel tasks are fine, but physical resources need clear ownership.

Source: https://dev.to/codekingai/my-two-ai-tasks-kept-fighting-for-the-same-mouse-1hij