Skip to content

[Bug]: WaitAsyncResultsTool waits on the inbox notification chain instead of task state, stalling the main agent when any link breaks #2791

Open

Description

@sailor-smile

Describe the bug

WaitAsyncResultsTool builds its waiting semantics on an indirect, multi-hop chain rather than
observing task state directly:

subtask completes -> TaskRepository completionCallback -> MessageBus inbox push
                  -> InboxMiddleware injects before next LLM call -> LLM sees the result

The tool itself only polls the inbox every 3s. If any link in that chain fails to deliver, the
tool never observes the fact that the task has actually finished — and it never cross-checks the
real task status in TaskRepository.

Combined with the MAX_CONSECUTIVE_EMPTY_WAITS rejection, the consequence escalates from "waits
too long" to "hard stall": after two consecutive empty waits the tool refuses to wait any longer,
while the main agent has neither received results nor been given any other way to make progress.

To Reproduce

  1. You code
HarnessAgent supervisor = HarnessAgent.builder()
        .model(model)
        .messageBus(messageBus)
        .subagentFactory("worker", name -> workerAgent)
        .build();

// Spawn one or more async subagents (background task mode), then let the supervisor
// call wait_async_results to collect their results.
supervisor.streamEvents(new UserMessage(promptThatSpawnsThenWaits), ctx).subscribe();
  1. How to execute

Run the flow, and make any one link of the injection chain fail. Any of these is enough:

  • another WorkspaceTaskRepository.setCompletionCallback call replaces the callback, so the
    inbox push no longer happens (later registration overwrites the earlier one);
  • the task reaches a terminal state between putTask and callback registration (race), so the
    completion event is lost;
  • the inbox message is consumed but injection lands after the round that needed it (injector race).

Then compare the subagent's real state with what the tool reports.

  1. See error

TaskRepository shows the task as COMPLETED, the inbox is empty, and the tool keeps waiting
until timeout, then refuses to wait again. The LLM never receives the results.

Expected behavior

Once a task has actually reached a terminal state, wait_async_results should observe it and hand
the result to the LLM. Even if the inbox notification side-channel fails, the tool must not treat
"notification missing" as "task not finished".

Error messages

No exception is raised. The failure is silent, so the observable symptoms are:

  • the tool blocks for the full 60s timeout although the task is already terminal;
  • after two consecutive empty waits, waiting is refused via MAX_CONSECUTIVE_EMPTY_WAITS and the
    conversation cannot proceed;
  • when the inbox is empty but all tasks are terminal, the tool returns a promise such as
    results will be injected automatically, which is never fulfilled in this scenario and actively
    misleads the LLM into waiting further.

Environment (please complete the following information):

  • AgentScope-Java Version: 2.0.0 (agentscope-harness 2.0.0)
  • Java Version: 17
  • OS: macos

Additional context

Root cause. The tool's wait condition is not the same thing as the semantics it means to express:

Intended semantics What is actually observed
Goal whether tasks reached a terminal state task status in TaskRepository
Actual whether the inbox has a message a product of the notification chain

Task status is the authoritative fact and is guaranteed to happen (unless the task itself
hangs). The inbox message is only a derived notification with several failure points along the
way. Observing the derived signal without checking the authoritative one makes "lost notification"
indistinguishable from "task not finished".

MAX_CONSECUTIVE_EMPTY_WAITS amplifies the defect. It assumes repeated empty waits mean the LLM
is abusing the wait, but when the notification chain is broken, repeated empty waits are a symptom
of the tool's own faulty observation — refusing to wait at that moment only pushes the LLM into a
dead end.

Suggested fix. Change the wait condition to poll TaskRepository for terminal task state
directly. TaskRepository.listTasks(ctx, sessionId, null) already returns all tasks with their
TaskStatus, and TaskStatus.isTerminal() already exists, so no new API is required. Once tasks
are terminal, return the result text as the tool's return value so result collection closes within
a single call() and no longer depends on cross-round injection. Inbox injection can stay as a
fast path, but should not be the only correctness dependency.

Secondary points:

  1. Remove or reposition MAX_CONSECUTIVE_EMPTY_WAITS. If the wait observes real task state, a
    terminal state is guaranteed to arrive and the rejection is meaningless; if the intent is to
    guard against hung tasks, the timeout itself is the better mechanism.
  2. When the inbox is empty and all tasks are terminal, do not return
    will be injected automatically. Return the actual results, or state the current status
    explicitly, instead of making a promise that will not be kept.

Affected classes:

  • io.agentscope.harness.agent.tool.WaitAsyncResultsTool
  • io.agentscope.harness.agent.subagent.task.WorkspaceTaskRepository (completion callback registration)

Activity

  1. added
    bug
    on Aug 20, 2026
  2. oss-maintainer commented on Sep 25, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Partly confirmed (verified against main@ea78c31)

    Thanks for the detailed report. Verification of each claim:

    Claim Result Evidence
    The wait decision ignores real task state Partly In legacy (inbox-any) mode the poll loop reads only the bus: messageBus.inboxHasMessages(sessionId) (WaitAsyncResultsTool.java:221-228); task state is consulted once before the loop (:182-204, hasNonTerminalTasks :485-488), never re-checked inside it. Barrier mode does re-read terminal status every poll (:318-329, completeTaskBarrierIfReady :364).
    MAX_CONSECUTIVE_EMPTY_WAITS escalates to a hard stall Confirmed (bounded) MAX_CONSECUTIVE_EMPTY_WAITS = 2 (:56); on exhaustion the tool rejects further waits and tells the model to use task_list / task_output(block=false) (:174-179, barrier twin :415-441). The budget check (:157) runs before the terminal pre-check (:182), so a task that finished while the budget was spent can still be reported only as "budget exhausted".
    The "injected automatically" promise can be unfulfilled Clarified That text is returned on the inbox-has-messages branch (:165-168, :225-228), not on the rejection branch — but it is still a promise about a side channel, so the concern stands when injection lands after the round that needed it.
    A second setCompletionCallback overwrites the first Confirmed WorkspaceTaskRepository.setCompletionCallback is a plain field assignment (:257-259); the javadoc in SubagentsMiddleware.wireMessageBus acknowledges it (:283-285, inbox push at :315).
    Net effect: results can be lost Partly mitigated SubagentsMiddleware.onReasoning drains findPendingDeliveries from TaskRecord state independently of the callback (:417-431), so a lost inbox push is normally recovered on the next reasoning round rather than permanently. The remaining hard case is "waiting is refused" + results not yet drained in that same round.

    Severity: medium — silent degradation of an async-subagent flow, no data loss, recovery path exists one round later.

    Suggested minimal fix

    1. WaitAsyncResultsTool legacy poll loop: re-check hasNonTerminalTasks per poll and return terminal results instead of waiting out the budget.
    2. rejectIfWaitBudgetExhausted (both modes): consult TaskRepository terminal state before rejecting the wait.
    3. WorkspaceTaskRepository.setCompletionCallback: compose into a listener list instead of overwriting.

    A state-based guard in the wait loop is the smallest change that closes the stall. Maintainer signal wanted on whether legacy (inbox-any) mode should keep existing at all, since barrier mode already implements the correct semantics — that decides between a targeted fix and converging the two paths.


    Automated evaluation by github-manager (oss-maintainer)

  3. added
    area/harness
    on Sep 25, 2026
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

    area/harnessbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions