[Bug]:Returning one external tool result redispatches suspended sibling calls
Describe the bug
When two external tool calls from the same model response have both been dispatched and suspended, returning one result through AgentSession.respond dispatches the unanswered tool again. In a local quote queue, answering quote-a enqueues B-2 alongside the original B-1 and replaces the pending event for quote-b.
To Reproduce
- Create a Harness session backed by
InMemorySessionLogStore. Use a deterministic model whose first response requestsquote-aandquote-b. - Register a tool whose
callAsyncrecords the call ID and returnsToolResultBlock.suspended(call). - Submit a turn and wait for it to suspend. Record the event ID of the pending
quote-brequest. - Call
session.respond("quote-a", "A")and wait for the response execution to settle. The dispatch list containsquote-btwice, and the pending event forquote-bhas a new ID.
Runnable regression test
Add import java.util.Set; and the following method to agentscope-harness/src/test/java/io/agentscope/harness/agent/session/AgentSessionTest.java. The method uses the existing fixtures in that class.
@Test
void partialExternalAnswerLeavesTheOriginalSiblingRequestPending() {
var dispatches = new CopyOnWriteArrayList<String>();
var toolkit = new Toolkit();
toolkit.registerAgentTool(
new ToolBase(
ToolBase.builder()
.name("external_quote")
.description("Submit a quote request")
.inputSchema(Map.of("type", "object"))) {
@Override
public Mono<ToolResultBlock> callAsync(ToolCallParam param) {
var call = param.getToolUseBlock();
dispatches.add(call.getId());
return Mono.just(ToolResultBlock.suspended(call));
}
});
var calls = new AtomicInteger();
Model model =
new Model() {
@Override
public String getModelName() {
return "external-quote-test";
}
@Override
public Flux<ChatResponse> stream(
List<Msg> messages, List<ToolSchema> tools, GenerateOptions options) {
if (calls.getAndIncrement() != 0)
return response(TextBlock.builder().text("done").build());
var batch =
List.<ContentBlock>of(
ToolUseBlock.builder()
.id("quote-a")
.name("external_quote")
.build(),
ToolUseBlock.builder()
.id("quote-b")
.name("external_quote")
.build());
return Flux.just(ChatResponse.builder().content(batch).build());
}
};
var store = new InMemorySessionLogStore();
String bEventId;
String turnId;
try (var agent = agent(model, toolkit, store)) {
var session = session(agent);
var first = session.await(session.submit("compare quotes")).block(WAIT);
assertEquals("suspended", first.status(), session.executionError());
assertEquals(Set.of("quote-a", "quote-b"), session.pending().keySet());
bEventId = session.pending().get("quote-b").eventId();
turnId = first.turnId();
}
try (var agent = agent(model, toolkit, store)) {
var session = session(agent);
var partial = session.await(session.respond("quote-a", "A")).block(WAIT);
assertEquals("suspended", partial.status(), session.executionError());
assertEquals(turnId, partial.turnId());
assertEquals(1, calls.get());
assertEquals(List.of("quote-a", "quote-b"), dispatches.stream().sorted().toList());
assertEquals(Set.of("quote-b"), session.pending().keySet());
assertEquals(bEventId, session.pending().get("quote-b").eventId());
var completed = session.await(session.respond("quote-b", "B")).block(WAIT);
assertEquals("completed", completed.status(), session.executionError());
assertEquals(turnId, completed.turnId());
assertTrue(session.pending().isEmpty());
assertEquals(2, calls.get());
}
}
Run from the repository root.
mvn -B -T1C -pl agentscope-harness -am test \
'-Dtest=AgentSessionTest#partialExternalAnswerLeavesTheOriginalSiblingRequestPending' \
-Dsurefire.failIfNoSpecifiedTests=false
Expected behavior
After the first answer, the same turn remains suspended with the original quote-b request pending. Each tool has been dispatched once. Answering quote-b then lets the turn complete.
Error messages
The regression test fails with this assertion on the unpatched baseline.
expected: <[quote-a, quote-b]> but was: <[quote-a, quote-b, quote-b]>
Environment
- AgentScope-Java Version —
2.1.0-SNAPSHOT, commit874c9cb0f2efc79b42e86c521cd24de159d3d035 - Java Version — Eclipse Temurin 21.0.11 with the project's Java 17 compilation target
- OS — macOS 26.2, arm64
Additional context
Submitting both results in a single respond(Map) call completes the turn with the original two dispatches.
Claiming — thank you for the runnable regression, it pins the exact contract: answering one suspended call must leave the other sibling's original pending request untouched. The dispatch list gaining quote-b twice plus a new event id indicates the resume path re-enters the "pending calls from the last model response" sweep and re-suspends calls whose results were never part of the returned answer. Proposed direction: when a partial external answer arrives, resume execution with only the answered call marked, and reconcile the remaining suspended calls against the existing pending events (match by tool-call id — reuse, don't redispatch); only calls absent from the pending set get synthesized. Will run your test as the acceptance gate and add the mixed/stale-result regressions alongside it.
Status update before writing any code: the API this report was filed against no longer exists on current main.
The regression targets AgentSession.respond / session.pending / InMemorySessionLogStore (baseline 874c9cb0). Three days after this issue was opened, #4154 (a4306d63, "streamline public APIs") removed the entire session layer — SessionExecution, SessionInbox, SessionRecorder, the AtomicSessionStorage → AtomicJournalStorage rename, and the AgentSession facade are all gone. External-answer handling now lives in the new recoverable runtime (AgentExecutionHost / AgentRun / ThreadRecovery), with a different suspension model, so I cannot reproduce the sibling-redispatch against the reported call path — there is no AgentSession.respond to call anymore.
I verified the old-path failure mode is real on the reported baseline (the dispatch-sweep you describe is visible in the removed code), but a fix can no longer be a patch to it. Before I re-investigate: does the behavior still reproduce on current main under the new runtime — i.e., does answering one of two suspended external calls re-dispatch the sibling? The new ThreadRecovery replay path may already reconcile pending calls by id (in which case this is fixed by #4154 as a side effect), or may carry the same sweep bug in a new shape (in which case I'll re-target the fix and your regression test at the new API, adapting the fixtures).
Holding the claim until we know which world we're in.
Confirmed this still reproduces on main at 9cfeaad4b (2.1.0-SNAPSHOT), using the current prepareRun() / ToolResultMessage APIs with InMemoryThreadJournalStore.
In both ReActAgent and HarnessAgent, returning only quote-a dispatches quote-b again and replaces its original pending event ID. This reproduces with the same instance and after rebuilding the agent. Returning both results together passes.
I’m planning to fix this against the current APIs and update #4105 accordingly.
Thanks for re-confirming on the new runtime — that settles the open question from my status update, and the fix is yours: #4105 is your branch, you have the repro on the current APIs, and I never got past the API-removal check, so I'm releasing the claim.
One observation from the old path may still transfer: the sibling re-dispatch there came from the resume path re-entering the "pending calls from the last model response" sweep, which re-suspended every call whose result was not part of the returned answer. If the new recovery path kept an analogous sweep, matching pending calls by tool-call id and reusing their existing pending event (reuse, don't redispatch) is the shape that fixes it — your "replaces its original pending event ID" symptom points at the same spot. Happy to review the updated #4105.