fix(session): Automatically detect and remove dangling tool calls whe…#873
Open
liuxh613 wants to merge 2 commits intoagentscope-ai:mainfrom
Open
fix(session): Automatically detect and remove dangling tool calls whe…#873liuxh613 wants to merge 2 commits intoagentscope-ai:mainfrom
liuxh613 wants to merge 2 commits intoagentscope-ai:mainfrom
Conversation
…n resuming a conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
857e491 to
ee96e85
Compare
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
#871
Describe the bug
When restoring Agent state from a persistent session (such as a database), if the Memory contains incomplete tool calls (ToolUseBlock without a corresponding ToolResultBlock), it causes the following error:
java.lang.IllegalStateException: Cannot add messages without tool results when pending tool calls exist.
Pending IDs: [call_ba1efbfa083f4323adb4f9]
To Reproduce
Steps to reproduce the behavior:
You code
How to execute
See error
Expected behavior
The ReActAgent.loadFrom() method can include automatic cleanup logic.
Error messages
2026-03-05 12:22:57.040 INFO [] io.agentscope.core.tool.Toolkit Line:239 - Registered tool 'context_reload' in group 'ungrouped'
2026-03-05 12:22:57.040 INFO [] io.agentscope.core.memory.autocontext.AutoContextHook Line:185 - AutoContextMemory integration completed for agent: ReActAgent
Error during execution: Cannot add messages without tool results when pending tool calls exist. Pending IDs: [call_ba1efbfa083f4323adb4f9]
java.lang.IllegalStateException: Cannot add messages without tool results when pending tool calls exist. Pending IDs: [call_ba1efbfa083f4323adb4f9]
at io.agentscope.core.ReActAgent.validateAndAddToolResults(ReActAgent.java:335)
at io.agentscope.core.ReActAgent.doCall(ReActAgent.java:256)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:133)
at io.agentscope.core.tracing.TracerRegistry$1.lambda$onNext$0(TracerRegistry.java:92)
at io.opentelemetry.context.Context.lambda$wrapSupplier$8(Context.java:344)
at io.agentscope.core.tracing.telemetry.TelemetryTracer.runWithContext(TelemetryTracer.java:226)
at io.agentscope.core.tracing.TracerRegistry$1.onNext(TracerRegistry.java:89)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:137)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:130)
at io.agentscope.core.tracing.TracerRegistry$1.lambda$onNext$0(TracerRegistry.java:92)
at io.opentelemetry.context.Context.lambda$wrapSupplier$8(Context.java:344)
at io.agentscope.core.tracing.telemetry.TelemetryTracer.runWithContext(TelemetryTracer.java:226)
at io.agentscope.core.tracing.TracerRegistry$1.onNext(TracerRegistry.java:89)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:137)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondComplete(MonoFlatMap.java:246)
at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:307)
at io.agentscope.core.tracing.TracerRegistry$1.lambda$onNext$0(TracerRegistry.java:92)
at io.opentelemetry.context.Context.lambda$wrapSupplier$8(Context.java:344)
at io.agentscope.core.tracing.telemetry.TelemetryTracer.runWithContext(TelemetryTracer.java:226)
at io.agentscope.core.tracing.TracerRegistry$1.onNext(TracerRegistry.java:89)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2565)
at reactor.core.publisher.MonoFlatMap$FlatMapInner.onSubscribe(MonoFlatMap.java:293)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:56)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:75)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:166)
at io.agentscope.core.tracing.TracerRegistry$1.lambda$onNext$0(TracerRegistry.java:92)
at io.opentelemetry.context.Context.lambda$wrapSupplier$8(Context.java:344)
at io.agentscope.core.tracing.telemetry.TelemetryTracer.runWithContext(TelemetryTracer.java:226)
at io.agentscope.core.tracing.TracerRegistry$1.onNext(TracerRegistry.java:89)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:137)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondComplete(MonoFlatMap.java:246)
at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:307)
at io.agentscope.core.tracing.TracerRegistry$1.lambda$onNext$0(TracerRegistry.java:92)
at io.opentelemetry.context.Context.lambda$wrapSupplier$8(Context.java:344)
at io.agentscope.core.tracing.telemetry.TelemetryTracer.runWithContext(TelemetryTracer.java:226)
at io.agentscope.core.tracing.TracerRegistry$1.onNext(TracerRegistry.java:89)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2565)
at reactor.core.publisher.MonoFlatMap$FlatMapInner.onSubscribe(MonoFlatMap.java:293)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:56)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:75)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:166)
at io.agentscope.core.tracing.TracerRegistry$1.lambda$onNext$0(TracerRegistry.java:92)
at io.opentelemetry.context.Context.lambda$wrapSupplier$8(Context.java:344)
at io.agentscope.core.tracing.telemetry.TelemetryTracer.runWithContext(TelemetryTracer.java:226)
at io.agentscope.core.tracing.TracerRegistry$1.onNext(TracerRegistry.java:89)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:137)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2565)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:195)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:195)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:172)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:195)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:195)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2361)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onSubscribe(FluxOnErrorResume.java:75)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:118)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onSubscribe(FluxHide.java:123)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:118)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onSubscribe(FluxHide.java:123)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:96)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onSubscribe(FluxHide.java:123)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:118)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onSubscribe(FluxHide.java:123)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:118)
at io.agentscope.core.tracing.TracerRegistry$1.onSubscribe(TracerRegistry.java:83)
at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onSubscribe(FluxHide.java:123)
at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:56)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:75)
at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:56)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:75)
at reactor.core.publisher.MonoUsing.subscribe(MonoUsing.java:109)
at reactor.core.publisher.Mono.subscribe(Mono.java:4569)
at reactor.core.publisher.Mono.block(Mono.java:1772)
at io.agentscope.examples.advanced.DaMengRAGFlowStudioExample.main(DaMengRAGFlowStudioExample.java:318)
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:104)
at reactor.core.publisher.Mono.block(Mono.java:1773)
... 1 more
Saving final session...
Closing resources...
2026-03-05 12:22:57.116 INFO [] com.zaxxer.hikari.HikariDataSource Line:349 - HikariPool-1 - Shutdown initiated...
2026-03-05 12:22:57.118 INFO [] com.zaxxer.hikari.HikariDataSource Line:351 - HikariPool-1 - Shutdown completed.
Shutting down Studio...
✓ Done
2026-03-05 12:22:57.120 INFO [] io.agentscope.core.studio.StudioWebSocketClient Line:154 - Socket.IO disconnected from /python namespace
2026-03-05 12:23:57.137 INFO [] io.agentscope.core.model.transport.HttpTransportFactory Line:185 - Shutting down 1 managed HttpTransport(s)
Environment (please complete the following information):
AgentScope-Java Version: 1.0.10-SNAPSHOT
Java Version: 21
OS: windows11
Additional context
Add any other context about the problem here.