Skip to content

fix(core): preserve failed summary termination state - #2757

Open
DennisWLX wants to merge 3 commits into
agentscope-ai:mainfrom
DennisWLX:codex/fix-2754-summary-failure-state
Open

fix(core): preserve failed summary termination state#2757
DennisWLX wants to merge 3 commits into
agentscope-ai:mainfrom
DennisWLX:codex/fix-2754-summary-failure-state

Conversation

@DennisWLX

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT

Description

When the ReAct loop reaches maxIters and final summary generation also fails, the fallback message currently uses the default MODEL_STOP reason. Downstream callers cannot distinguish this failure from a normal model completion.

This change:

  • preserves GenerateReason.MAX_ITERATIONS on the summary fallback message
  • adds internal _summary_failed=true metadata for explicit failure detection
  • adds a regression test for the returned reason, metadata, and error text

Fixes #2754

Testing

  • mvn -pl agentscope-core clean test: 2276 tests passed, 9 skipped

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (metadata Javadoc; no external docs required)
  • Code is ready for review

Keep MAX_ITERATIONS as the generate reason when final summary generation fails, and expose the failure through message metadata for downstream callers.\n\nFixes agentscope-ai#2754
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

This PR adds metadata markers to the summary-error fallback path in ReActAgent.handleSummaryError(). Specifically, it sets SUMMARY_FAILED=true in the message metadata and explicitly assigns GenerateReason.MAX_ITERATIONS to the error fallback message. This brings the error path into symmetry with the successful summary path (which already sets MAX_ITERATIONS via withGenerateReason), while the new SUMMARY_FAILED flag allows callers to distinguish a failed summary from a successful one. The change is minimal, well-targeted, and includes a focused unit test that validates all three assertions (generate reason, metadata flag, and error message text). No bugs or correctness issues found.

+ " generating summary: %s",
maxIters, error.getMessage()))
.build())
.metadata(Map.of(MessageMetadataKeys.SUMMARY_FAILED, true))

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.

[nitpick] The .metadata(Map.of(...)) call creates an unmodifiable map. The subsequent .generateReason() call correctly wraps it into a HashMap (via the instanceof HashMap check in Msg.Builder.generateReason()), so the current code works correctly. However, this creates an implicit ordering dependency: if a future refactoring moves .metadata() after .generateReason(), the metadata() call would silently overwrite the generate-reason entry. Consider adding a brief comment like // .metadata() must precede .generateReason() or using new HashMap<>(Map.of(...)) directly to make the intent explicit and prevent accidental breakage.

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Aug 19, 2026

@zouyx zouyx 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.

有个冲突要解决下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Preserve max-iteration terminal semantics when summary generation fails

3 participants