Repository navigation
Description
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:
OpenAIClientstreaming: a[DONE]-only stream completes the Flux normally (takeWhileon the done marker); malformed chunks are parsed to null and silently skipped. No error is ever raised.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 existingretryWhen/ fallback machinery.ReasoningContext.buildFinalMessage()returnsnullwhen no blocks were accumulated.ReActAgent.reasoning():finalMsg == null→Mono.justOrEmpty(null)→ the subsequent.flatMapis skipped entirely, sorunPostReasoningPipelinenever executes.- 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
- Point an
OpenAIChatModelat a stub endpoint that returns HTTP 200 with bodydata: [DONE]\n\n(or unit-level: invoke aReActAgentwhose model returnsFlux.empty()). - Ask a plain question:
agent.call(...). - The run completes successfully — no assistant message, no error logged, no retry (even with
maxAttempts > 1), and no fallback model engaged (switchOnFirstonly 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
- Distinct from [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: that fix handles "has message, no visible content" and requires a non-null final message; zero-chunk completions bypass
runPostReasoningPipelineentirely, so the protection has a blind spot by construction. - Contributing gap, likely worth its own issue:
OpenAIResponse.isError()does not recognize MiniMax-stylebase_resp.status_code != 0/input_sensitivemarkers, so provider-side filtered responses are indistinguishable from normal empty streams. Related: [Bug]: ModelCallEndEvent in Middleware lacks complete response info (status_code) for sensitive content filtering #2641 asks for status exposure in middleware events. - Keeping the two empty-outcome conditions separate matters for the fix: folding zero-chunk into the reminder loop would waste a full LLM call re-prompting what is actually a transport fault.
Activity
fix(core): fail model empty-completion before retry
oss-maintainer commentedon Sep 13, 2026
Issue Evaluation
Category:
bug| Status: Confirmed | Severity: highVerified against
main@39cd304a. All five steps of the chain you describe still hold.Root cause (evidence per step)
OpenAIClient.java:411-446—[DONE]is stripped by the transports (OkHttpTransport.java:276-289,JdkHttpTransport.java:324-331), andparseStreamDatareturningnull(:511-540) is skipped by thehandleoperator;OpenAIChatModel.java:169-177adds another.filter(Objects::nonNull). Zero emitted items completes theFluxnormally, with no error signal.ModelUtils.java:69-139— the shared wrapper applies only.timeout()(line 86, wall-clock) and.retryWhen()(line 129, error-driven). There is noswitchIfEmpty/ element-count check, so an empty completion passes straight through.ReasoningContext.java:174-175—contentBuilderis never initialised when noChatResponseis processed, sobuildFinalMessage()returnsnull.ReActAgent.java:2429—Mono.justOrEmpty(finalMsg)becomesMono.empty(), so the.flatMapat:2450-2463never fires andrunPostReasoningPipeline(: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.ReActAgent.java:1195-1224—doCall's.switchIfEmpty(line 1219) saves session state and returnsMono.empty().switchOnFirstinmodelForCall()(:4077-4090) only inspectssignal.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.
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.ReActAgent.reasoning()(~line 2429): defense in depth — whenfinalMsg == nulland noRequestStopEventwas observed, surface an error instead ofMono.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
/approveto proceed,/reviseto change the approach.Automated evaluation by github-manager-bot
oss-maintainer commentedon Sep 16, 2026
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,/reviseor/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:
fix(core): fail model empty-completion before retry, by @Buktal, closes this issue.That is the same seam as suggested above: a zero-chunk
[DONE]completion completes theFluxnormally with no error signal (OpenAIClient.java:411-446,OpenAIChatModel.java:169-177),ModelUtils.applyTimeoutAndRetryhas no empty-stream guard between.timeout()and.retryWhen()(ModelUtils.java:69-139), soReasoningContext.buildFinalMessage()returnsnullandReActAgent.reasoning()collapses intoMono.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=SUCCESSat head3839e8b587withreviewDecision=REVIEW_REQUIRED, last updated 2026-09-14T16:15Z — but its mergeability isCONFLICTING, so it needs a rebase onto currentmainbefore 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 theswitchIfEmptyguard — reply on this issue and we will re-evaluate.Automated by github-manager-bot