You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
serialize first-time transport registration with double-checked locking
publish _discovered only after the complete import sweep, so concurrent lookups cannot observe partial registry state
leave discovery retryable when an unexpected transport import fails
add deterministic contention and failed-publication regression coverage
Root cause
_discover_transports() set _discovered = True before importing the transport modules. A concurrent caller could therefore skip the initial discovery path while the registry was only partially populated, then fall into the miss retry. The retry masked the race under normal startup but did not make publication atomic.
Testing
uv run pytest -q tests/agent/transports (242 passed)
concurrency regression file repeated 25 times
uv run ruff check agent/transports/__init__.py tests/agent/transports/test_transport_discovery_concurrency.py
uv run ruff format --check agent/transports/__init__.py tests/agent/transports/test_transport_discovery_concurrency.py
Credit to @wesleysimplicio for reporting the race and for the earlier closed reference implementation in #24692; this replacement is rebuilt and revalidated on current main.
CI classification: the sole Python failure is the known current-main baseline test test_profile_route_and_nonmultiplexed_resolution_preserve_boundaries. It rejects the unserved research profile and returns the default mode; #83745 is the exact focused correction and has a fully green required matrix. This branch only changes transport discovery and its tests, and all other 11 Python slices, the 242-test local transport suite, lints, OS-specific lanes, scans, attribution, and lock checks passed. I am keeping the unrelated gateway fixture correction out of this PR; rebasing after #83745 lands will absorb it.
alt-glitch
added
type/bug
Something isn't working
comp/agent
Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
P3
Low — cosmetic, nice to have
labels
Aug 11, 2026
AI code review — automated review for reference, author can ignore or act on any point.
fix(transports): serialize transport discovery
Good fix. Moving _discovered = True to the end also removes the previous "poisoned-on-failure" behavior (the flag was set before the imports, so a failed sweep left the registry permanently marked discovered), and the new failure test documents the retry semantics. Observations:
register_transport (invoked at module import during the sweep) and get_transport mutate/read _REGISTRY without the lock. Safe under the GIL for the discovery path, but a runtime plugin registering a transport concurrently with a sweep has no ordering guarantee. Consider taking _discover_lock in register_transport or documenting that registration must not run concurrently with discovery.
The lock is held across the whole 4-module import sweep and threading.Lock.acquire is blocking. If discovery is ever triggered lazily from an asyncio context while another thread holds the lock, the event loop stalls. At startup this is likely fine; if a mid-session lazy trigger is possible, run_in_executor or a non-blocking acquire would be safer.
Minor: a transport raising a non-ImportError now propagates on every get_transport call (since _discovered stays False and nothing caches the failure). Consider caching the failure or logging at most once per attempt to avoid error spam.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointP3Low — cosmetic, nice to havetype/bugSomething isn't working
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_discoveredonly after the complete import sweep, so concurrent lookups cannot observe partial registry stateRoot cause
_discover_transports()set_discovered = Truebefore importing the transport modules. A concurrent caller could therefore skip the initial discovery path while the registry was only partially populated, then fall into the miss retry. The retry masked the race under normal startup but did not make publication atomic.Testing
uv run pytest -q tests/agent/transports(242 passed)uv run ruff check agent/transports/__init__.py tests/agent/transports/test_transport_discovery_concurrency.pyuv run ruff format --check agent/transports/__init__.py tests/agent/transports/test_transport_discovery_concurrency.pyuv lock --checkgit diff --checkCloses #24687.
Credit to @wesleysimplicio for reporting the race and for the earlier closed reference implementation in #24692; this replacement is rebuilt and revalidated on current main.