BUG-HUNT: [concurrency] A2aEventQueue is not thread-safe #5907

Open
opened 2026-04-09 11:42:57 +00:00 by HAL9000 · 1 comment
Owner

Bug Report: [concurrency] — A2aEventQueue is not thread-safe

Severity Assessment

  • Impact: Race conditions can lead to data corruption, inconsistent state, or application crashes in a multi-threaded environment.
  • Likelihood: High, if the event queue is used by multiple threads concurrently.
  • Priority: High

Location

  • File: src/cleveragents/a2a/events.py
  • Function/Class: A2aEventQueue
  • Lines: 53-164

Description

The A2aEventQueue class is not thread-safe. The _events list and _subscriptions dictionary are accessed and modified without any locks. If multiple threads are publishing and subscribing to the queue at the same time, it could lead to race conditions. For example, one thread could be iterating over _subscriptions while another thread is adding or removing a subscription, which would raise a RuntimeError.

Evidence

The publish, subscribe_local, and unsubscribe methods all modify the _subscriptions dictionary without any locking mechanism. The publish method also modifies the _events list.

Expected Behavior

The A2aEventQueue class should be thread-safe. This can be achieved by using a threading.Lock to protect access to the shared _events and _subscriptions data structures.

Actual Behavior

The A2aEventQueue class is not thread-safe, which can lead to race conditions in a multi-threaded environment.

Suggested Fix

Use a threading.Lock to protect access to the _events and _subscriptions data structures. The lock should be acquired before accessing these data structures and released after the access is complete.

Category

concurrency

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be
created for TDD. The test will use tags: @tdd_issue, @tdd_issue_,
and @tdd_expected_fail to prove the bug exists before fixing it.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter

## Bug Report: [concurrency] — A2aEventQueue is not thread-safe ### Severity Assessment - **Impact**: Race conditions can lead to data corruption, inconsistent state, or application crashes in a multi-threaded environment. - **Likelihood**: High, if the event queue is used by multiple threads concurrently. - **Priority**: High ### Location - **File**: `src/cleveragents/a2a/events.py` - **Function/Class**: `A2aEventQueue` - **Lines**: 53-164 ### Description The `A2aEventQueue` class is not thread-safe. The `_events` list and `_subscriptions` dictionary are accessed and modified without any locks. If multiple threads are publishing and subscribing to the queue at the same time, it could lead to race conditions. For example, one thread could be iterating over `_subscriptions` while another thread is adding or removing a subscription, which would raise a `RuntimeError`. ### Evidence The `publish`, `subscribe_local`, and `unsubscribe` methods all modify the `_subscriptions` dictionary without any locking mechanism. The `publish` method also modifies the `_events` list. ### Expected Behavior The `A2aEventQueue` class should be thread-safe. This can be achieved by using a `threading.Lock` to protect access to the shared `_events` and `_subscriptions` data structures. ### Actual Behavior The `A2aEventQueue` class is not thread-safe, which can lead to race conditions in a multi-threaded environment. ### Suggested Fix Use a `threading.Lock` to protect access to the `_events` and `_subscriptions` data structures. The lock should be acquired before accessing these data structures and released after the access is complete. ### Category concurrency ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: High — Thread-safety in A2aEventQueue is critical for the A2A (Agent-to-Agent Protocol) implementation. The spec requires concurrent event handling for parallel plan execution (10+ concurrent subplans in v3.5.0). Race conditions in the event queue could cause data corruption and crashes in production.
  • Milestone: v3.5.0 — A2A event queue is core infrastructure for the autonomy hardening milestone.
  • Story Points: 5 — L size. Adding proper locking to a concurrent data structure requires careful analysis and testing.
  • MoSCoW: Must Have — Thread-safety is a correctness requirement, not an optimization. The v3.5.0 milestone requires parallel execution scaling to 10+ concurrent subplans, which depends on a thread-safe event queue.
  • Parent Epic: Needs linking to the A2A/Event System epic.

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: High — Thread-safety in `A2aEventQueue` is critical for the A2A (Agent-to-Agent Protocol) implementation. The spec requires concurrent event handling for parallel plan execution (10+ concurrent subplans in v3.5.0). Race conditions in the event queue could cause data corruption and crashes in production. - **Milestone**: v3.5.0 — A2A event queue is core infrastructure for the autonomy hardening milestone. - **Story Points**: 5 — L size. Adding proper locking to a concurrent data structure requires careful analysis and testing. - **MoSCoW**: Must Have — Thread-safety is a correctness requirement, not an optimization. The v3.5.0 milestone requires parallel execution scaling to 10+ concurrent subplans, which depends on a thread-safe event queue. - **Parent Epic**: Needs linking to the A2A/Event System epic. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 added this to the v3.5.0 milestone 2026-04-09 13:18:43 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#5907
No description provided.