[FIX] Fix SyncEnvClient loop affinity issues and restore test/runtime compatibility#396
Open
burtenshaw wants to merge 7 commits intomainfrom
Open
[FIX] Fix SyncEnvClient loop affinity issues and restore test/runtime compatibility#396burtenshaw wants to merge 7 commits intomainfrom
burtenshaw wants to merge 7 commits intomainfrom
Conversation
Contributor
Greptile SummaryReplaced the Key changes:
Issues identified:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant SyncEnvClient
participant LoopThread as Background Loop Thread
participant AsyncClient as EnvClient (async)
participant Server
User->>SyncEnvClient: __init__(async_client)
Note over SyncEnvClient: _loop = None<br/>_loop_thread = None
User->>SyncEnvClient: connect() / __enter__()
SyncEnvClient->>SyncEnvClient: _ensure_loop()
alt Loop not started
SyncEnvClient->>LoopThread: Start thread (daemon=True)
LoopThread->>LoopThread: Create new event loop
LoopThread->>LoopThread: loop.run_forever()
LoopThread-->>SyncEnvClient: _loop_ready.set()
end
SyncEnvClient->>SyncEnvClient: _run(async_client.connect())
SyncEnvClient->>LoopThread: asyncio.run_coroutine_threadsafe(coro, loop)
LoopThread->>AsyncClient: connect()
AsyncClient->>Server: WebSocket connection
Server-->>AsyncClient: Connected
AsyncClient-->>LoopThread: Result
LoopThread-->>SyncEnvClient: future.result()
User->>SyncEnvClient: step(action)
SyncEnvClient->>SyncEnvClient: _run(async_client.step(action))
SyncEnvClient->>LoopThread: run_coroutine_threadsafe
LoopThread->>AsyncClient: step(action)
AsyncClient->>Server: Send action
Server-->>AsyncClient: StepResult
AsyncClient-->>LoopThread: Result
LoopThread-->>SyncEnvClient: future.result()
SyncEnvClient-->>User: StepResult
User->>SyncEnvClient: close() / __exit__()
SyncEnvClient->>SyncEnvClient: _run(async_client.close())
SyncEnvClient->>LoopThread: run_coroutine_threadsafe
LoopThread->>AsyncClient: close()
AsyncClient->>Server: Disconnect
Server-->>AsyncClient: Closed
AsyncClient-->>LoopThread: Done
LoopThread-->>SyncEnvClient: Complete
SyncEnvClient->>SyncEnvClient: _stop_loop()
SyncEnvClient->>LoopThread: loop.call_soon_threadsafe(loop.stop)
LoopThread->>LoopThread: loop.stop()
SyncEnvClient->>LoopThread: thread.join(timeout=5)
Note over SyncEnvClient,LoopThread: Cleanup complete
Last reviewed commit: a28ba18 |
Contributor
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/openenv/core/sync_client.py
Line: 48:52
Comment:
Outdated docstring references `run_async_safely()` which has been removed. Update to reflect the new dedicated event loop approach.
How can I resolve this? If you propose a fix, please make it concise. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR fixes cross-event-loop failures in synchronous client usage and resolves related test
collection/execution regressions across optional env modules and script utilities.
Problem
SyncEnvClient previously executed each async call independently, which can bind connection state (especially websockets) to one loop and then use it from another. This caused runtime errors like Future attached to a different loop in sync workflows.
In parallel, several tests failed due to:
Changes
Core sync client fix
sync calls.
Websocket integration tests
Optional dependency resilience
HF collection script compatibility