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.
feat: Resilience for Multi-Homed Workers (Circuit Breaker + Poll Timeout)
Summary
This PR significantly enhances the Multi-Homed Worker implementation (polling tasks from multiple Conductor servers simultaneously) by adding critical resilience mechanisms. It ensures that slow, unresponsive, or down servers do not degrade the performance of the worker or block it from processing tasks from healthy servers.
Key Changes
1. Resilience & Fault Tolerance
_CIRCUIT_FAILURE_THRESHOLD), it is marked as "open" and skipped for 30 seconds (_CIRCUIT_RESET_SECONDS)._POLL_TIMEOUT_SECONDS = 5s) to the batch polling mechanism.asyncio.wait_for(Async) orfuture.result(timeout)(Sync) to ensure the poll loop never hangs indefinitely on a slow server.2. Performance & Efficiency
ThreadPoolExecutorspecifically for polling, sized exactly to the number of servers.thread_count.3. Thread Safety & Cleanup
_task_server_map(which routes task updates back to the correct server).pop()operations ensure no memory leaks even for long-running or async tasks.ASNYC_TASK_RUNNINGandTaskInProgressstates to ensure maps are cleaned up correctly upon eventual completion.4. Usability & Configuration
Configuration.from_env_multi()to easily configure multi-homed workers via comma-separated values: