Repository navigation
fix(accumulator): warn on malformed streamed tool arguments - #2844
mikemikimike wants to merge 22 commits into
Conversation
|
The added observability is useful, but I think this exact form creates two safety problems:
A minimal fail-closed contract would be:
For AgentScope, this belongs locally in the accumulator/ |
|
Addressed in 6106aa9: malformed tool-call diagnostics now log only tool id/name, UTF-8 byte length, SHA-256 digest, exception type, and message. The raw argument payload is no longer emitted to default logs. Existing {} fallback and merged-argument behavior remain unchanged. Focused tests (16/16), module tests, Spotless, and git diff --check pass. The earlier full CI failure was unrelated, in agentscope-harness teardown. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Thanks — The execution-integrity issue is still present, though, and the new regression currently locks it in: A minimal follow-up can stay local and avoid choosing a repair policy here:
If changing |
|
Addressed the remaining execution-integrity concern in
Local validation with JDK 21:
|
|
This PR currently conflicts with the git fetch origin
git checkout codex/2841-tool-call-parse-diagnostics
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review once the conflicts are resolved. Automated notification by github-manager-bot |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
PR #2844 makes malformed streamed tool arguments fail closed: ToolCallsAccumulator marks the final block PARSE_FAILED, clears merged args and logs a redacted diagnostic (id/name/length/sha256), and ReActAgent.executeToolCalls short-circuits the batch into error results. The core idea is right and the earlier log-leak concern is resolved, but the guard fires on every intermediate streaming snapshot (per-chunk WARN + SHA-256 spam), rejects valid sibling calls in mixed batches, and is bypassable on the permission-HITL resume path where ASKING/ALLOWED overwrites PARSE_FAILED — overall: useful fix, needs the three warnings addressed before the fail-closed guarantee actually holds.
Findings
- [Warning] agentscope-core/src/main/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulator.java:131 — build() is also invoked per streamed chunk (LegacyHookDispatcher.fireReasoningChunk → ReasoningContext.getAccumulatedToolCall, and resolveToolCallId for id-less fragments), so the new catch block logs a WARN + full SHA-256 over the partial payload for essentially every argument fragment of every normally-streamed tool call (O(n²) hashing, log noise that drowns real parse failures), and mid-stream ReasoningChunkEvent snapshots now report PARSE_FAILED with empty input while the final args may be valid. Distinguish the final build from intermediate snapshots (e.g. a finalize flag from buildAllToolCalls/buildFinalMessage).
- [Warning] agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3527 — the anyMatch guard rejects the entire batch when any single call is PARSE_FAILED: valid sibling calls in a parallel batch are also rejected with the same "malformed tool arguments" message (behavior change vs main, misleading per-call feedback). Prefer synthesizing errors only for the malformed calls and dispatching the rest, or a per-call message naming the failing call.
- [Warning] agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3527 — PARSE_FAILED does not survive the permission HITL flow: updateToolCallStates (ReActAgent.java:3028-3047) overwrites the context block state to ASKING/ALLOWED before the pause, applyConfirmResults (ReActAgent.java:2112) promotes it to ALLOWED, and resumeAgent() → acting(0) re-extracts calls from the context — so a malformed call that was ASK-gated and approved (or auto-allowed next to an ASK-gated sibling) reaches the guard with state=ALLOWED and is dispatched with the cleared empty input map, defeating the "must not execute" guarantee. Enforce at dispatch time or use a flag the permission state machine does not overwrite.
- [Info] agentscope-core/src/main/java/io/agentscope/core/message/ToolCallState.java:32 — new "parse_failed" constant is part of the serialized message model (sessions, RemoteEventCodec sub-agent events, agent-protocol store); same-version Jackson round-trip verified, but older peers/SDKs pinned to the previous enum will fail to decode it in mixed-version deployments.
- [Info] agentscope-core/src/main/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulator.java:125 — with the default codec the logged exceptionType/message are always the JsonException wrapper's constants ("Failed to deserialize JSON to java.util.Map"); the actual parse cause is dropped. Jackson 2.21 already redacts source content, so logging e.getCause()'s class/message would be safe and much more useful.
- [Info] agentscope-core/src/test/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulatorTest.java:109 — new tests cover only the accumulator; the ReActAgent guard is uncovered (matches codecov's missing lines). Add a ReActAgent-level test for a mixed batch and for the ASK → approve → resume path.
Suggestions
- Track "stream complete" on ToolCallBuilder (set from buildAllToolCalls/finalize) so parse-failure handling only applies to final builds.
- Move the malformed-arguments rejection to dispatchToolCalls (or Toolkit.callTools) so it holds for every consumer (external-execution resume, structured output) and cannot be erased by state transitions.
- Include the tool name/id in the synthesized error so the model can correct the right call.
Automated review by github-manager-bot
| // fails. The PARSE_FAILED state prevents dispatch through ReActAgent, and | ||
| // clearing the map keeps the block fail-closed for other consumers too. | ||
| finalArgs.clear(); | ||
| log.warn( |
There was a problem hiding this comment.
build() is not only called once at stream end: it is invoked per streamed chunk via LegacyHookDispatcher.fireReasoningChunk (ReActAgent.java:2677-2689 -> ReasoningContext.getAccumulatedToolCall, LegacyHookDispatcher.java:85) and via resolveToolCallId (ReActAgent.java:2850) for id-less fragments. While streaming is in progress the rawContent is an incomplete JSON prefix, so this catch block now fires for essentially every argument fragment of every normally-streamed tool call: one WARN log plus a full SHA-256 and two UTF-8 byte[] copies over the partial payload per fragment (O(n^2) hashing per tool call on the hot streaming path), and the ToolUseBlock snapshots handed to legacy ReasoningChunkEvent hooks come back with state=PARSE_FAILED and empty input even though the final arguments may be perfectly valid. The final message itself stays correct (the clear only affects the returned copy), but the log signal for genuine parse failures is drowned in per-chunk noise. Please distinguish the final build from intermediate snapshots, e.g. a finalize flag passed from buildAllToolCalls()/buildFinalMessage, or suppress the warn/state/clear while the stream is still accumulating.
| private Mono<List<Map.Entry<ToolUseBlock, ToolResultBlock>>> executeToolCalls( | ||
| List<ToolUseBlock> toolCalls, | ||
| BiConsumer<ToolUseBlock, ToolResultBlock> internalChunkCallback) { | ||
| if (toolCalls.stream().anyMatch(t -> t.getState() == ToolCallState.PARSE_FAILED)) { |
There was a problem hiding this comment.
This guard rejects the entire batch when any single call is PARSE_FAILED. In a parallel batch of [valid, valid, malformed] the two valid calls are also rejected with the same "Tool execution rejected: malformed tool arguments" error even though their arguments parsed fine — a behavior change vs main, where valid siblings executed — and each valid call's error message is misleading, giving the model nothing actionable about which call was actually malformed (it cannot tell its own retry apart). Consider synthesizing the error result only for the PARSE_FAILED calls and dispatching the remaining calls through dispatchToolCalls, or at minimum making the message per-call (name the tool call whose arguments failed to parse).
| private Mono<List<Map.Entry<ToolUseBlock, ToolResultBlock>>> executeToolCalls( | ||
| List<ToolUseBlock> toolCalls, | ||
| BiConsumer<ToolUseBlock, ToolResultBlock> internalChunkCallback) { | ||
| if (toolCalls.stream().anyMatch(t -> t.getState() == ToolCallState.PARSE_FAILED)) { |
There was a problem hiding this comment.
The PARSE_FAILED marker does not survive the permission HITL flow, so this guard is bypassable. In actingStream, updateToolCallStates (ReActAgent.java:3028-3047) overwrites the context ToolUseBlock's state to ASKING/ALLOWED before RequestStopEvent pauses the turn, and applyConfirmResults (ReActAgent.java:2112) then promotes it to ALLOWED. On resume, resumeAgent() -> acting(0) re-extracts tool calls from the context (ReActAgent.java:2872), so a malformed call that was ASK-gated and then approved — or auto-allowed in a batch where a sibling asked — reaches this check with state=ALLOWED: the anyMatch misses and the tool is dispatched with the cleared, empty input map. That defeats the "must not execute" guarantee of the new state (it only fails later if the tool validates required params). Consider enforcing the check at dispatch time (e.g. in dispatchToolCalls/Toolkit, or a malformed flag that the permission state machine does not overwrite) rather than relying on ToolUseBlock.state alone.
| FINISHED("finished"), | ||
|
|
||
| /** The streamed tool arguments failed final JSON parsing and must not execute. */ | ||
| PARSE_FAILED("parse_failed"); |
There was a problem hiding this comment.
state is part of the serialized message model: it is written into persisted sessions (AgentStateStore), remote sub-agent events (RemoteEventCodec) and the agent-protocol task store. Jackson round-trips the new value fine on this version (verified against the repo's Jackson 2.21.1 via @jsonvalue), but peers/SDKs pinned to the previous enum constants will fail to decode a ToolUseBlock carrying "parse_failed" in mixed-version deployments. Worth confirming that cross-version consumers tolerate unknown state values, or noting the constraint for the wire protocol.
| } | ||
| } catch (Exception ignored) { | ||
| // Parsing failed, keep previously merged args | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
With the default codec the caught exception is always JsonUtils' wrapper: exceptionType is io.agentscope.core.util.JsonException and message is the constant "Failed to deserialize JSON to java.util.Map", so the last two log fields tell you nothing about why parsing failed and the underlying cause (e.g. Jackson's "Unexpected character ... column: N") is dropped on the floor. Jackson 2.21 already redacts source content from its exception messages, so including e.getCause()'s class and message — or passing the throwable as the trailing SLF4J argument — would be both safe and far more diagnostic.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
PR #2844 makes malformed streamed tool arguments fail closed: ToolCallsAccumulator marks the final block PARSE_FAILED, clears merged args and logs a redacted diagnostic (id/name/length/sha256), and ReActAgent.executeToolCalls short-circuits the batch into error results. The core idea is right and the earlier log-leak concern is resolved, but the guard fires on every intermediate streaming snapshot (per-chunk WARN + SHA-256 spam), rejects valid sibling calls in mixed batches, and is bypassable on the permission-HITL resume path where ASKING/ALLOWED overwrites PARSE_FAILED — overall: useful fix, needs the three warnings addressed before the fail-closed guarantee actually holds.
Findings
- [Warning] agentscope-core/src/main/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulator.java:131 — build() is also invoked per streamed chunk (LegacyHookDispatcher.fireReasoningChunk → ReasoningContext.getAccumulatedToolCall, and resolveToolCallId for id-less fragments), so the new catch block logs a WARN + full SHA-256 over the partial payload for essentially every argument fragment of every normally-streamed tool call (O(n²) hashing, log noise that drowns real parse failures), and mid-stream ReasoningChunkEvent snapshots now report PARSE_FAILED with empty input while the final args may be valid. Distinguish the final build from intermediate snapshots (e.g. a finalize flag from buildAllToolCalls/buildFinalMessage).
- [Warning] agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3527 — the anyMatch guard rejects the entire batch when any single call is PARSE_FAILED: valid sibling calls in a parallel batch are also rejected with the same "malformed tool arguments" message (behavior change vs main, misleading per-call feedback). Prefer synthesizing errors only for the malformed calls and dispatching the rest, or a per-call message naming the failing call.
- [Warning] agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3527 — PARSE_FAILED does not survive the permission HITL flow: updateToolCallStates (ReActAgent.java:3028-3047) overwrites the context block state to ASKING/ALLOWED before the pause, applyConfirmResults (ReActAgent.java:2112) promotes it to ALLOWED, and resumeAgent() → acting(0) re-extracts calls from the context — so a malformed call that was ASK-gated and approved (or auto-allowed next to an ASK-gated sibling) reaches the guard with state=ALLOWED and is dispatched with the cleared empty input map, defeating the "must not execute" guarantee. Enforce at dispatch time or use a flag the permission state machine does not overwrite.
- [Info] agentscope-core/src/main/java/io/agentscope/core/message/ToolCallState.java:32 — new "parse_failed" constant is part of the serialized message model (sessions, RemoteEventCodec sub-agent events, agent-protocol store); same-version Jackson round-trip verified, but older peers/SDKs pinned to the previous enum will fail to decode it in mixed-version deployments.
- [Info] agentscope-core/src/main/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulator.java:125 — with the default codec the logged exceptionType/message are always the JsonException wrapper's constants ("Failed to deserialize JSON to java.util.Map"); the actual parse cause is dropped. Jackson 2.21 already redacts source content, so logging e.getCause()'s class/message would be safe and much more useful.
- [Info] agentscope-core/src/test/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulatorTest.java:109 — new tests cover only the accumulator; the ReActAgent guard is uncovered (matches codecov's missing lines). Add a ReActAgent-level test for a mixed batch and for the ASK → approve → resume path.
Suggestions
- Track "stream complete" on ToolCallBuilder (set from buildAllToolCalls/finalize) so parse-failure handling only applies to final builds.
- Move the malformed-arguments rejection to dispatchToolCalls (or Toolkit.callTools) so it holds for every consumer (external-execution resume, structured output) and cannot be erased by state transitions.
- Include the tool name/id in the synthesized error so the model can correct the right call.
Automated review by github-manager-bot
| // fails. The PARSE_FAILED state prevents dispatch through ReActAgent, and | ||
| // clearing the map keeps the block fail-closed for other consumers too. | ||
| finalArgs.clear(); | ||
| log.warn( |
There was a problem hiding this comment.
build() is not only called once at stream end: it is invoked per streamed chunk via LegacyHookDispatcher.fireReasoningChunk (ReActAgent.java:2677-2689 -> ReasoningContext.getAccumulatedToolCall, LegacyHookDispatcher.java:85) and via resolveToolCallId (ReActAgent.java:2850) for id-less fragments. While streaming is in progress the rawContent is an incomplete JSON prefix, so this catch block now fires for essentially every argument fragment of every normally-streamed tool call: one WARN log plus a full SHA-256 and two UTF-8 byte[] copies over the partial payload per fragment (O(n^2) hashing per tool call on the hot streaming path), and the ToolUseBlock snapshots handed to legacy ReasoningChunkEvent hooks come back with state=PARSE_FAILED and empty input even though the final arguments may be perfectly valid. The final message itself stays correct (the clear only affects the returned copy), but the log signal for genuine parse failures is drowned in per-chunk noise. Please distinguish the final build from intermediate snapshots, e.g. a finalize flag passed from buildAllToolCalls()/buildFinalMessage, or suppress the warn/state/clear while the stream is still accumulating.
| private Mono<List<Map.Entry<ToolUseBlock, ToolResultBlock>>> executeToolCalls( | ||
| List<ToolUseBlock> toolCalls, | ||
| BiConsumer<ToolUseBlock, ToolResultBlock> internalChunkCallback) { | ||
| if (toolCalls.stream().anyMatch(t -> t.getState() == ToolCallState.PARSE_FAILED)) { |
There was a problem hiding this comment.
This guard rejects the entire batch when any single call is PARSE_FAILED. In a parallel batch of [valid, valid, malformed] the two valid calls are also rejected with the same "Tool execution rejected: malformed tool arguments" error even though their arguments parsed fine — a behavior change vs main, where valid siblings executed — and each valid call's error message is misleading, giving the model nothing actionable about which call was actually malformed (it cannot tell its own retry apart). Consider synthesizing the error result only for the PARSE_FAILED calls and dispatching the remaining calls through dispatchToolCalls, or at minimum making the message per-call (name the tool call whose arguments failed to parse).
| private Mono<List<Map.Entry<ToolUseBlock, ToolResultBlock>>> executeToolCalls( | ||
| List<ToolUseBlock> toolCalls, | ||
| BiConsumer<ToolUseBlock, ToolResultBlock> internalChunkCallback) { | ||
| if (toolCalls.stream().anyMatch(t -> t.getState() == ToolCallState.PARSE_FAILED)) { |
There was a problem hiding this comment.
The PARSE_FAILED marker does not survive the permission HITL flow, so this guard is bypassable. In actingStream, updateToolCallStates (ReActAgent.java:3028-3047) overwrites the context ToolUseBlock's state to ASKING/ALLOWED before RequestStopEvent pauses the turn, and applyConfirmResults (ReActAgent.java:2112) then promotes it to ALLOWED. On resume, resumeAgent() -> acting(0) re-extracts tool calls from the context (ReActAgent.java:2872), so a malformed call that was ASK-gated and then approved — or auto-allowed in a batch where a sibling asked — reaches this check with state=ALLOWED: the anyMatch misses and the tool is dispatched with the cleared, empty input map. That defeats the "must not execute" guarantee of the new state (it only fails later if the tool validates required params). Consider enforcing the check at dispatch time (e.g. in dispatchToolCalls/Toolkit, or a malformed flag that the permission state machine does not overwrite) rather than relying on ToolUseBlock.state alone.
| FINISHED("finished"), | ||
|
|
||
| /** The streamed tool arguments failed final JSON parsing and must not execute. */ | ||
| PARSE_FAILED("parse_failed"); |
There was a problem hiding this comment.
state is part of the serialized message model: it is written into persisted sessions (AgentStateStore), remote sub-agent events (RemoteEventCodec) and the agent-protocol task store. Jackson round-trips the new value fine on this version (verified against the repo's Jackson 2.21.1 via @jsonvalue), but peers/SDKs pinned to the previous enum constants will fail to decode a ToolUseBlock carrying "parse_failed" in mixed-version deployments. Worth confirming that cross-version consumers tolerate unknown state values, or noting the constraint for the wire protocol.
| } | ||
| } catch (Exception ignored) { | ||
| // Parsing failed, keep previously merged args | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
With the default codec the caught exception is always JsonUtils' wrapper: exceptionType is io.agentscope.core.util.JsonException and message is the constant "Failed to deserialize JSON to java.util.Map", so the last two log fields tell you nothing about why parsing failed and the underlying cause (e.g. Jackson's "Unexpected character ... column: N") is dropped on the floor. Jackson 2.21 already redacts source content from its exception messages, so including e.getCause()'s class and message — or passing the throwable as the trailing SLF4J argument — would be both safe and far more diagnostic.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed head 76ca00d7 (one commit since my 111d884f review). The rework resolves the issue I flagged last round: the parse guard is applied only on the final build, so intermediate stream chunks no longer trip it, and rejection is now scoped per tool call instead of failing the whole batch — a valid sibling executes while the malformed call gets an error result. Dropping ToolCallState.PARSE_FAILED in favour of an internal metadata marker is safe here (the constant never reached main, and no remaining reference exists in the tree), and the new testIntermediateSnapshotDoesNotFailBeforeStreamCompletes plus the two ReActAgentHitlTest cases cover the behaviour change well. One follow-up keeps this a comment rather than an approval: because the marker is only written on the final build, the non-final view returned by getAccumulatedToolCall(...) — which LegacyHookDispatcher hands to hooks — is no longer fail-closed. Details inline; the fix looks otherwise good.
Findings
- [Warning]
ToolCallsAccumulator.java:129— non-final snapshots keep partial args/PENDINGstate;LegacyHookDispatcher.java:85consumes that view, so hook consumers see a well-formed-looking block for a rejected call. - [Info]
ReActAgent.java:3550— id-keyed correlation collapses duplicate tool-call ids; a missing id turns into an NPE insideMap.entry. - [Info]
MessageMetadataKeys.java:158— internal marker is persisted and replayed; confirm formatters strip it.
Checks
- CI:
Check License,Check Module Sync,build (ubuntu-latest),build (windows-latest),codecov/patch,license/cla— all passing at review time. - CLA: signed.
Automated review by github-manager-bot
| .toList()) | ||
| results -> { | ||
| for (int i = 0; i < executableCalls.size(); i++) { | ||
| resultsById.put(executableCalls.get(i).getId(), results.get(i)); |
There was a problem hiding this comment.
[Info] Correlating by toolCall.getId() is the right shape for partial rejection, but it collapses when a stream emits two tool calls under one id: resultsById.put overwrites the first entry and both Map.entry pairs resolve to the last result, whereas the old positional pairing kept one result per call. A duplicate-id guard, or pairing the rejected entries positionally alongside executableCalls, closes that hole. Map.entry also rejects null values, so if dispatchToolCalls ever yields fewer results than executableCalls the lookup becomes an NPE rather than the previous IndexOutOfBoundsException — same onErrorResume path, just a changed failure mode.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
The PR adds final-stream malformed-JSON diagnostics, clears stale arguments, and rejects marked tool calls while allowing valid siblings to run. It resolves the previous snapshot exposure and result-correlation findings, but the parser-failure marker is still not durable across externally reconstructed HITL confirmations and is exported over A2A. Overall verdict: request changes, because approving a malformed call through these adapters can bypass the rejection guard.
Previous round's findings
ToolCallsAccumulator.java:129non-final hook snapshots exposed partial arguments — resolved (the parse-failure path now clears input for both final and non-final builds).ReActAgent.java:3538ID-keyed result correlation could collapse duplicate or missing IDs — resolved (the new ordered loop pairs each source call with the next executable result).MessageMetadataKeys.java:234internal-marker persistence/replay needed formatter checks — unresolved (the A2A parser copies allToolUseBlock.metadataentries into outbound metadata).
Findings
- [Warning]
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3527— Confirmation adapters can drop the parse-failure marker and let a malformed call execute after approval. - [Info]
agentscope-core/src/main/java/io/agentscope/core/message/MessageMetadataKeys.java:234— The internal marker is exported in A2A metadata.
Checks
- CLA: signed (
license/cla= success on heada2d5aeec). - CI at review time:
Check License,Check Module Sync,build (ubuntu-latest),build (windows-latest),codecov/patch,license/cla— all pass.
Verified good
- Final malformed parsing clears previously merged input, emits the existing
{}content fallback, and records the marker only at final build. - Intermediate malformed snapshots clear input without receiving a terminal marker, and the added accumulator test covers completion by a later fragment.
- A valid empty object remains pending, while the ReAct HITL tests cover rejection plus execution of a valid sibling.
- Diagnostics log tool identity, byte length, SHA-256, and cause type without logging raw tool arguments.
- The execution loop preserves original tool-call order while omitting marked calls from dispatch and synthesizing their error results.
Automated review by github-manager-bot
Additional notes (not anchored to a changed line)
- [INFO]
agentscope-core/src/main/java/io/agentscope/core/message/MessageMetadataKeys.java:234—TOOL_CALL_PARSE_FAILEDis described as internal but is stored in normalToolUseBlock.metadata.ToolUseBlockParsercopies that map into A2ADataPart.metadata, so malformed calls now expose this internal key on the A2A wire format (and state serialization persists it). Either strip the key at protocol/export boundaries or make this a documented public metadata extension; otherwise downstream A2A consumers observe an unplanned payload change. (line outside diff)
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-review after the new head bfca6786. Both blocking findings from the previous round are resolved: the parse-failure marker is now durable across externally reconstructed HITL confirmations (carried from the retained asking blocks in applyConfirmResults, with a regression test that rebuilds the block without metadata), and the internal _tool_call_parse_failed key is no longer exported over A2A. Ordering between toolCalls and dispatched results is preserved by the new pair loop, and the test coverage (fail-closed final build, non-final snapshot, valid empty object, non-ASCII payload) is thorough. Verdict: approved, with two small non-blocking notes below.
Findings
- [Warning]
ToolCallsAccumulator.java:131—catch (Exception e)is broader than the JSON failure it detects and converts any throw into a permanent fail-closed rejection. - [Info]
ToolCallsAccumulator.java:104—ToolCallState state = ToolCallState.PENDINGis a constant local duplicating the builder default. - [Info]
ReActAgent.java:3614—hasParseFailurerelies on metadata only, so blocks reconstructed from persisted context still read as clean; worth documenting or keeping the raw payload for re-validation.
Suggestions
No further changes required for this PR to be mergeable; the three points above are comment-level and can be addressed in a follow-up if you prefer.
Automated review by github-manager-bot
| ToolUseBlock build() { | ||
| ToolUseBlock build(boolean finalBuild) { | ||
| Map<String, Object> finalArgs = new HashMap<>(args); | ||
| ToolCallState state = ToolCallState.PENDING; |
There was a problem hiding this comment.
[Info] ToolCallState state = ToolCallState.PENDING; is a constant local that is only ever fed to .state(state) on line 167, and ToolCallState / finalMetadata are now built from a copy of metadata instead of the field directly. Two small cleanups:
- drop the local and use
ToolCallState.PENDINGat the builder call (or drop.state(...)entirely ifToolUseBlock.builder()already defaults toPENDING— it currently duplicates that default), - if
.state(PENDING)is meant to be meaningful, add a comment saying the state is deliberately reset for a failed parse; otherwise the reader has to guess.
Not a blocker — just a bit of noise in an otherwise tight change.
345c956 to
67363bf
Compare
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed the two commits pushed since bfca6786 (head now 2934f4a1). One is an upstream main merge, the other is docs(core): document tool parse failure metadata boundaries. Verdict: approved — and all three of my previous-round notes are now closed.
catch (Exception)was broader than the JSON failure it detects — resolved, nowcatch (JsonException)atToolCallsAccumulator.java:130. That is the right scope and still fail-closed for the case that matters:JacksonJsonCodec.fromJsonwraps everyJsonProcessingExceptionintoJsonException, so malformed bodies, truncated stream tails and top-level array/scalar payloads (MismatchedInputException) all still set the marker, while a non-JSON codec fault now propagates instead of permanently poisoning the tool call.- Constant local
ToolCallState state = ToolCallState.PENDING— resolved, gone frombuild(...). hasParseFailurereads metadata only, so a reconstructed block looks clean — resolved as documentation inMessageMetadataKeys.TOOL_CALL_PARSE_FAILED: raw arguments are discarded, the marker must survive persistence/reconstruction, providers and protocol formatters must omit it outbound. Enforcement is still metadata-only, which is a fair trade for keeping the rejected payload from being re-sent; noted inline rather than asked again.- The pair-ordering logic in
executeToolCallssurvived the upstream merge intact: parse-failed calls are filtered out of dispatch, then re-inserted in original position viaresultIndex, soToolResultBlockordering still matchestoolCalls, and the all-failed case short-circuits onexecutableCalls.isEmpty()instead of calling the toolkit with an empty list.
The two new provider tests (AnthropicMessageConverterTest, OpenAIMessageConverterTest) are the right shape — they assert the internal key never reaches an outbound payload rather than re-testing the parser. They did not execute on this head though: build (ubuntu-latest) aborts in agentscope-harness on HarnessMiddlewareActivePointsTest (JUnitException: Failed to close extension context, root cause IOException: Failed to delete temp directory /tmp/junit-… DirectoryNotEmptyException), a @TempDir cleanup race in a module this PR does not touch, which leaves every downstream module — Anthropic, OpenAI, A2A client — SKIPPED. build (windows-latest) cancelled behind it. That is an infra flake, not a defect in this change, and CI re-runs are handled by the separate feedback/CI job rather than by this review, so I am not holding the approval for it.
CLA signed (license/cla: success), mergeable, mergeStateStatus=UNSTABLE from that failing check only, no conflict.
Automated review by github-manager-bot
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
Post-merge validation for |
Summary
Fixes the silent loss of streamed tool-call JSON parse failures described in Issue #2841.
The raw malformed argument string is not retained for recovery. Tool arguments may contain sensitive user data; diagnostics use a digest, byte length, and parser details without copying the payload into default logs or persisted content.
Testing
Fixes #2841