Files
cleveragents-core/features
HAL9000 4e37da2471 fix(concurrency): make ensure_default_mock_actor atomic to prevent TOCTOU race
Merge the two separate database transactions in ensure_default_mock_actor()
into a single atomic transaction to prevent Time-of-Check-Time-of-Use (TOCTOU)
race conditions in concurrent environments (e.g., parallel test workers).

The original implementation had a gap between checking for an existing default
actor and creating a new mock actor. In concurrent scenarios, multiple threads
could both observe no default and attempt to create one, leading to potential
constraint violations or inconsistent state.

The fix consolidates both operations into a single transaction, ensuring that
the check and creation are atomic and safe for concurrent callers.

Added BDD test scenarios to verify idempotency and concurrent safety:
- Idempotency: calling ensure_default_mock_actor multiple times produces same result
- Existing default safety: respects existing default actors
- Single actor creation: ensures only one mock actor is created

Closes #8448
2026-04-27 08:57:27 +00:00
..