[Bug]: ExecutionConfig retry settings are ignored for tool failures
Describe the bug
When a tool call fails with an exception, the retry policy configured in ExecutionConfig (maxAttempts, retryOn, backoff) is never applied. The tool is invoked exactly once and the failure is immediately returned as a ToolResultBlock error result, even for clearly retryable errors such as IOException (network/transport failures).
Root cause: ToolExecutor.executeWithInfrastructure(...) runs the compatibility entry execute(...), which converts tool failures into ToolResultBlock error results inside executeCore(...) before the scheduling/timeout/retry layers run. By the time applyRetry(...) executes, failures are already completed results, so retryWhen never sees an error signal. Only the error emitted by the timeout(...) operator can still reach the retry layer.
To Reproduce
Steps to reproduce the behavior:
- Add the following test class to
agentscope-core/src/test/java/io/agentscope/core/tool/RetryReproTest.java:
package io.agentscope.core.tool;
import io.agentscope.core.message.ToolResultBlock;
import io.agentscope.core.message.ToolUseBlock;
import io.agentscope.core.model.ExecutionConfig;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
/** Minimal reproduction for tool retry behavior. */
class RetryReproTest {
static final AtomicInteger CALLS = new AtomicInteger(0);
static class FlakyTools {
@Tool(name = "flaky", description = "Fails once, then recovers")
public String flaky() throws IOException {
if (CALLS.incrementAndGet() == 1) {
throw new IOException("Network down");
}
return "recovered";
}
}
@Test
void reproduce() {
Toolkit toolkit = new Toolkit();
toolkit.registerTool(new FlakyTools());
ExecutionConfig config =
ExecutionConfig.builder()
.maxAttempts(3) // 1 initial attempt + up to 2 retries
.initialBackoff(Duration.ofMillis(100))
.maxBackoff(Duration.ofMillis(200))
.retryOn(ExecutionConfig.RETRYABLE_ERRORS) // IOException is retryable
.build();
ToolUseBlock call =
ToolUseBlock.builder()
.id("call-1")
.name("flaky")
.input(Map.of())
.content("{}") // required: schema validation reads ToolUseBlock.content()
.build();
List<ToolResultBlock> results =
toolkit.callTools(List.of(call), config, null, null).block();
System.out.println("REPRO attempts = " + CALLS.get());
System.out.println("REPRO state = " + results.get(0).getState());
System.out.println("REPRO output = " + results.get(0).getOutput());
}
@Test
void timeoutComparison() {
AtomicInteger timeoutCalls = new AtomicInteger(0);
Toolkit toolkit = new Toolkit();
toolkit.registerTool(
new AgentTool() {
@Override
public String getName() {
return "never";
}
@Override
public String getDescription() {
return "never completes";
}
@Override
public Map<String, Object> getParameters() {
return Map.of();
}
@Override
public Mono<ToolResultBlock> callAsync(ToolCallParam param) {
timeoutCalls.incrementAndGet();
return Mono.never();
}
});
ExecutionConfig config =
ExecutionConfig.builder()
.timeout(Duration.ofMillis(100))
.maxAttempts(3)
.initialBackoff(Duration.ofMillis(50))
.maxBackoff(Duration.ofMillis(100))
.build();
ToolUseBlock call =
ToolUseBlock.builder()
.id("call-2")
.name("never")
.input(Map.of())
.content("{}")
.build();
List<ToolResultBlock> results =
toolkit.callTools(List.of(call), config, null, null).block();
System.out.println("REPRO timeout attempts = " + timeoutCalls.get());
System.out.println("REPRO timeout state = " + results.get(0).getState());
System.out.println("REPRO timeout output = " + results.get(0).getOutput());
}
}
- Run it from the repository root:
mvn -pl agentscope-core test -Dtest=RetryReproTest -Dsurefire.failIfNoSpecifiedTests=false
- See the printed output and the surefire report (see Error messages).
Expected behavior
The first failure should surface as an error signal to the retry layer, so the tool is re-invoked and recovers:
REPRO attempts = 2
REPRO state = RUNNING
REPRO output = ["recovered"]
(RUNNING is the framework's default state for a plain successful tool result.) In the timeout comparison, the tool should be re-invoked on every attempt and the final error result should keep the root cause:
REPRO timeout attempts = 3
REPRO timeout state = ERROR
REPRO timeout output = [Error: Tool execution failed: Tool execution timeout after PT0.1S]
Error messages
No exception is thrown; the symptom is the missing retry. Actual output on the current main:
REPRO attempts = 1
REPRO state = ERROR
REPRO output = [Error: Tool execution failed: Network down]
REPRO timeout attempts = 1
REPRO timeout state = ERROR
REPRO timeout output = [Error: Tool execution failed: Retries exhausted: 2/2]
Observations:
- For the flaky tool, no
Retrying tool call 'flaky' ...warning ever appears: the retry layer never runs for tool exceptions. - The timeout comparison isolates the two halves of the bug: the timeout error signal is retried (the
Retries exhausted: 2/2message proves 3 attempts), but the tool is still only invoked once (REPRO timeout attempts = 1) — retries merely re-subscribe the already-assembled chain instead of re-invoking the tool. Additionally, the exhausted-retry message replaces the real cause (Tool execution timeout after PT0.1S) with the genericRetries exhausted: 2/2.
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.3-SNAPSHOT (reproduced on
mainat commitddad42e3; the same code path exists in earlier 2.0.x) - Java Version: 17
- OS: macOS (the issue is OS-independent)
Additional context
- Relevant code:
ToolExecutor.executeCore(...)converts failures withToolResultBlock.error(...);ToolExecutor.executeWithInfrastructure(...)then pipes that chain throughapplyScheduling/applyTimeout/applyRetry/applyShutdownGuard, soapplyRetryonly ever sees completed results (except timeouts). - A fix needs the tool invocation to keep failures as reactive error signals until after the timeout/retry layers (for example, a separate execution channel that is re-invoked per attempt), while preserving the existing
Toolkit.callTool(...)contract that direct calls still receive error results. - The fix must also keep
ToolSuspendException(external-execution suspension) from ever being retried, even when it is wrapped in reflection/future/arbitrary exceptions, since replaying a suspension duplicates side effects. - I am preparing a fix and will open a PR referencing this issue.
Filed #3114 for a second symptom of the same execute(...) / executeWithInfrastructure(...) divergence described here: Toolkit.callTool(...) returns a ToolResultBlock with null id and name, because withIdAndName(...) is only ever applied inside executeWithInfrastructure(...).
Reproduced on main at c5db8f72:
REPRO callTool id=null name=null state=RUNNING
REPRO callTools id=call-batch name=echo state=RUNNING
Not the same bug — the retry analysis here is separate and more involved — but it may be relevant to the fix. You note that a fix should preserve the Toolkit.callTool(...) contract that direct calls still receive error results; if that means introducing a separate execution channel, that seems like the natural moment to also decide whether callTool shares the stamping stage, or stays deliberately thin and gets that documented.
I have kept #3114 scoped narrowly to the id/name defect so it does not cut across your PR.
Issue Evaluation
Category: bug (area/core/tool) | Status: Confirmed — still reproducible on current main | Severity: medium-high
Verified against main @ 3c1c29c0 (engine-assisted static read; this issue was below the newest-open scan window, so it is being evaluated here for the first time).
| Claim | Result | Evidence |
|---|---|---|
Tool exceptions never reach the retry layer — the tool runs exactly once and the failure is returned as a ToolResultBlock error |
TRUE | agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java:302-310 — executeCore catches errors from tool.callAsync(...) and emits Mono.just(ToolResultBlock.error(...)), so the downstream Mono completes successfully and retryWhen sees no error signal |
Root cause: the compatibility entry execute(...) is what executeWithInfrastructure(...) runs, so the conversion happens before scheduling/timeout/retry |
TRUE | ToolExecutor.java:470 (execute(param, ...)) → :473-475 (applyScheduling / applyTimeout / applyRetry). Only an error raised by the timeout(...) operator at :509 can still propagate to applyRetry — exactly the exception the report calls out |
Same divergence produces null id/name on the Toolkit.callTool path |
TRUE | Toolkit.java:559-560 delegates to executor.execute(param) (not executeWithInfrastructure), and withIdAndName(...) is applied only at ToolExecutor.java:480 — cross-links to #3114, which was already confirmed on 2026-09-12 |
Impact. Any user who configures ExecutionConfig with maxAttempts / retryOn / backoff on a tool gets silently no retrying: a transient IOException from an HTTP-backed tool fails the whole ReAct turn instead of being retried. The configuration is accepted and documented, so this is a contract violation, not a missing feature.
Testability. No test covers retry-on-tool-failure today: ExecutionConfigTest only exercises the RETRYABLE_ERRORS predicate, ExecutionConfigE2ETest is model-level, and ToolExecutorTest asserts the single-attempt error wrapping — i.e. the current tests actively pin the buggy behaviour. A regression test needs only a ToolBase stub that throws IOException on the first call and succeeds on the second, plus an ExecutionConfig(maxAttempts=2); no external services.
Behaviour-change note for reviewers (design call, not a defect). Fixing this means tools that used to fail once will now be attempted up to maxAttempts times. That is what the configuration promises, but it changes observable behaviour for non-idempotent tools that today rely on the accidental single-shot semantics — worth one line in the release note. The two candidate shapes are (a) keep the raw error signal until after applyRetry and convert to ToolResultBlock.error at the boundary, or (b) apply retry inside executeCore; (a) preserves the timeout-only path and is the smaller change.
No automated PR from us. The issue author already has PR #2830 (OPEN, updated 2026-09-24, fix(tool): honor execution config retries for tool exceptions) against this exact root cause, and #3114 is the second symptom of the same divergence. A generated patch would duplicate in-flight community work; #2830 will be picked up on the scheduled PR review rotation instead, where the points above (raw-signal-vs-wrapped-error, the withIdAndName bypass, and re-basing the ToolExecutorTest assertion) get inline review.
Automated evaluation by github-manager-bot