Skip to content

fix(tools): adapt daemon_pool to Python 3.14 ThreadPoolExecutor internals - #83227

Open
yjslzx wants to merge 1 commit into
NousResearch:mainfrom
yjslzx:fix/daemon-pool-py314
Open

fix(tools): adapt daemon_pool to Python 3.14 ThreadPoolExecutor internals#83227
yjslzx wants to merge 1 commit into
NousResearch:mainfrom
yjslzx:fix/daemon-pool-py314

Conversation

@yjslzx

@yjslzx yjslzx commented Aug 10, 2026

Copy link
Copy Markdown

Problem

On Python 3.14, concurrent.futures.ThreadPoolExecutor was reworked: __init__ no longer stores self._initializer/self._initargs, and _worker's signature changed to (executor_reference, ctx, work_queue) with initializer state carried in a per-worker context from prepare_context().

DaemonThreadPoolExecutor._adjust_thread_count (in tools/daemon_pool.py) was mirroring the CPython 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, hence the flaky appearance).

Fix

Detect the 3.14 layout at runtime (hasattr(self, "_create_worker_context")) and build _worker args accordingly, preserving the daemon=True / no-_threads_queues-registration behavior on both code paths. Behavior on 3.8–3.13 is unchanged.

Verification

scripts/run_tests.sh on Python 3.14.4:

  • tests/tools/test_daemon_pool.py — 3 passed
  • tests/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_queues non-registration all verified.

…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).
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/tools Tool registry, model_tools, toolsets duplicate This issue or pull request already exists labels Aug 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #65182: both patch the same DaemonThreadPoolExecutor._adjust_thread_count CPython 3.14 WorkerContext/_worker argument-contract change. #65182 is the earlier open canonical implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants