fix(tools): adapt daemon_pool to Python 3.14 ThreadPoolExecutor internals - #83227
Open
yjslzx wants to merge 1 commit into
Open
fix(tools): adapt daemon_pool to Python 3.14 ThreadPoolExecutor internals#83227yjslzx wants to merge 1 commit into
yjslzx wants to merge 1 commit into
Conversation
…nals
Python 3.14 reworked ThreadPoolExecutor: __init__ no longer stores
self._initializer/_initargs, and _worker's signature became
(executor_reference, ctx, work_queue) with initializer state carried in a
per-worker context from prepare_context().
_adjust_thread_count mirrored the 3.8-3.13 internals, so spawning a new
worker on 3.14 raised AttributeError ('DaemonThreadPoolExecutor' object
has no attribute '_initializer'), breaking concurrent tool execution
intermittently (only when the pool needed a fresh thread).
Detect the 3.14 layout at runtime and build _worker args accordingly,
preserving the daemon=True / no-_threads_queues behavior on both paths.
Verified via scripts/run_tests.sh on 3.14.4:
tests/tools/test_daemon_pool.py (3 passed) and
tests/agent/test_compress_context_progress_timeout.py (15 passed).
Collaborator
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.
Problem
On Python 3.14,
concurrent.futures.ThreadPoolExecutorwas reworked:__init__no longer storesself._initializer/self._initargs, and_worker's signature changed to(executor_reference, ctx, work_queue)with initializer state carried in a per-worker context fromprepare_context().DaemonThreadPoolExecutor._adjust_thread_count(intools/daemon_pool.py) was mirroring the CPython 3.8–3.13 internals, so spawning a new worker on 3.14 raisedAttributeError: 'DaemonThreadPoolExecutor' object has no attribute '_initializer'— breaking concurrent tool execution intermittently (only when the pool needed a fresh thread, hence the flaky appearance).Fix
Detect the 3.14 layout at runtime (
hasattr(self, "_create_worker_context")) and build_workerargs accordingly, preserving thedaemon=True/ no-_threads_queues-registration behavior on both code paths. Behavior on 3.8–3.13 is unchanged.Verification
scripts/run_tests.shon Python 3.14.4:tests/tools/test_daemon_pool.py— 3 passedtests/agent/test_compress_context_progress_timeout.py— 15 passed (indirect user of the daemon pool, timeout path)Also exercised manually: basic execution,
initializer=propagation, 8 tasks / 4 workers concurrency, daemon flag and_threads_queuesnon-registration all verified.