Skip to content

fix(delegate): save parent tool names before child construction mutates global#2083

Merged
teknium1 merged 1 commit intoNousResearch:mainfrom
ygd58:fix/delegate-save-parent-tool-names-before-child-build
Mar 20, 2026
Merged

fix(delegate): save parent tool names before child construction mutates global#2083
teknium1 merged 1 commit intoNousResearch:mainfrom
ygd58:fix/delegate-save-parent-tool-names-before-child-build

Conversation

@ygd58
Copy link
Copy Markdown
Contributor

@ygd58 ygd58 commented Mar 19, 2026

Fixes #2079

Root Cause

The previous fix (#1804/#1894) moved _saved_tool_names into _run_single_child() to fix the NameError, but the save still captured the wrong value. _build_child_agent() calls AIAgent() which calls get_tool_definitions(), which overwrites model_tools._last_resolved_tool_names with the child's toolset. By the time _run_single_child() saves the global, it's already the child's tools — not the parent's.

Fix

  1. Save parent tool names before any child construction in delegate_task() at the top of the build loop
  2. Set correct value on each child via child._delegate_saved_tool_names = _parent_tool_names
  3. Authoritative restore after all children are built: _model_tools._last_resolved_tool_names = _parent_tool_names
  4. _run_single_child now reads from child._delegate_saved_tool_names (correct parent value)

Fixes Both Cases

  • Single task: Parent tools correctly restored after delegation
  • Batch mode: No race condition — each thread reads from its own child object, authoritative restore happens on main thread
@ygd58 ygd58 force-pushed the fix/delegate-save-parent-tool-names-before-child-build branch from ef927ae to 816d134 Compare March 19, 2026 19:27
@teknium1 teknium1 merged commit 493bf8d into NousResearch:main Mar 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants