Skip to content

fix(hook): skip auto-patch only when ToolResultBlock IDs match pendin… Fixes #42#1409

Closed
sunwg2 wants to merge 3 commits into
agentscope-ai:mainfrom
sunwg2:main
Closed

fix(hook): skip auto-patch only when ToolResultBlock IDs match pendin… Fixes #42#1409
sunwg2 wants to merge 3 commits into
agentscope-ai:mainfrom
sunwg2:main

Conversation

@sunwg2

@sunwg2 sunwg2 commented May 16, 2026

Copy link
Copy Markdown

…g tool calls

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.12, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • 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 (e.g. links, examples, etc.)
  • Code is ready for review

@sunwg2 sunwg2 requested a review from a team May 16, 2026 09:22
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


sunwg2 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sunwg2

sunwg2 commented May 16, 2026

Copy link
Copy Markdown
Author

Fixes #42

@LearningGp

Copy link
Copy Markdown
Member
image

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../agentscope/core/hook/PendingToolRecoveryHook.java 55.55% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels May 28, 2026
test(hook): add recovery hook test for auto-patching stale tool result IDs
@LearningGp

Copy link
Copy Markdown
Member

Run 'mvn spotless:apply' to fix these violations.

@sunwg2

sunwg2 commented Jun 4, 2026

Copy link
Copy Markdown
Author

Run 'mvn spotless:apply' to fix these violations.

Thank you for the feedback!

I will run mvn spotless:apply to fix the formatting violations
and resolve the merge conflicts right away.

Also, I noticed you mentioned PR #1566 which seems to address
the same issue. Should I close this PR in favor of #1566,
or would you like me to continue with this fix?

I'll wait for your guidance. Thanks!

@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 refines PendingToolRecoveryHook to use ID-level matching when deciding whether to skip auto-patching. Previously, any ToolResultBlock present in the input would suppress auto-recovery, even if the IDs were stale or unrelated to the current pending tool calls. Now, only ToolResultBlocks whose IDs match an active pending tool call ID will inhibit auto-patch. The logic change is correct and addresses a real edge case where stale tool results could block recovery.

* <li>Only patches when pending tool calls exist AND user input does not contain any
* {@link ToolResultBlock} whose ID matches a current pending tool call ID</li>
* <li>If the input contains {@link ToolResultBlock}s but none of their IDs match the current
* pending IDs (i.e., stale or unrelated results), a warning is logged and the input is

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.

[minor] Javadoc states: 'the input is passed through unmodified -- ReActAgent's doCall will then reject the invalid IDs with an IllegalStateException'. This is incorrect. After the warning, execution falls through to the auto-patch section which clears pending state. doCall subsequently runs normally without throwing. Suggested fix: rewrite to describe the actual flow.

return Mono.just(event);
}
// Input contains ToolResultBlocks, but none of their IDs match the current
// pending tool call IDs (stale / unrelated results). Log a warning and

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.

[minor] Inline comment says 'doCall will reject the invalid IDs with an IllegalStateException, which is the correct strict-mode behavior'. This contradicts the actual flow: the code falls through to patchPendingToolCalls, which clears the pending state. Remove the misleading sentence.

@github-actions

Copy link
Copy Markdown

Closing due to inactivity. Feel free to reopen when ready.

@github-actions github-actions Bot added the stale label Jun 13, 2026
@github-actions github-actions Bot closed this Jun 13, 2026
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 stale wait-for-response PRs that require further response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants