Skip to content

[Bug]: DelegateTool reports errored, stuck or paused sub-agents as completed work #6488

Open

Description

@enyst

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Bug Description

DelegateExecutor runs each sub-agent with _run_until_finished() and then reports get_agent_final_response() as that agent's result, or "No response from sub-agent" (delegate/impl.py#L331-L348).`` It never reads conversation.state.execution_status. Every status, including ERROR and STUCK, reaches the parent agent as an ordinary result, and the observation isn't marked as an error.

This matters most for budget limits. A sub-agent that hits max_budget_per_task ends in ERROR without raising, through _emit_run_limit_error (local_conversation.py#L783-L786,```` #L2166).````` The parent then carries on as if the delegated work had been done.

TaskManager had the same bug and fixed it in e75b9c2 (#3742), "surface non-FINISHED sub-agent runs as errors, not empty success". The two delegation paths now disagree on the same sub-conversation.

Expected Behavior

Only a FINISHED sub-conversation counts as success. Any other status produces an error entry that names the status, as TaskManager does, and the observation's is_error reflects it.

Actual Behavior

ERROR, STUCK and FINISHED produce the same observation: is_error=False, with the text "Completed delegation of 1 tasks / Results: 1. Agent worker: No response from sub-agent", or the partial text when there is one.

Steps to Reproduce

Run the code sample below on main (28f4dfe). The sub-conversation is a mock carrying the real ConversationExecutionStatus, the same technique the existing TaskManager tests use.

Acceptance Criteria

  • DelegateTool reports a sub-agent whose final status is not FINISHED as an error that names the status, and the observation is marked is_error when any sub-agent fails.
  • A FINISHED sub-agent's result is reported as today.
  • DelegateTool and TaskManager classify the same sub-conversation outcome the same way, ideally through one shared helper.

SDK Version

main at 28f4dfe

Python Version

3.13

Operating System

Linux

Minimal Code Sample

import tempfile
from unittest.mock import MagicMock
from pydantic import SecretStr
from openhands.sdk import LLM, Agent
from openhands.sdk.conversation.impl.local_conversation import LocalConversation
from openhands.sdk.conversation.state import ConversationExecutionStatus
from openhands.tools.delegate.definition import DelegateAction
from openhands.tools.delegate.impl import DelegateExecutor

parent = LocalConversation(
    agent=Agent(llm=LLM(model="gpt-4o", api_key=SecretStr("k"), usage_id="p"), tools=[]),
    workspace=tempfile.mkdtemp(), visualizer=None,
)
for status in (ConversationExecutionStatus.ERROR, ConversationExecutionStatus.STUCK,
               ConversationExecutionStatus.FINISHED):
    sub = MagicMock()
    sub.state.events = []
    sub.run.side_effect = lambda s=sub, st=status: setattr(s.state, "execution_status", st)
    ex = DelegateExecutor()
    ex._parent_conversation = parent
    ex._sub_agents = {"worker": sub}
    obs = ex._delegate_tasks(DelegateAction(command="delegate", tasks={"worker": "do it"}))
    print(status.value, obs.is_error)  # error False / stuck False / finished False

Evidence and Additional Context

Found by applying the property behind e75b9c2 ("a delegated task succeeds iff its sub-conversation FINISHED") to the second delegation front-end. It fails for every non-FINISHED status. See #6486.


OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

DelegateExecutor._delegate_tasks() reports every sub-agent outcome as an ordinary result: it never reads conversation.state.execution_status, so runs ending in ERROR or STUCK reach the parent as success text, and the observation is never marked is_error (the exception path renders "Agent X ERROR: ..." with is_error=False too). TaskManager already classifies the same sub-conversations correctly since e75b9c2 (#3742): only FINISHED counts as success, any other status is surfaced as an error naming the status with partial output preserved. The bug is confirmed against current main and the issue includes a runnable reproducer; prioritized low because it was found by inspection/property testing with a synthetic reproduction and there is no user, support, or production report yet. Bounded scope: classify delegate outcomes by execution status (FINISHED-only success), name the failing status in the results entry, and set the aggregate observation's is_error when any sub-agent fails. Non-goals: no change to TaskManager behavior, no change to how a FINISHED sub-agent's result text is formatted, no budget plumbing, retry, or resume behavior, no changes to spawn/agent lifecycle or metrics handling, and no tool-schema change beyond the corrected is_error value.

Acceptance Criteria

  • For a sub-agent whose run ends in a non-FINISHED execution status (ERROR, STUCK, or PAUSED), the delegate observation's result entry for that agent names the execution status and preserves any partial final response, and the observation's is_error is true when at least one delegated sub-agent fails.
  • For a sub-agent whose run ends FINISHED, the result entry shows the sub-agent's final response as it does today, and the observation's is_error is false when every delegated sub-agent finishes.
  • For the same sub-conversation outcome (FINISHED, ERROR, STUCK, PAUSED), DelegateTool and TaskManager classify it the same way, demonstrated by tests exercising the same status values through both paths or by one shared classification helper used by both.
  • Regression tests covering the non-FINISHED and FINISHED delegation outcomes fail on main without the fix and pass with it; uv run pytest tests/tools/delegate/test_delegation.py passes with the fix applied.

Activity

  1. added
    bug
    on Nov 5, 2026
  2. added
    ready-for-dev
    on Nov 5, 2026
  3. Christian-Sidak commented on Nov 5, 2026

    @Christian-Sidak

    Opened a fix in #6498: adds proper status checking in DelegateTool so that only sub-agents with a FINISHED status are counted as completed work, while those that errored, got stuck, or were paused are collected into a separate errors dict. The fix also surfaces error details from ConversationErrorEvent and partial output, and sets is_error=True on the DelegateObservation when any sub-agent did not finish cleanly.

  4. Christian-Sidak commented on Nov 5, 2026

    @Christian-Sidak

    Opened a fix in #6498: adds a _run_stop_detail method that reads the sub-agent execution status after _run_until_finished, routing non-FINISHED outcomes (ERROR, STUCK, PAUSED) into errors with the status name preserved, so DelegateObservation correctly sets is_error=True instead of silently treating failed sub-agents as successful results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions