Skip to content

[Bug]: Zero-chunk model completion ends the ReAct run as silent success - no error, no retry, no fallback #2962

Open

Description

@Buktal

Describe the bug

When a model provider (or an LLM gateway in front of it) returns HTTP 200 with a stream that completes without any content-bearing chunk — e.g. only the [DONE] marker, or chunks that all fail to parse — the whole chain treats it as a normal successful completion:

  1. OpenAIClient streaming: a [DONE]-only stream completes the Flux normally (takeWhile on the done marker); malformed chunks are parsed to null and silently skipped. No error is ever raised.
  2. ModelUtils.applyTimeoutAndRetry — the shared wrapper all model implementations route through (openai / gemini / dashscope / ollama / anthropic) — has no empty-completion detection, so the error never enters the existing retryWhen / fallback machinery.
  3. ReasoningContext.buildFinalMessage() returns null when no blocks were accumulated.
  4. ReActAgent.reasoning(): finalMsg == null → Mono.justOrEmpty(null) → the subsequent .flatMap is skipped entirely, so runPostReasoningPipeline never executes.
  5. The run ends "normally": no WARN, no error event, no fallback model selected, no assistant message persisted. To the caller it looks like the model simply chose to say nothing.

The empty-response reminder loop added for "message with no visible content" (#2750 / #2755) cannot catch this case: it lives inside runPostReasoningPipeline, which is unreachable when the final message is null. The two conditions are also semantically different — a thinking-only message is a model-behavior problem (the reminder loop is the right response), while a zero-chunk completion is an upstream transport/service anomaly (error + retry is the right response).

To Reproduce

  1. Point an OpenAIChatModel at a stub endpoint that returns HTTP 200 with body data: [DONE]\n\n (or unit-level: invoke a ReActAgent whose model returns Flux.empty()).
  2. Ask a plain question: agent.call(...).
  3. The run completes successfully — no assistant message, no error logged, no retry (even with maxAttempts > 1), and no fallback model engaged (switchOnFirst only switches on an error signal).

Observed in production (AgentScope 2.0.1, OpenAI-compatible endpoint behind an LLM gateway): a run whose chat call returned 200 + zero content chunks in 0.211s ended "successfully" with no reply; a retry two minutes later also got an empty stream (0.146s); a third attempt six minutes later produced a normal 5.26s response — a transient upstream fault, silently swallowed twice with no signal at any layer.

Expected behavior

A stream that completes without any content-bearing ChatResponse (no TextBlock / ThinkingBlock / ToolUseBlock) is an upstream anomaly, not a valid "the model said nothing" outcome. It should surface as a ModelException so the existing retry (retryWhen) and fallback chains can engage and the caller sees an error instead of a silent empty reply. ModelUtils.applyTimeoutAndRetry is the natural single point for this detection — shared by all model implementations — chained before retryWhen.

Error messages

None — that is the bug. The only trace is the INFO-level harness log (AgentTraceMiddleware: "empty completion (no text, no tool call) — ReAct loop will terminate") acknowledging that the loop terminates silently.

Environment (please complete the following information:)

  • AgentScope-Java Version: 2.0.1 (production); verified still present on main @ ea511ec2
  • Java Version: 17
  • OS: any
  • Provider: OpenAI-compatible endpoint (MiniMax) behind an LLM gateway

Additional context

Activity

  1. added a commit that references this issue on Sep 3, 2026
    3839e8b
  2. oss-maintainer commented on Sep 13, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed | Severity: high

    Verified against main @ 39cd304a. All five steps of the chain you describe still hold.

    Root cause (evidence per step)

    1. OpenAIClient.java:411-446 — [DONE] is stripped by the transports (OkHttpTransport.java:276-289, JdkHttpTransport.java:324-331), and parseStreamData returning null (:511-540) is skipped by the handle operator; OpenAIChatModel.java:169-177 adds another .filter(Objects::nonNull). Zero emitted items completes the Flux normally, with no error signal.
    2. ModelUtils.java:69-139 — the shared wrapper applies only .timeout() (line 86, wall-clock) and .retryWhen() (line 129, error-driven). There is no switchIfEmpty / element-count check, so an empty completion passes straight through.
    3. ReasoningContext.java:174-175 — contentBuilder is never initialised when no ChatResponse is processed, so buildFinalMessage() returns null.
    4. ReActAgent.java:2429 — Mono.justOrEmpty(finalMsg) becomes Mono.empty(), so the .flatMap at :2450-2463 never fires and runPostReasoningPipeline (:2467-2523) is unreachable. Your point that the [Bug]: ReActAgent treats thinking-only final response as finished - user receives no text message, silent failure #2750/fix(core): retry empty final responses instead of finishing silently #2755 empty-response reminder cannot help here is correct — it lives at :2505-2511, inside that unreachable stage.
    5. ReActAgent.java:1195-1224 — doCall's .switchIfEmpty (line 1219) saves session state and returns Mono.empty(). switchOnFirst in modelForCall() (:4077-4090) only inspects signal.isOnError(), so no fallback model is selected.

    Impact: a provider or gateway returning HTTP 200 with no content-bearing chunk is indistinguishable from "the model chose to stay silent". No WARN, no error event, no retry (even with maxAttempts > 1), no fallback, no assistant message persisted. Because the failure is silent and transient upstream faults are exactly what the retry/fallback machinery exists for, this is hard to diagnose in production.

    Severity rationale: high rather than critical — it needs a degenerate provider response, which is uncommon with major providers under normal conditions, but the silent-failure mode and the fact that it defeats existing defenses is what makes it worth fixing.

    Fix direction: two complementary changes.

    1. ModelUtils.applyTimeoutAndRetry (~line 129): insert .switchIfEmpty(Flux.error(new ModelException("Model returned empty response (zero chunks)", modelName, provider))) before .retryWhen(...). One operator, and it activates every existing retry/fallback path for all providers, since they all route through this wrapper.
    2. ReActAgent.reasoning() (~line 2429): defense in depth — when finalMsg == null and no RequestStopEvent was observed, surface an error instead of Mono.empty().

    One deliberate scoping note: the detection should be "no content-bearing block", not "no text block" — a thinking-only or tool-call-only stream is a model-behaviour problem, not a transport anomaly, and is already handled by the reminder loop.

    We can generate a PR for this. Reply /approve to proceed, /revise to change the approach.


    Automated evaluation by github-manager-bot

  3. added
    bug
    on Sep 13, 2026
  4. oss-maintainer commented on Sep 16, 2026

    @oss-maintainer
    Collaborator

    Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed

    The evaluation above went 72 hours without an /approve, /revise or /reject, so per our workflow the window is closed and no competing PR will be generated. No action is needed from anyone.

    The root cause in the evaluation still stands, and the fix is already in flight from the reporter:

    That is the same seam as suggested above: a zero-chunk [DONE] completion completes the Flux normally with no error signal (OpenAIClient.java:411-446, OpenAIChatModel.java:169-177), ModelUtils.applyTimeoutAndRetry has no empty-stream guard between .timeout() and .retryWhen() (ModelUtils.java:69-139), so ReasoningContext.buildFinalMessage() returns null and ReActAgent.reasoning() collapses into Mono.empty() (ReActAgent.java:2429, :1195-1224) — a silent success that bypasses retry, fallback and the empty-response reminder.

    As of this check #2968 has statusCheckRollup=SUCCESS at head 3839e8b587 with reviewDecision=REVIEW_REQUIRED, last updated 2026-09-14T16:15Z — but its mergeability is CONFLICTING, so it needs a rebase onto current main before it can move. That rebase plus a maintainer review are what #2968 needs next, not a second implementation. #2968 stays the active path for this issue.

    If maintainers would still like an independent proposal here — for example the defence-in-depth change in ReActAgent.reasoning() on top of the switchIfEmpty guard — reply on this issue and we will re-evaluate.

    Automated by github-manager-bot

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions