Skip to content

Conversation

@alexhancock
Copy link
Collaborator

We need to disable subagents being able to create other subagents. It might be cleaner to not even advertise the tool, but looks like it would be a bigger refactor to do so

@tlongwell-block @DOsinga Let me know if this looks like a good fix to you for the immediate term

Demo:

Screenshot 2025-11-10 at 4 27 06 PM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds runtime protection to prevent subagents from creating nested subagent chains. When a subagent (identified by SessionType::SubAgent) attempts to call tools that would create other subagents, an INVALID_REQUEST error is returned instead.

  • Adds validation in dispatch_tool_call to block subagent creation tools when invoked from a subagent context
  • Blocks DYNAMIC_TASK_TOOL_NAME_PREFIX and SUBAGENT_EXECUTE_TASK_TOOL_NAME tools for subagents

Comment on lines +415 to +427
if session.session_type == crate::session::SessionType::SubAgent
&& (tool_call.name == DYNAMIC_TASK_TOOL_NAME_PREFIX
|| tool_call.name == SUBAGENT_EXECUTE_TASK_TOOL_NAME)
{
return (
request_id,
Err(ErrorData::new(
ErrorCode::INVALID_REQUEST,
"Subagents cannot create other subagents".to_string(),
None,
)),
);
}
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check doesn't prevent subagents from creating sub-recipe tasks, which also spawn subagents. Sub-recipe tools (with names like subrecipe__create_task_*) create sessions with SessionType::SubAgent and should also be blocked. Consider checking self.sub_recipe_manager.is_sub_recipe_tool(&tool_call.name) in addition to the existing conditions.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can go with this for now since we need something, but it should ideally be done in should_enabled_subagents I think

@alexhancock alexhancock merged commit d3f723d into main Nov 10, 2025
20 checks passed
jamadeo pushed a commit that referenced this pull request Nov 11, 2025
tiensi added a commit to tiensi/goose that referenced this pull request Nov 11, 2025
* main: (83 commits)
  silence copilot on minor text issues (block#5665)
  fix: disallow runaway subagent chains (block#5659)
  chore: remove usage of non-existent env var for log dir (block#5658)
  clarify agent instructions (block#5655)
  feat: add check-everything for unified style checks (block#5650)
  Show errors on failure (block#5643)
  custom instructions for copilot reviews (block#5646)
  fix: prevent repeated 404 errors when accessing deleted sessions (block#5644)
  Flake.nix corrected main (block#5600)
  fix: goose recipe list can return duplicated entries (block#5645)
  fix: bedrock creds refresh (block#5599)
  Fix Claude Code provider to default to Auto mode (block#5638) (block#5642)
  Scheduler cleanup (block#5571)
  Better search paths and handling of CLI providers (block#5554)
  docs: description required for "Add Extension" in cli - phase 2 (block#5635)
  Remove some logging (block#5631)
  Use session IDs as task IDs for subagents instead of UUIDs (block#5398)
  Fix the naming (block#5628)
  fix: default tetrate model is broken, replace with haiku-4.5 (block#5535) (block#5587)
  Fetch less and use the right SHA (block#5621)
  ...
michaelneale added a commit that referenced this pull request Nov 11, 2025
* main:
  silence copilot on minor text issues (#5665)
  fix: disallow runaway subagent chains (#5659)
  chore: remove usage of non-existent env var for log dir (#5658)
  clarify agent instructions (#5655)
  feat: add check-everything for unified style checks (#5650)
  Show errors on failure (#5643)
  custom instructions for copilot reviews (#5646)
  fix: prevent repeated 404 errors when accessing deleted sessions (#5644)
  Flake.nix corrected main (#5600)
  fix: goose recipe list can return duplicated entries (#5645)
  fix: bedrock creds refresh (#5599)
Surendhar-N-D pushed a commit to Surendhar-N-D/goose that referenced this pull request Nov 17, 2025
arul-cc pushed a commit to arul-cc/goose that referenced this pull request Nov 17, 2025
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Nov 29, 2025
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.

3 participants