Repository navigation
fix(core): handle synchronous failures in model fallback - #3149
Conversation
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
There was a problem hiding this comment.
🟢 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 withFlux.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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
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
|
LGTM |
AgentScope-Java Version
2.0.3-SNAPSHOT, based on main60934595a7e9f6805bd0649a68d26766b158042e.Description
Fixes #3148.
A configured fallback currently runs when the primary returns
Flux.error(error), but not whenModel.stream()throws the same error before returning its publisher. The eager invocation happens beforeswitchOnFirst, 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):
Scoped Spotless apply/check and
git diff --cached --checkpass. 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
mvn spotless:applyand verified withspotless:checkmvn test) — 57 relevant tests passed locally; full-suite CI pending