Skip to content

fix: prevent UnboundLocalError crash when delegate_tasks gets an unknown agent_id - #7

Open
Captain-Tripps wants to merge 1 commit into
kyuz0:mainfrom
Captain-Tripps:fix/delegate-tasks-unboundlocalerror
Open

Captain-Tripps wants to merge 1 commit into
kyuz0:mainfrom
Captain-Tripps:fix/delegate-tasks-unboundlocalerror

Conversation

@Captain-Tripps

Copy link
Copy Markdown

Summary

  • _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.

Test plan

  • Confirmed the affected code path (skills/local-agent-builder/examples/basic-tui-agent/src/engine/orchestrator.py) now returns the graceful error message instead of raising on an unknown agent_id.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant