fix(core): fail model empty-completion before retry - #2968
Open
Buktal wants to merge 1 commit into
Open
Conversation
ModelUtils.applyTimeoutAndRetry's shared path (all model implementations) now detects empty completions—streams with zero chunks or only chunks whose content blocks are not TextBlock/ThinkingBlock/ToolUseBlock—and converts them to ModelException before retryWhen, so the existing retry and fallback chains engage. Detection is unconditional (applies regardless of ExecutionConfig/retry configuration), since empty completion is an upstream transport anomaly that should always surface as an error. Detection sits after timeout (a timed-out request bypasses the check and goes straight to error). Three regression tests: zero-chunk stream, all-empty-content chunks, and retry-then-success (confirming the error triggers retry and a subsequent non-empty response completes successfully). Fixes agentscope-ai#2962
Buktal
force-pushed
the
fix/2962-empty-completion-silent-success
branch
from
September 3, 2026 13:31
aa64284 to
3839e8b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
main @
ea511ec2(defect observed in production on 2.0.1)Description
Fixes #2962
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 only well-formed chunks whose content parses to empty — the entire chain treated it as a normal successful completion: no error, no retry, no fallback, and no assistant message persisted. To the caller it looked like the model simply chose to say nothing.Changes
ModelUtils.applyTimeoutAndRetry— the shared path all model implementations route through — now detects empty completions and converts them to aModelExceptionbeforeretryWhen:ensureNonEmptyCompletion(new private helper) rejects a stream that completes without any chunk carrying a non-null, non-emptygetContent(). Any content block counts (multimodal blocks included); only a fully contentless stream is rejected.switchOnFirst-based fallback commits on the first signal, and the common OpenAI-compatible empty shape (a role-only first chunk, then[DONE]) would otherwise emit a contentless chunk first and bypass the fallback model entirely. Healthy streams are unaffected — withheld chunks are released the moment content arrives, with order and metadata preserved.agent.call(...)without anExecutionConfigstill surfaces the error instead of ending as silent success.applyTimeoutAndRetryno longer NPEs when bothoptionsanddefaultOptionsare null —GenerateOptions.mergeOptionsdocuments that it can return null, and both parameters are documented as nullable.Tests
ModelTimeoutRetryTest— 6 tests:Flux.empty(), the[DONE]-only case) → error.switchOnFirst-based fallback still engages).attemptCount == 2.RetryExhaustedExceptionwrappingModelException).ReActAgentTest: primary model returns an empty completion (contentless chunks, then complete) → fallback model takes over and answers.Provider extension tests: mocks that stubbed contentless responses (
choices: [], or streaming bodies without any content-bearing delta) were updated to return realistic content-bearing responses, since a contentless completion is now an error by design (OpenAIChatModelTest,DashScopeChatModelTest,DashScopeNonStreamingBlockingBehaviorTest).Checklist
mvn spotless:applymvn test -pl agentscope-core, plus the fullagentscope-extensions-modelreactor)