Skip to content

fix(tools): make DaemonThreadPoolExecutor compatible with Python 3.14 - #81569

Closed
Ufonik88 wants to merge 1 commit into
NousResearch:mainfrom
Ufonik88:fix/daemon-pool-py314
Closed

fix(tools): make DaemonThreadPoolExecutor compatible with Python 3.14#81569
Ufonik88 wants to merge 1 commit into
NousResearch:mainfrom
Ufonik88:fix/daemon-pool-py314

Conversation

@Ufonik88

@Ufonik88 Ufonik88 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

DaemonThreadPoolExecutor._adjust_thread_count (used for parallel tool execution and subagent timeout wrappers) reads self._initializer / self._initargs directly. Python 3.14 refactored concurrent.futures.thread: ThreadPoolExecutor.__init__ no longer stores those attributes — the initializer now lives in a WorkerContext produced by _create_worker_context(), and _worker's signature became (executor_reference, ctx, work_queue).

On 3.14 every concurrent tool batch fails at the first worker spawn:

AttributeError: 'DaemonThreadPoolExecutor' object has no attribute '_initializer'

This breaks any parallel tool batch (skill_view/search_files/read_file/patch fan-out, cron job runs, subagent submit) on interpreters where the venv resolved to Python 3.14.

Root cause

tools/daemon_pool.py, _adjust_thread_count — worker args tuple hard-coded self._initializer, self._initargs, which only exist on Python ≤3.13.

Fix

Route worker args through a new _daemon_worker_args() helper that adapts to the running interpreter:

  • 3.14+: build the WorkerContext via executor._create_worker_context() and pass (weakref, ctx, work_queue).
  • 3.8–3.13: keep the legacy (weakref, work_queue, initializer, initargs) tuple, using getattr so missing attrs degrade safely.

All call sites (tools/async_delegation.py, tools/skills_hub.py, tools/delegate_tool.py) share the one fixed class, so the whole bug class is covered.

Verification

  • tests/tools/test_daemon_pool.py — 3 passed on Python 3.14.4 (the existing tests exercise worker spawn, which is exactly the failing path).
  • Manual: submit batches with and without an initializer/initargs on 3.14.4 — results correct, initializer runs once per worker.
  • Live repro: parallel tool batches in the running gateway failed with the AttributeError before the fix and complete normally after.

… worker context

Python 3.14 refactored concurrent.futures.thread: ThreadPoolExecutor no
longer sets self._initializer/_initargs — the initializer now lives in a
WorkerContext created via _create_worker_context(), and _worker's
signature became (executor_reference, ctx, work_queue).

The old _adjust_thread_count passed self._initializer directly, so any
concurrent tool batch (parallel skill_view/search_files/read_file/patch,
cron job runs) raised:
  AttributeError: 'DaemonThreadPoolExecutor' object has no attribute '_initializer'

Route worker args through _daemon_worker_args() which adapts to the
running interpreter: 3.14+ builds a WorkerContext via
_create_worker_context(); 3.8-3.13 keeps the (initializer, initargs)
tuple, using getattr so missing attrs degrade safely. Verified with
tests/tools/test_daemon_pool.py (3 passed) plus manual submit/initializer
checks on Python 3.14.4.
@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades duplicate This issue or pull request already exists labels Aug 8, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #65182: both implement the same Python 3.14 WorkerContext/_worker compatibility repair in tools/daemon_pool.py. #65182 is the earlier open implementation.

@Ufonik88 Ufonik88 closed this Aug 9, 2026
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 sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants