Skip to content

fix(tools): adapt DaemonThreadPoolExecutor for Python 3.14 _worker signature - #58598

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-58596-daemon-pool-py314
Closed

fix(tools): adapt DaemonThreadPoolExecutor for Python 3.14 _worker signature#58598
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-58596-daemon-pool-py314

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes DaemonThreadPoolExecutor crash on Python 3.14 where _adjust_thread_count() references self._initializer and self._initargs, which no longer exist. Python 3.14 changed concurrent.futures.thread._worker from 4 params to 3, replacing (initializer, initargs) with a WorkerContext object created via self._create_worker_context().

Related Issue

Fixes #58596

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • tools/daemon_pool.py: Detect _worker signature at import time (inspect.signature, 3 vs 4 params) and branch _adjust_thread_count args accordingly. Python ≥3.14 passes self._create_worker_context() as the ctx argument; ≤3.13 passes self._initializer/self._initargs.
  • tests/tools/test_daemon_pool.py: Added test_worker_signature_detection_matches_runtime (verifies _WORKER_USES_CTX matches runtime _worker param count) and test_concurrent_submit_with_context_path (10 concurrent submits under the ctx-based path).

How to Test

  1. Run python -m pytest tests/tools/test_daemon_pool.py -v — all 6 tests should pass
  2. On Python 3.14: python -c "from tools.daemon_pool import DaemonThreadPoolExecutor; e = DaemonThreadPoolExecutor(max_workers=1); print(e.submit(lambda: 42).result())" should print 42 (previously crashed with AttributeError)
  3. On Python ≤3.13: same tests pass via the legacy 4-param _worker path

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/tools/test_daemon_pool.py -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 26, Python 3.14.0

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 — N/A (stdlib change is cross-platform)
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

…gnature

Python 3.14 changed concurrent.futures.thread._worker from 4 params
(executor_ref, work_queue, initializer, initargs) to 3 params
(executor_ref, ctx, work_queue), replacing instance-level
self._initializer/self._initargs with a WorkerContext created via
self._create_worker_context().

Detect the signature at import time via inspect.signature and branch
_args accordingly. Preserves daemon=True and no _threads_queues
registration semantics.

Fixes NousResearch#58596
@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 Jul 5, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #57459 — both PRs fix the same crash in tools/daemon_pool.py _adjust_thread_count (Python 3.14 removed _initializer/_initargs and changed _worker from 4 to 3 params). #57459 (created 2026-07-03, earlier) is canonical; it uses a getattr fallback, this PR uses an inspect.signature branch — same code-site, same goal, so the mechanism difference doesn't make this a separate fix.

Related: #58596 (the issue), #50077 / #47634 (same 3.14 theme but a different file, tools/async_delegation.py).

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing as a self-duplicate of #57459 — both fix the same DaemonThreadPoolExecutor crash on Python 3.14 (_initializer/_initargs removed). #57459 uses getattr fallback (simpler, already open since 2026-07-03); this PR uses inspect.signature branching (more thorough but same fix site). The getattr approach is sufficient since the fallback to None matches CPython's new behavior.

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.

DaemonThreadPoolExecutor crashes on Python 3.14: _initializer attribute removed

2 participants