Fix race condition in McpClient.start() double initialization #10892

Merged
HAL9000 merged 2 commits from bugfix/mcp-race-condition-start into master 2026-06-10 15:32:55 +00:00

2 Commits

Author SHA1 Message Date
HAL9000 bcf1eb9100 fix(test): resolve lint errors and remove tdd_expected_fail after #10438 fix
CI / push-validation (pull_request) Successful in 25s
CI / build (pull_request) Successful in 41s
CI / lint (pull_request) Successful in 48s
CI / quality (pull_request) Successful in 47s
CI / helm (pull_request) Successful in 46s
CI / typecheck (pull_request) Successful in 58s
CI / security (pull_request) Successful in 1m33s
CI / unit_tests (pull_request) Successful in 6m44s
CI / integration_tests (pull_request) Successful in 10m30s
CI / docker (pull_request) Successful in 1m45s
CI / coverage (pull_request) Successful in 10m23s
CI / status-check (pull_request) Successful in 4s
- Move MockMCPTransport import to module level in counting_mcp_transport.py,
  removing the noqa: PLC0415 suppression that caused RUF100 (unused noqa)
- Remove dead `if TYPE_CHECKING: pass` block and unused TYPE_CHECKING import
- Remove unused `from typing import Any` in race condition step definitions (F401)
- Fix excess blank lines (3 → 2) between imports and first section in step file
- Remove @tdd_expected_fail tag from tdd_mcp_client_start_race.feature; the
  bug is fixed so the scenario now passes, and the file's own comment states
  the tag must be removed when #10438 is resolved

ISSUES CLOSED: #10438
2026-06-10 11:14:45 -04:00
freemo 33cf919e7b Fix race condition in McpClient.start() double initialization
Add _state == McpClientState.STARTING guard inside the threading.RLock in
start() and _ensure_started() so that concurrent callers see the in-progress
state and return immediately, preventing double initialisation of the MCP
server connection.

- Move _CountingTransport test double from inline step file to dedicated
  features/mocks/counting_mcp_transport.py per CONTRIBUTING.md mock placement rules
- Updated step definitions to import CountingMCPTransport from new location
- Added Race condition entry to CHANGELOG under [Unreleased] -> Fixed
- Added contributor credit for McpClient race condition fix

ISSUES CLOSED: #10438
2026-06-10 11:14:45 -04:00