Skip to content

fix(delegate-task): prevent infinite loop when both category and subagent_type provided#2934

Closed
guazi04 wants to merge 1 commit intocode-yeongyu:devfrom
guazi04:fix/category-subagent-loop-upstream
Closed

fix(delegate-task): prevent infinite loop when both category and subagent_type provided#2934
guazi04 wants to merge 1 commit intocode-yeongyu:devfrom
guazi04:fix/category-subagent-loop-upstream

Conversation

@guazi04
Copy link
Copy Markdown
Contributor

@guazi04 guazi04 commented Mar 29, 2026

Problem

When models pass both category and subagent_type to the task() tool, the current code throws an error. Models then retry with the same parameters, creating an infinite loop that wastes tokens and blocks execution.

Root cause

  1. Tool description mentions "Sisyphus-Junior" twice in the category context (lines 76, 82), causing models to associate category with sisyphus-junior and pass both parameters
  2. Description/behavior inconsistency: description says "subagent_type is ignored" but code throws
  3. Throw creates unrecoverable loop: models receive the error but keep generating the same function call

Reproduction

Any model (especially GPT series) delegating a quick task:

task(category="quick", subagent_type="sisyphus-junior", ...)
// → Error: mutually exclusive
// → Model retries with same params → infinite loop

Changes

1. Tool description cleanup

  • Removed 3 references to "Sisyphus-Junior" — internal implementation detail models don't need to know
  • Fixed wording inconsistency about mutual exclusion behavior

2. Defensive behavior restored

  • throw new Error(...)log() + args.subagent_type = undefined
  • When both provided: warn, discard subagent_type, continue with category
  • This matches the pre-existing behavior before the strict validation was introduced

3. Test updated

  • Replaced rejects.toThrow("mutually exclusive") with successful resolution + log assertion

Verification

  • bun run typecheck: ✅ pass
  • bun test src/tools/delegate-task/: 234 pass, 0 fail

Summary by cubic

Prevents infinite retry loops in the task() tool by ignoring subagent_type when category is also provided, logging a warning, and continuing with category. Cleans up the tool description to reduce confusion and updates tests.

  • Bug Fixes
    • When both category and subagent_type are passed, log a warning and drop subagent_type; proceed with category.
    • Removed “Sisyphus-Junior” references and clarified mutual-exclusion wording in the tool help.
    • Updated test to expect successful execution and assert the warning log.

Written for commit ef0ed6d. Summary will update on new commits.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 4/5

  • This PR is likely safe to merge, with a small behavior mismatch in src/tools/delegate-task/tools.ts rather than a clear breakage.
  • In src/tools/delegate-task/tools.ts, the tool description says passing both parameters should error, but the implementation now ignores subagent_type; this can confuse callers and lead to unexpected task-routing behavior.
  • The issue is moderate (5/10) but high-confidence, so it’s worth aligning docs and runtime behavior soon to avoid subtle regressions.
  • Pay close attention to src/tools/delegate-task/tools.ts - parameter-conflict handling no longer matches the documented error behavior.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tools/delegate-task/tools.ts">

<violation number="1" location="src/tools/delegate-task/tools.ts:79">
P2: Tool description claims both parameters cause an error, but implementation now silently ignores `subagent_type` when both are present.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- subagent_type: For direct agent invocation (explore, librarian, oracle, etc.)

**DO NOT provide both.** category and subagent_type are mutually exclusive.
**DO NOT provide both.** Providing both will cause an error.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 29, 2026

Choose a reason for hiding this comment

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

P2: Tool description claims both parameters cause an error, but implementation now silently ignores subagent_type when both are present.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tools/delegate-task/tools.ts, line 79:

<comment>Tool description claims both parameters cause an error, but implementation now silently ignores `subagent_type` when both are present.</comment>

<file context>
@@ -73,13 +73,13 @@ export function createDelegateTask(options: DelegateTaskToolOptions): ToolDefini
   - subagent_type: For direct agent invocation (explore, librarian, oracle, etc.)
   
-  **DO NOT provide both.** category and subagent_type are mutually exclusive.
+  **DO NOT provide both.** Providing both will cause an error.
   
   - load_skills: ALWAYS REQUIRED. Pass [] if no skills needed, or ["skill-1", "skill-2"] for category tasks.
</file context>
Fix with Cubic

@code-yeongyu
Copy link
Copy Markdown
Owner

Thanks for the PR! This addresses the same issue as #2939, #2947, and #2847. We're going with #2939 (sjawhar) which takes the same category-wins approach with a response note for the agent.

Closing as duplicate.

@code-yeongyu
Copy link
Copy Markdown
Owner

Duplicate — going with #2939

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.

2 participants