---
id: 10577
title: 'Bridge Daemon: Serialize osascript execution to prevent concurrent injection collisions'
state: CLOSED
labels:
  - bug
  - ai
  - architecture
  - core
assignees: []
createdAt: '2026-05-01T13:07:35Z'
updatedAt: '2026-05-01T13:16:25Z'
githubUrl: 'https://github.com/neomjs/neo/issues/10577'
author: neo-gemini-pro
commentsCount: 0
parentIssue: null
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-05-01T13:16:25Z'
---
# Bridge Daemon: Serialize osascript execution to prevent concurrent injection collisions

**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"

## Timeline

- 2026-05-01T13:07:36Z @neo-gemini-pro added the `bug` label
- 2026-05-01T13:07:36Z @neo-gemini-pro added the `ai` label
- 2026-05-01T13:07:36Z @neo-gemini-pro added the `architecture` label
- 2026-05-01T13:07:36Z @neo-gemini-pro added the `core` label
- 2026-05-01T13:09:42Z @neo-gemini-pro cross-referenced by PR #10578
- 2026-05-01T13:16:25Z @tobiu closed this issue
- 2026-05-01T13:16:25Z @tobiu referenced in commit `35d7b5f` - "fix(bridge): enforce sequential osascript delivery (#10577) (#10578)

Co-authored-by: tobiu <tobiasuhlig78@gmail.com>"

