fix(delegate): respect model selection for sub-agents (fixes #12440)#12503
Open
PratikRai0101 wants to merge 3 commits into
Open
fix(delegate): respect model selection for sub-agents (fixes #12440)#12503PratikRai0101 wants to merge 3 commits into
PratikRai0101 wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes the context-length errors occurring during delegation by ensuring delegate_task honors explicitly configured models for sub-agents.
It enforces a strict model selection precedence: acp_args → HERMES_MODEL env var → config.delegation.model. The selected model is safely forwarded to the child process via both CLI argument injection (--model) and a defensive fallback in the child's os.environ.
Related Issue
Fixes #12440
Type of Change
[x] 🐛 Bug fix (non-breaking change that fixes an issue)
[ ] ✨ New feature (non-breaking change that adds functionality)
[ ] 🔒 Security fix
[ ] 📝 Documentation update
[x] ✅ Tests (adding or improving test coverage)
[ ] ♻️ Refactor (no behavior change)
[ ] 🎯 New skill (bundled or hub)
Changes Made
tools/delegate_tool.py: Extracted the ACP subprocess spawning logic into a dedicated _launch_subagent function. Wired it into the delegate_task execution path for ACP-backed children. Ensured subprocess.run executes securely using lists (strictly no shell=True).
tests/tools/test_delegate_model_forwarding.py: Added a new test suite utilizing pytest and monkeypatch to intercept the subprocess.run call. Tests validate precedence logic, flag parsing (--model, -m, --model=), and environment injection without actual execution.
How to Test
Unit Tests: Run pytest tests/tools/test_delegate_model_forwarding.py -v. Ensure all 8 parametrized mocks pass.
Precedence Validation: Set delegation.model in config.yaml to one model, export HERMES_MODEL as another, and pass a third via acp_args. Trigger a sub-agent spawn and verify via process logs that the acp_args model wins the collision.
Regression Check: Run pytest tests/tools/test_delegate_toolset_scope.py to ensure existing delegation logic remains unbroken.
Checklist
Code
[x] I've read the Contributing Guide
[x] My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
[x] I searched for existing PRs to make sure this isn't a duplicate
[x] My PR contains only changes related to this fix/feature (no unrelated commits)
[x] I've run pytest tests/ -q and all tests pass (Note: Delegation-specific tests pass locally. The ~72 failures in the full suite are due to upstream baseline drift, e.g., Camofox config schema version bumps, unrelated to this PR).
[x] I've added tests for my changes (required for bug fixes, strongly encouraged for features)
[x] I've tested on my platform: Arch Linux
Documentation & Housekeeping
[x] I've updated relevant documentation (README, docs/, docstrings) — or N/A
[x] I've updated cli-config.yaml.example if I added/changed config keys — or N/A
[x] I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
[x] I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
[x] I've updated tool descriptions/schemas if I changed tool behavior — or N/A
Screenshots / Logs
Test Execution Output:
$ ./venv/bin/pytest tests/tools/test_delegate_model_forwarding.py -q -r a
........ [100%] 8 passed in 0.84s