Context
The bridge daemon uses osascript to inject A2A messages into IDEs. When multiple agents have wake events simultaneously, the daemon dispatches all osascript calls concurrently.
The Problem
Concurrent osascript calls racing to steal focus and type keystrokes cause a desktop environment collision (the "Electron-Paradox"). Payloads interleave or get injected into the wrong IDE window depending on millisecond-level focus stealing. This leads to cross-tenant data leakage (e.g., Claude receiving Gemini's payload).
The Architectural Reality
The ai/scripts/bridge-daemon.mjs script's deliverDigest loops through all matched subscriptions and executes osascript child processes asynchronously without any mutual exclusion.
The Fix
Add an asynchronous Promise mutex (deliveryPromise) inside bridge-daemon.mjs to force the deliveries into sequential execution.
Acceptance Criteria
deliverDigest uses a global Promise.resolve() chain to serialize AppleScript injection.
- Concurrent broadcast events no longer cause payload corruption or interleaved typing.
Out of Scope
Fixing the intrinsic human "focus switching" problem during sequential execution (e.g., if a human user actively clicks into a different window while osascript is typing).
Origin Session ID
Origin Session ID: 7f5dd104-283b-4c52-96d3-8ca4a9e7353e
Retrieval Hint: "bridge-daemon serialization mutex"
Context The bridge daemon uses
osascriptto inject A2A messages into IDEs. When multiple agents have wake events simultaneously, the daemon dispatches allosascriptcalls concurrently.The Problem Concurrent
osascriptcalls racing to steal focus and type keystrokes cause a desktop environment collision (the "Electron-Paradox"). Payloads interleave or get injected into the wrong IDE window depending on millisecond-level focus stealing. This leads to cross-tenant data leakage (e.g., Claude receiving Gemini's payload).The Architectural Reality The
ai/scripts/bridge-daemon.mjsscript'sdeliverDigestloops through all matched subscriptions and executesosascriptchild processes asynchronously without any mutual exclusion.The Fix Add an asynchronous Promise mutex (
deliveryPromise) insidebridge-daemon.mjsto force the deliveries into sequential execution.Acceptance Criteria
deliverDigestuses a globalPromise.resolve()chain to serialize AppleScript injection.Out of Scope Fixing the intrinsic human "focus switching" problem during sequential execution (e.g., if a human user actively clicks into a different window while
osascriptis typing).Origin Session ID Origin Session ID: 7f5dd104-283b-4c52-96d3-8ca4a9e7353e Retrieval Hint: "bridge-daemon serialization mutex"