Skip to content

fix(tools): DaemonThreadPoolExecutor Python 3.14 compatibility - #59897

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-59896
Closed

fix(tools): DaemonThreadPoolExecutor Python 3.14 compatibility#59897
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-59896

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes DaemonThreadPoolExecutor on Python 3.14, where all parallel tool calls fail with AttributeError: 'DaemonThreadPoolExecutor' object has no attribute '_initializer'.

Python 3.14 reworked ThreadPoolExecutor internals: it replaced the _initializer / _initargs attributes with a WorkerContext pattern and changed _worker's signature from (ref, work_queue, initializer, initargs) to (ref, ctx, work_queue).

This PR adds a runtime version probe (hasattr(self, "_create_worker_context")) and uses the new API on Python 3.14+ while falling back to the old API on older versions. The fix is minimal, focused on the single method that creates worker threads.

Related Issue

Fixes #59896

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • tools/daemon_pool.py: Add runtime version probe in _adjust_thread_count(). Use _create_worker_context() on Python 3.14+, fall back to _initializer/_initargs on <3.14.
  • tests/tools/test_daemon_pool.py: Add regression test test_initializer_args_passed_on_python_314_plus() to verify initializer args are correctly passed on both Python versions.

How to Test

  1. On Python 3.14 (or 3.13), run the new test:

    pytest tests/tools/test_daemon_pool.py::test_initializer_args_passed_on_python_314_plus -v

    Should pass with initializer called and task result correct.

  2. Run full daemon pool test suite:

    pytest tests/tools/test_daemon_pool.py -v

    All 5 tests should pass.

  3. Verify parallel tool calls work (e.g., batched search_files, delegate_task):

    hermes "Run two search_files calls in parallel"

    Observed result: both calls execute successfully without AttributeError.

Checklist

Code

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

This PR does not add a skill.

Screenshots / Logs

Test output:

$ pytest tests/tools/test_daemon_pool.py -q
.....                                                                    [100%]
5 passed in 0.77s

Python 3.14 reworked ThreadPoolExecutor internals:
_replaced _initializer/_initargs attributes with WorkerContext
changed _worker signature from (ref, work_queue, initializer, initargs)
to (ref, ctx, work_queue) on 3.14+

This broke DaemonThreadPoolExecutor which mirrored the 3.8-3.13
implementation, causing AttributeError on every parallel tool call.

Fix: runtime version probe (hasattr _create_worker_context).
Use new API on 3.14+, fall back to old API on <3.14.

Fixes NousResearch#59896
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #57459 (earliest-open fix for the same Python 3.14 _initializer removal at the same _adjust_thread_count site in tools/daemon_pool.py). The hasattr version-probe here vs #57459's getattr fallback is a minor mechanism difference; canonical is the earliest open PR. Fixes #58596/#59896.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing this PR as a duplicate of #57459, which fixes the same Python 3.14 _initializer/_initargs bug with an earlier submission and a simpler getattr fallback approach.

Both PRs address DaemonThreadPoolExecutor Python 3.14 compatibility, but #57459's solution is more minimal and backward-compatible:

The getattr approach works across Python versions without requiring runtime detection, and is already being reviewed.

Fixes #59896 / #58596 (duplicate issues for the same bug).

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint 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.

[Bug] DaemonThreadPoolExecutor breaks on Python 3.14 — parallel tool calls fail with AttributeError

2 participants