fix: prevent UnboundLocalError crash when delegate_tasks gets an unknown agent_id - #7
Open
Captain-Tripps wants to merge 1 commit into
Open
Captain-Tripps wants to merge 1 commit into
Captain-Tripps wants to merge 1 commit into
Conversation
…own agent_id _run_single_task() returns an error message early (before children_token is ever assigned) when the caller passes an agent_id that doesn't match any available sub-agent name. The finally block unconditionally calls available_sub_agents_ctx.reset(children_token) on the way out, which raises UnboundLocalError on that early-return path, replacing the intended graceful "Sub-agent named 'X' does not exist" response with an unhandled exception. This is easy to trigger in any agent with 2+ sibling sub-agents at the same delegation level, where the orchestrator LLM has to pick a target by exact name - a slightly wrong name (typo, case mismatch, hallucinated variant) is enough to hit it. Single-child delegation chains rarely exercise this path, which is likely why it hasn't surfaced before. Fix: initialize children_token = None before the try block and only reset it in finally if it was actually set.
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.
Summary
_run_single_task()returns an error message early (beforechildren_tokenis ever assigned) when the caller passes anagent_idthat doesn't match any available sub-agent name.finallyblock unconditionally callsavailable_sub_agents_ctx.reset(children_token)on the way out, which raisesUnboundLocalErroron that early-return path — replacing the intended graceful "Sub-agent named 'X' does not exist" response with an unhandled exception.Fix
Initialize
children_token = Nonebefore thetryblock and only reset it infinallyif it was actually set.Test plan
skills/local-agent-builder/examples/basic-tui-agent/src/engine/orchestrator.py) now returns the graceful error message instead of raising on an unknownagent_id.