Skip to content

fix(core): handle synchronous failures in model fallback - #3149

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/synchronous-model-fallback
Sep 15, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/synchronous-model-fallback

Conversation

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT, based on main 60934595a7e9f6805bd0649a68d26766b158042e.

Description

Fixes #3148.

A configured fallback currently runs when the primary returns Flux.error(error), but not when Model.stream() throws the same error before returning its publisher. The eager invocation happens before switchOnFirst, so the agent fails without trying the fallback or notifying the failover listener.

Defer primary invocation so synchronous setup failures enter the existing first-signal fallback path. A primary that has already emitted a response still propagates a subsequent error without switching, avoiding mixed output from two models. Retry budgets and cooldown policy are unchanged.

The new test covers both initial error forms, the original error/model delivered to the listener, one fallback invocation, and no switch after partial output. On unmodified main: 3 tests, 2 pass and the synchronous case errors. With this fix: 57 selected core tests pass (0 failures/errors/skips):

mvn -B -pl agentscope-core -Dtest=ReActAgentFailoverBoundaryTest,ReActAgentTest,ReActAgentNewLoopBuilderTest,ReActAgentGenerateOptionsTest,ModelConfigTest,ModelTimeoutRetryTest -Dspotless.skip=true test

Scoped Spotless apply/check and git diff --cached --check pass. Tests use local model fixtures and make no provider requests. The full repository suite was not run locally.

AI assistance was used for investigation, implementation and test preparation; the stated tests were executed and the diff reviewed.

Checklist

  • Code has been formatted with scoped mvn spotless:apply and verified with spotless:check
  • All repository tests are passing (mvn test) — 57 relevant tests passed locally; full-suite CI pending
  • No public API or Javadoc contract changes
  • No user-facing configuration changes; the inline comment explains the deferred invocation
  • Code is ready for review

Defer primary model invocation so setup errors reach the existing first-signal fallback and listener. Cover both initial error forms and preserve no-switch behavior after partial output.

Fixes agentscope-ai#3148
Copilot AI lite review requested due to automatic review settings September 15, 2026 00:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved blocking issues were identified.

Pull request overview

Fixes synchronous model failures so they correctly trigger the configured fallback.

Changes:

  • Defers primary Model.stream() invocation with Flux.defer.
  • Adds regression tests for synchronous/reactive failures and partial responses.
File summaries
File Description
agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentFailoverBoundaryTest.java Covers fallback and partial-stream failure behavior.
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Routes synchronous setup failures through existing failover logic.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Wrapping the primary model.stream(...) call in Flux.defer(...) so a synchronous setup failure (thrown before a publisher exists) enters the existing switchOnFirst error path instead of escaping call(). This closes the gap where a configured fallback and the failover listener were only honoured for the Flux.error(...) form — the fix is minimal, correctly targeted, and does not change retry budgets, cooldown policy, or any public API.

ReActAgentFailoverBoundaryTest parameterises both failure forms (throw / Flux.error) and additionally pins the two invariants that matter here: the fallback is invoked exactly once with the original error delivered to the listener, and a primary that has already emitted content is not switched mid-stream (so no mixed output from two models). Tests use local fixtures only, CI is green on ubuntu + windows, and the change is bounded to the fallback decorator.

No findings. LGTM.


Automated review by github-manager-bot

@gmjneko

gmjneko commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

LGTM

@jujn
jujn merged commit a51d176 into agentscope-ai:main Sep 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Synchronous model stream failures bypass the configured fallback

5 participants