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

Parallel agent demos look great until two tasks try to use the same mouse.

One task logs into a site. Another opens a browser. A third task tries to answer a simple question. Suddenly, the system clicks the wrong place or reports a failure. This is not an intelligence problem. It is a resource problem.

While building CliGate, I learned a hard lesson about desktop automation.

Code tasks can run in parallel. You can look up the weather while a runtime session works. Background summaries do not need to block anything.

The desktop is different. You have one keyboard, one mouse, and one screen. If two agents think they 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. A user asking for the weather should not stop a desktop task. The worst bug happens when an agent sees another active run and accidentally cancels itself.

I had to stop treating concurrency as a prompt problem. I had to treat it as a resource problem.

I set three new rules:

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

In CliGate, desktop input works like a lease. If a task uses the mouse, it holds the lease. 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 when the user says stop.

This change turned confusing failures into predictable behavior. Instead of retrying a click and causing more interference, the assistant now says the truth: "The desktop is busy. I am queued and will start when it is free."

I also added a rule to prevent self-cancellation. An agent must never list its own active run as a target to cancel.

Building AI tooling often fails when you try to be too clever. Users do not need magic. They need simple logic:

  • If tasks do not conflict, let them run.
  • If they conflict over a physical resource, queue them.
  • If the user asks for status, provide it.
  • If the user says stop, stop.

If your AI touches the desktop, remember this: parallel tasks are fine, but physical resources need ownership.

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