a2a/events: add tests for EventBusBridge overly broad contextlib.suppress(RuntimeError) swallowing non-queue-closed errors #10484

Open
opened 2026-04-18 10:05:49 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Commit message: test(a2a/events): add TDD tests for EventBusBridge contextlib.suppress(RuntimeError) overly broad suppression
  • Branch name: test/a2a-events-eventbusbridge-suppress-runtimeerror

Background and Context

EventBusBridge._on_domain_event() uses contextlib.suppress(RuntimeError) to swallow errors when publishing to a closed queue. However, this suppresses ALL RuntimeError exceptions, not just the "closed queue" one. Any programming error that raises RuntimeError during publish() (e.g., a bug in a subscriber callback) would be silently swallowed with no logging.

File: src/cleveragents/a2a/events.py, lines 308–311:

import contextlib

with contextlib.suppress(RuntimeError):
    self._event_queue.publish(a2a_event)

The only RuntimeError that publish() intentionally raises is:

def publish(self, event: A2aEvent) -> None:
    if self._is_closed:
        raise RuntimeError("Cannot publish to a closed event queue")

But contextlib.suppress(RuntimeError) also suppresses any other RuntimeError that might arise during the publish operation (e.g., from subscriber callbacks, from internal list operations, etc.).

Expected Behavior

  • When the event queue is closed, EventBusBridge._on_domain_event() should NOT raise and should log nothing (expected behavior).
  • When publish() raises a RuntimeError with a message OTHER than "Cannot publish to a closed event queue", the bridge should log a warning rather than silently swallowing it.
  • Only the specific "closed queue" RuntimeError should be suppressed; all other RuntimeError exceptions should propagate or be logged.

Acceptance Criteria

  • A test verifies that when the event queue is closed, EventBusBridge._on_domain_event() does not raise and logs nothing.
  • A test verifies that when publish() raises a RuntimeError with a message other than "Cannot publish to a closed event queue", the bridge logs a warning (not silently swallows it).
  • A test verifies that the bridge does not suppress non-RuntimeError exceptions from publish().
  • All tests tagged @tdd_expected_fail fail before the fix is applied.
  • All tests pass after the fix is applied.
  • nox -s unit_tests passes with coverage ≥ 97%.

Subtasks

  • Write test: bridge handles closed queue gracefully (no exception, no log)
  • Write test: bridge logs warning when non-closed-queue RuntimeError occurs during publish
  • Write test: bridge does not suppress non-RuntimeError exceptions from publish

Definition of Done

  • All tests tagged @tdd_expected_fail fail before the fix
  • All tests pass after the fix is applied
  • nox -s unit_tests passes with coverage ≥ 97%

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit message**: `test(a2a/events): add TDD tests for EventBusBridge contextlib.suppress(RuntimeError) overly broad suppression` - **Branch name**: `test/a2a-events-eventbusbridge-suppress-runtimeerror` ## Background and Context `EventBusBridge._on_domain_event()` uses `contextlib.suppress(RuntimeError)` to swallow errors when publishing to a closed queue. However, this suppresses ALL `RuntimeError` exceptions, not just the "closed queue" one. Any programming error that raises `RuntimeError` during `publish()` (e.g., a bug in a subscriber callback) would be silently swallowed with no logging. **File**: `src/cleveragents/a2a/events.py`, lines 308–311: ```python import contextlib with contextlib.suppress(RuntimeError): self._event_queue.publish(a2a_event) ``` The only `RuntimeError` that `publish()` intentionally raises is: ```python def publish(self, event: A2aEvent) -> None: if self._is_closed: raise RuntimeError("Cannot publish to a closed event queue") ``` But `contextlib.suppress(RuntimeError)` also suppresses any other `RuntimeError` that might arise during the publish operation (e.g., from subscriber callbacks, from internal list operations, etc.). ## Expected Behavior - When the event queue is closed, `EventBusBridge._on_domain_event()` should NOT raise and should log nothing (expected behavior). - When `publish()` raises a `RuntimeError` with a message OTHER than "Cannot publish to a closed event queue", the bridge should log a warning rather than silently swallowing it. - Only the specific "closed queue" `RuntimeError` should be suppressed; all other `RuntimeError` exceptions should propagate or be logged. ## Acceptance Criteria - [ ] A test verifies that when the event queue is closed, `EventBusBridge._on_domain_event()` does not raise and logs nothing. - [ ] A test verifies that when `publish()` raises a `RuntimeError` with a message other than "Cannot publish to a closed event queue", the bridge logs a warning (not silently swallows it). - [ ] A test verifies that the bridge does not suppress non-`RuntimeError` exceptions from `publish()`. - [ ] All tests tagged `@tdd_expected_fail` fail before the fix is applied. - [ ] All tests pass after the fix is applied. - [ ] `nox -s unit_tests` passes with coverage ≥ 97%. ## Subtasks - [ ] Write test: bridge handles closed queue gracefully (no exception, no log) - [ ] Write test: bridge logs warning when non-closed-queue RuntimeError occurs during publish - [ ] Write test: bridge does not suppress non-RuntimeError exceptions from publish ## Definition of Done - [ ] All tests tagged `@tdd_expected_fail` fail before the fix - [ ] All tests pass after the fix is applied - [ ] `nox -s unit_tests` passes with coverage ≥ 97% --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor --- **Automated by CleverAgents Bot** Agent: new-issue-creator
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.

Dependencies

No dependencies set.

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