Repository navigation
fix(agui): report a frontend tool's error as an ERROR tool result - #3324
Conversation
The AG-UI protocol lets a tool message carry an `error` field, but AguiMessage had no binding for it and the converter built every tool result with ToolResultState.SUCCESS. A frontend tool that failed was therefore reported to the ReActAgent as a successful result, leaving the model with an empty tool output and no signal to retry, report the failure, or ask the user. - bind `error` on AguiMessage. A new @jsoncreator overload takes it; the existing 5-argument constructor is kept and delegates with null, so source compatibility is preserved. - in AguiMessageConverter, build the tool result through ToolResultBlock.error(toolCallId, error) when the client reported an error, and keep any payload sent alongside it rather than discarding it. - include `error` in AguiMessage's toString/equals/hashCode. Tests: three tests in AguiMessageConverterTest cover an error with no payload, an error with a payload, and a blank error (regression guard); a fourth deserializes a tool message through the framework's JSON codec to prove the field is no longer dropped silently. Reverting the converter change fails exactly the three error cases. Co-Authored-By: Claude Code <[email protected]>
|
Two things suggest this is environmental rather than caused by this change:
This PR only touches Could the workflow be re-run? For reference, #3321 also failed CI on |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Well-scoped fix for #3307: binding the AG-UI tool message error field and mapping it to ToolResultState.ERROR is exactly what was missing, and the model can now see a failed frontend tool instead of an empty success. Reviewed against main@f98a685 (the PR base) — no blocking issue found; 1 non-blocking design gap and 3 informational notes are inline.
Verified
- Every tool-result path funnels through
addTextBlock, so the new early-return covers both the text-content case and the no-content case (toMsgcalls it with""for a tool message with a nullcontent); the structured-blocks branch throws for non-user roles, so nothing bypasses the error handling. - The
[ERROR]literal matchesToolResultBlock.error(String, String)(agentscope-core/.../ToolResultBlock.java:242-249), andReActAgent.determineToolResultState(agentscope-core/.../ReActAgent.java:3502-3508) returns the explicitERRORstate before falling back to the prefix check — so the claim that no core change was needed holds. - Backward compatibility: the 5-arg constructor is kept and delegates with
null, and only the 6-arg constructor carries@JsonCreator, so existing Java callers and pre-errorJSON keep working. - Blank/absent
errorkeepsSUCCESS, and thetoolCallIdis preserved on the error block.
Two things to look at
- Round-trip asymmetry (inline,
AguiMessageConverter.java:310) —toAguiMessagedoes not emiterrorand dropsToolResultState, so an ERROR result converts back to a message that only looks like a text payload prefixed with[ERROR]. If the outbound direction is in scope for this protocol, this is worth closing here; otherwise a javadoc note is enough. - CI (below) — both build jobs fail on a test this PR does not touch.
CI status
build (ubuntu-latest) and build (windows-latest) fail in agentscope-service/service-dataplane at ToolConfirmationCoordinatorTest.replacementTurnLeaseCannotReleaseOldTicketAndMayReuseToolUseId:452 (CannotStubVoidMethodWithReturnValue — the when(controlPlaneClient.managedExecutionScope(...)) stub). Nothing in this PR reaches that module, and main@f98a685fd (this PR's base) is green on the same workflow (run 8278), so this is not caused by your change — it looks like the same test is order/isolation-sensitive once it runs in the PR merge context. Please re-run the failed jobs; if it fails again, a maintainer re-run or a look from the service-dataplane owners is the right next step rather than a change on your side.
Holding at COMMENT (not APPROVE) while the required build checks are red. Ping me after a green re-run and I'll re-review.
Automated review by github-manager-bot
| // A frontend tool that failed reports the reason in the AG-UI `error` field | ||
| // rather than in `content`. Report the failure instead of a success, so the | ||
| // model can retry, report it, or ask the user. | ||
| blocks.add(errorResultBlock(aguiMessage.getToolCallId(), error, text)); |
There was a problem hiding this comment.
The new handling is inbound-only: toAguiMessage (same file, lines 133-166) still ignores ToolResultBlock.getState() and never populates error, so an ERROR result leaves this class as a tool message whose text merely starts with [ERROR] and no error field. A client that consumes the outbound side therefore cannot tell a failed frontend tool from a successful one, and re-feeding that message back in only works by the prefix accident in ReActAgent.determineToolResultState. Not blocking if the AG-UI server path only ever uses toMsg, but please either mirror the field here (trb.getState() == ERROR → set error, strip the prefix) or note the asymmetry in the javadoc so the next reader does not assume round-tripping.
There was a problem hiding this comment.
You're right, and thanks for the precise pointer — I confirmed it: toAguiMessage only read trb.getOutput() and trb.getId(), so an ERROR result left here as a tool message carrying the [ERROR] prefix in its text and nothing in error. Round-tripping only worked by the prefix check in ReActAgent.determineToolResultState, which is exactly the accident you describe.
I've mirrored it in this PR (0bb67a2) rather than leaving the asymmetry for the next reader: a ToolResultState.ERROR result now sets error with the [ERROR] prefix stripped, and its text is no longer also appended to content, so a round trip does not carry it in both places. The construction at the end of toAguiMessage now uses the six-arg constructor.
Two things worth flagging on that:
- It is a wire-format change for the outbound direction: an ERROR tool result that used to leave as
content: "[ERROR] <reason>"now leaves aserror: "<reason>"with no content. That is the intent — a client should not have to parse a marker to learn a tool failed — but it is visible to anything already consuming the outbound side. - A non-text output block on an ERROR result is still dropped, same as before; only the text is mirrored. I did not widen the scope to cover that.
There was a problem hiding this comment.
Correction to the paragraph above, after an independent review re-checked it.
I wrote that round-tripping "only worked by the prefix check in ReActAgent.determineToolResultState". That is wrong. toMsg sets ToolResultState.SUCCESS explicitly for a tool message with no error, so determineToolResultState returns at its explicit-state branch and never reaches the prefix check. The prefix is a fallback for a result whose state is null or RUNNING, which this path never produced.
So the pre-fix behaviour was not "saved by an accident" — it was a plain misclassification. A failed frontend tool entered the context as SUCCESS, which is also what let a returnDirect tool in that state take the short-circuit and hand its output back as the final answer. That is now pinned end to end in d190512.
| private final MessageContent content; | ||
| private final List<AguiToolCall> toolCalls; | ||
| private final String toolCallId; | ||
| private final String error; |
There was a problem hiding this comment.
AguiMessage is the only model in this package without @JsonInclude(JsonInclude.Include.NON_NULL) (AguiEvent, ImageInputContent, AudioInputContent, VideoInputContent, DocumentInputContent all have it), and JacksonJsonCodec.createDefaultObjectMapper sets no serialization inclusion, so every outbound AguiMessage — including inside AguiEvent.MessagesSnapshot — now carries one more "error": null key. toolCalls/toolCallId/content already serialize as null today, so this does not break anything by itself; a class-level NON_NULL would be the cleaner fix but is a wire-format change for the existing fields, so it is fine as a follow-up issue rather than part of this PR.
There was a problem hiding this comment.
Agreed, and I've left it out of this PR — toolCalls, toolCallId and content already serialize as null today, so error is consistent with the class rather than a new behaviour, and a class-level @JsonInclude(NON_NULL) would change the wire format for those existing fields. Happy to open a follow-up issue for it if you want one tracked.
There was a problem hiding this comment.
Correction to the paragraph above.
I wrote that toolCalls "already serialize as null today". It does not: the constructor normalises it to an empty list, so it serialises as []. Only content and toolCallId can be null. The conclusion still holds — a class-level annotation would have changed those two — but the claim about toolCalls was wrong and the argument should not rest on it.
This is addressed in 663ed38 by annotating the getter instead, which touches neither.
| + ", toolCallId='" | ||
| + toolCallId | ||
| + "', error='" | ||
| + error |
There was a problem hiding this comment.
toString() now interpolates the raw error text. Worth knowing that frontend-reported errors can carry provider response bodies, stack traces or absolute paths, and this class is a natural logging target — the project guidance is that credentials/error detail must not leak into logs. content is already dumped in full here, so this adds no new class of exposure; mentioning it only in case you want to truncate (e.g. first 200 chars) before these objects reach a logger.
There was a problem hiding this comment.
Fair point — I checked before replying and this adds no new class of exposure: content is already interpolated in full one field earlier, and for a tool message the error text usually arrives inside that content today anyway. Truncating only error would make the two inconsistent, so I've left toString as it is; if truncation is wanted I'd apply it to both or put it in the logging configuration.
| assertEquals(ToolResultState.SUCCESS, result.getState()); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Good coverage for the inbound direction, and the codec round-trip test is the right regression guard for the silent-drop bug. Two cases that would pin the contract cheaply: (1) error on a non-tool role — today it is read only inside the isToolMessage() branch of addTextBlock, so a role:"assistant" message with error is silently a no-op, and (2) the outbound toAguiMessage direction (see the converter comment above). Either one documents the intended behaviour if you decide the current semantics are what you want.
There was a problem hiding this comment.
Both pinned. For (1) I added testErrorOnNonToolRoleIsIgnored, which asserts error on an assistant message stays a no-op and does not turn it into a failed tool result — the current semantics are now documented rather than accidental. If that is not the behaviour you want, that test is the place to change it.
For (2) the outbound direction is covered in 0bb67a2 by testConvertErrorToolResultToAguiMessageMirrorsError and testErrorToolResultRoundTripsThroughBothDirections, together with the mirroring above. I also kept a success-path guard (testConvertSuccessToolResultToAguiMessageKeepsTextInContent) so the mirroring does not leak into successful results.
`toAguiMessage` ignored `ToolResultBlock.getState()`, so an ERROR result left the converter as a tool message whose text merely started with `[ERROR] ` and whose `error` field was null. A client consuming the outbound direction could not tell a failed tool call from a successful one, and round-tripping only worked through the prefix check in `ReActAgent.determineToolResultState`. A result in `ToolResultState.ERROR` now sets `error` with the marker stripped, and its text is no longer also appended to `content`, so a round trip does not carry it in both places. Note this changes the outbound wire format: an ERROR result that previously left as `content: "[ERROR] <reason>"` now leaves as `error: "<reason>"` with no content. That is the intent, but it is visible to existing consumers. Co-Authored-By: Claude Code <[email protected]>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…ith toolCallId Two defects in the outbound mirroring added by the previous commit: - A failed tool result carrying several text blocks kept only the first one and dropped the rest silently, where they used to reach `content` in full. - `error` took the first failing result while `toolCallId` takes the last, so a message holding more than one result reported one call's failure under another call's id. Both now take the last, matching how `toolCallId` is set. Also documents that only ERROR is mirrored: DENIED and INTERRUPTED keep travelling as content, because the protocol carries a single error string and cannot express the richer states core distinguishes. An ERROR result with no text is pinned as a known limitation: it leaves as `error: ""`, and the inbound side reads a blank error as no error, so the state does not survive the round trip. Changing that means making the field mean "failed" on presence rather than on content, which is a protocol decision rather than part of this fix. Co-Authored-By: Claude Code <[email protected]>
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Maps a frontend tool's AG-UI error field onto a real ToolResultState.ERROR result (and mirrors ERROR results back out into error), instead of the field being dropped by the lenient codec. The design is well argued, the backward-compatible 5-arg constructor is kept, and the test suite is genuinely thorough — mixed success/error, blank error, multi-text output, round trips, non-tool roles, and a pinned known limitation for empty-text errors. CLA signed; builds green on ubuntu/windows at 8877990.
Findings
- [Warning] AguiMessageConverter.java:174 —
toolCallIdanderrorcan end up describing different tool results when a message mixes ERROR and SUCCESS blocks. - [Warning] AguiMessage.java:96 — the new field serialises as
"error": nullon every message; the class lacks the@JsonInclude(NON_NULL)used elsewhere in this module. - [Info] AguiMessageConverter.java:364 — inbound
erroris not prefix-stripped, so an echoed[ERROR]value double-prefixes. - [Info] AguiMessageConverter.java:91 — the
[ERROR]marker is duplicated from core; consider a shared constant.
None of these look like blockers for correctness of the primary path, but the null-serialisation one is a wire-format change worth resolving before merge.
Automated review by github-manager-bot
| // round trip does not carry it in both places. The protocol carries one | ||
| // `error` per message and `toolCallId` is likewise the last one seen, so | ||
| // the last failing result wins to keep the two describing the same call. | ||
| error = stripErrorPrefix(toolResultText(trb)); |
There was a problem hiding this comment.
In a message carrying several ToolResultBlocks the loop always overwrites toolCallId but only overwrites error on ERROR results, so an ERROR block followed by a SUCCESS block produces toolCallId of the successful call combined with the error of the failed one — the two fields can describe different calls. Consider tracking the id alongside the error (only assigning toolCallId when the error is set), or emitting one AguiMessage per tool result.
There was a problem hiding this comment.
Fixed in 663ed38. The id now travels with the error: an ERROR result sets both error and toolCallId, and a later successful result only claims the id when no error has been set. That covers the mixed case the same way the two-ERROR case was already covered.
testConvertMixedToolResultsKeepsErrorOnTheSameCallAsToolCallId pins it — reverting the pairing makes it fail with expected: <tc-1> but was: <tc-2>, which is the mismatch you described.
I did not take the second option you offered (one AguiMessage per tool result): that changes how a Msg is projected rather than how the mirroring pairs its fields, and it would affect every caller of the outbound direction, so it seemed better raised separately than folded in here.
| // A frontend tool that failed reports the reason in the AG-UI `error` field | ||
| // rather than in `content`. Report the failure instead of a success, so the | ||
| // model can retry, report it, or ask the user. | ||
| blocks.add(errorResultBlock(aguiMessage.getToolCallId(), error, text)); |
There was a problem hiding this comment.
The inbound error value is used verbatim while the outbound path strips the marker: a client that echoes back text already prefixed with [ERROR] yields [ERROR] [ERROR] ... in the produced ToolResultBlock. A stripErrorPrefix(error) here would keep both directions symmetric.
There was a problem hiding this comment.
Fixed in 663ed38: the incoming value now goes through the same stripErrorPrefix the outbound path uses, so an echoed marker no longer doubles. The helper's javadoc says it applies in both directions now.
testConvertToolMessageWithAlreadyPrefixedErrorDoesNotDoubleTheMarker pins it — reverting the strip produces [ERROR] [ERROR] sandbox unavailable, which is the case you described.
| * constant for it, so it is repeated here for the case where an error has to be combined with | ||
| * the payload the client sent alongside it. | ||
| */ | ||
| private static final String ERROR_TEXT_PREFIX = "[ERROR] "; |
There was a problem hiding this comment.
The [ERROR] marker is duplicated here because core exposes no constant. Worth promoting it to a public constant on ToolResultBlock (or a shared helper) so the two sides cannot drift; the same argument applies to the DENIED/INTERRUPTED states that are deliberately not mirrored.
| ? Collections.unmodifiableList(toolCalls) | ||
| : Collections.emptyList(); | ||
| this.toolCallId = toolCallId; | ||
| this.error = error; |
There was a problem hiding this comment.
AguiMessage has no @JsonInclude(NON_NULL) (unlike AguiEvent and the *InputContent models in this module), so the new field will serialise as "error": null on every message. Please annotate the class (or the getter) with @JsonInclude(JsonInclude.Include.NON_NULL) so successful messages keep their previous wire representation for strict AG-UI clients.
There was a problem hiding this comment.
Done in 663ed38 — on the getter rather than the class. Your suggestion caught something my earlier reply got wrong: I had argued a class-level annotation would change the wire format of toolCalls / toolCallId / content, so it belonged in a follow-up. Annotating getError() only affects the new property, so a successful message keeps the shape it had before the field existed and the existing fields are untouched.
testJsonSerializationOmitsErrorWhenAbsent pins both halves: no error key when there is none, and the value still round-trips when there is. It fails with "error":null in the output if the annotation comes off.
|
Pushed 8877990 with two defects I found re-reading the mirroring added in 0bb67a2, plus two boundaries worth stating rather than leaving implied. The defects — both reproduced by reverting to 0bb67a2 and watching the new tests fail:
Two boundaries:
518 tests pass, |
…l answer `ReturnDirectAguiProjectionTest` covered a successful returnDirect tool taking the short-circuit, but not a failed one. A result in `ToolResultState.ERROR` must not take it — `isReturnDirectToolCall` decides that, and its javadoc is explicit that ERROR results must never be presented as the final answer. Otherwise a failed frontend tool hands its error text back as the agent's answer and the closing model call never runs. Reproduced against the pre-fix shape first: with a `SUCCESS` result carrying the same text the turn short-circuits after one model call. With the shape `AguiMessageConverter` produces it takes two, and the failure stays out of the projected text. `ReturnDirectTool` now takes the result it returns, so both cases share one tool. Co-Authored-By: Claude Code <[email protected]>
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
The latest commit adds a regression test ensuring an explicit ToolResultState.ERROR result from a returnDirect frontend tool does not take the returnDirect short-circuit. commented (the new commit is clean, but the prior review's non-blocking warnings remain open)
What changed since the last review
d190512—ReturnDirectAguiProjectionTest: refactored theReturnDirectToolfixture to accept a configurableToolResultBlockand addedfailedToolResultIsNotProjectedAsTheFinalAnswer, which pins that an ERROR result forces the closing model call instead of projecting the error text as the final answer.- The source-level findings from the previous review (
mixed ERROR/SUCCESS tool results can pair the wrong id with errorandAguiMessageserialiseserror: null) are not addressed in this push and remain open.
Findings
None.
Verification
I read the PR-head versions of AguiMessageConverter, AguiMessage, and ReturnDirectAguiProjectionTest, and confirmed against ReActAgent.isReturnDirectToolCall that an explicit ERROR result is excluded from the returnDirect short-circuit. The new test covers the regression path; no new issues were found in the changed lines.
Automated review by github-manager-bot
…ing the marker Three source-level findings from review, all in the AG-UI converter's error handling: - `toolCallId` was assigned from every tool result while `error` only came from failing ones, so an ERROR result followed by a SUCCESS result reported the successful call's id alongside the failed call's reason. The id now travels with the error, and a successful result only claims an id when no error was set. - A client echoing back a value this converter already prefixed produced `[ERROR] [ERROR] ...`, because the marker is re-added inbound. The incoming value now goes through the same strip the outbound path uses. - `AguiMessage.getError()` is annotated `@JsonInclude(NON_NULL)` so a message that reports no error keeps the wire shape it had before the field existed. The annotation is on the getter, so the other fields are left as they are. Each is pinned by a test that fails when the corresponding change is reverted. Co-Authored-By: Claude Code <[email protected]>
The AG-UI ToolMessage schema lists `content` as required and types it as a string or a list of parts, so null is not a valid value. Moving a failed frontend tool's text out of `content` and into `error` left such a message with `content: null`, which a strict client or a schema validator rejects. A tool message now carries an empty string when the result has no ordinary output; other roles are unchanged. Also states two things the javadoc left implicit: that DENIED and INTERRUPTED results read back as SUCCESS, and that `error` is treated as an error only when non-blank. `testConvertMsgWithToolResultNoOutput` asserted the old null and is updated rather than deleted: what changed is the protocol requirement, not the test's intent. Co-Authored-By: Claude Code <[email protected]>
One open item I would rather flag than decide aloneA
An independent review pass over an earlier revision reproduced both and pinned the second in a probe, which is how I noticed the first is not consistent either. I had assumed pairing the id with the error was enough; it is not. Both readings are lossy, which points at a third option rather than either of these: one The outbound direction has no in-tree production caller ( |
Four tests for the branches the patch report listed as missed or partial. All of them are reachable from the converter's public surface; no production code changed. - A successful tool result carrying several text blocks: only the failing path had multi-block coverage, so the newline join in the success path never ran. - A non-text block in a tool result's output, in both states: the `instanceof TextBlock` false branch was never taken in either loop. - `error` reported with a text content whose value is null: only the empty-string case was covered. - Two `AguiMessage`s differing only in `toolCallId`, and only in `error`, so the two fields the error handling added to `equals` are actually exercised. Co-Authored-By: Claude Code <[email protected]>
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-review at 0018fb2f. Both warnings from the previous pass are resolved: the mirrored error now keeps its own toolCallId (AguiMessageConverter.java:178-186), and @JsonInclude(NON_NULL) on getError() puts a successful tool message back on its pre-error wire shape. Inbound prefix-stripping makes the two directions symmetric, and the new tests pin the multi-text-block join, the non-text-output case, a Text(null) payload with an error, and the known empty-error round-trip gap. CLA signed, build (ubuntu-latest) / build (windows-latest) / codecov/patch all green at this head.
Approving — the one finding below is a narrow multi-result edge case worth a decision or a pinning test, not a blocker.
Findings
- [Warning]
AguiMessageConverter.java:178— a TOOL message carrying twoERRORresults drops the earlier reason from botherrorandcontent; worth a test pinning the chosen behaviour. - [Info]
AguiMessageConverter.java:201—contenton a tool message now serialises as""instead ofnullfor all tool messages, not just failing ones; fine per protocol, but call it out for frontends that branch oncontent == null. - [Info]
AguiMessage.java:287—erroris now the only non-null-included property on the class; asymmetry is documented, acceptable. Suggested follow-up (not here): promote the[ERROR]marker to a coreToolResultBlockconstant so the runtime and this module stop mirroring the literal.
Verified
ToolResultBlock.error(String, String)emits exactly[ERROR]+ reason (agentscope-core/.../ToolResultBlock.java:242-249), soERROR_TEXT_PREFIXmirrors core today; the 5-arg constructor still delegates withnulland only the 6-arg form carries@JsonCreator, so both Java callers and pre-errorpayloads keep working.- Every tool-result inbound path funnels through
addTextBlock, including the null-content case (toMsgcalls it with""), so there is no path where a reportederroris silently converted into a success.
Automated review by github-manager-bot
| // and it takes `toolCallId` with it: a message may hold more than one result | ||
| // and the protocol carries one `error`, so the id has to stay with the error | ||
| // it describes. A later successful result must not claim that id. | ||
| error = stripErrorPrefix(toolResultText(trb)); |
There was a problem hiding this comment.
[Warning] When a TOOL message carries more than one ERROR result, every earlier error is overwritten here and never appended to content, so the earlier failure reason disappears from the wire entirely — the client sees only the last one, and there is no trace of the rest.
The single-error protocol does constrain the field, but the text of the dropped results could still survive in content the way non-error results do, e.g. keep the final error in error and fold earlier ones into content:
if (trb.getState() == ToolResultState.ERROR) {
String text = stripErrorPrefix(toolResultText(trb));
if (error != null) { // an earlier error is being displaced
if (content.length() > 0) {
content.append("\n");
}
content.append(ERROR_TEXT_PREFIX).append(error);
}
error = text;
toolCallId = trb.getId();
}Either way, it would be worth a test for two ERROR blocks in one message pinning whichever behaviour you choose — right now the loss is neither intended nor asserted, just a consequence of the loop. Low probability in practice (one result per tool message is the norm), so not a blocker for the primary path.
| // so a result with no ordinary output carries an empty string rather than omitting the | ||
| // field. Other roles keep the previous behaviour. | ||
| String contentText = content.toString(); | ||
| MessageContent wireContent = |
There was a problem hiding this comment.
[Info] This changes the outbound wire shape for every tool message, not only failing ones: a TOOL-role message with no text output used to serialise content: null and now serialises content: "". The javadoc justifies it from the protocol (content is required on tool messages), and testConvertToolResultIgnoresNonTextOutput / the empty-content test pin it — flagging only so this is called out in the PR description for consumers that branch on content == null (CopilotKit-style frontends in particular). If any known client does that, it belongs in the release note.
| * @return The error message, or null if no error was reported | ||
| */ | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public String getError() { |
There was a problem hiding this comment.
[Info] @JsonInclude(NON_NULL) on the getter resolves the previous null-serialisation finding — with error absent, a successful tool message keeps its pre-error wire shape. One residual: the field is now asymmetrically optional on the class (every other property serialises its null), so a reader inspecting AguiMessage cannot tell from the annotations alone why this one differs; the javadoc explains it, which is enough. Follow-up worth opening separately rather than here: promote the [ERROR] marker to a constant on core's ToolResultBlock so this module and the runtime stop mirroring the literal (ERROR_TEXT_PREFIX is the second copy).
| } | ||
|
|
||
| @Test | ||
| void testEmptyTextErrorResultDoesNotSurviveRoundTrip() { |
There was a problem hiding this comment.
[Info] testEmptyTextErrorResultDoesNotSurviveRoundTrip is the right way to handle a known protocol gap: pin it, name it, and say why (error: "" reads as "no error" inbound so a client cannot flip a success into a failure). Worth one line in the PR description too, so the maintainers see that an ERROR with no reason degrades to SUCCESS on the way back rather than discovering it from the test name.
A TOOL message carrying two ERROR results kept only the last one: the earlier reason was overwritten and never reached `content` either, so it left the wire without a trace. The last failing result still takes `error` and `toolCallId` — the protocol carries one of each, and the id has to stay with the error it describes — but the reason it displaces is now folded into `content`, marker included, so it survives the round trip and still reads back as an error. Pinned by two tests: the plain two-ERROR case, and a displaced reason joining content that an earlier result already contributed. Co-Authored-By: Claude Code <[email protected]>
|
Nothing in this PR can reach that module: The same test class has now failed twice on this PR with different symptoms — the first was I have not established the cause. Could the job be re-run? I cannot trigger it from a fork. |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
This PR binds an error field on AguiMessage and converts a client-reported tool error into a ToolResultState.ERROR tool result, mirroring ERROR results back outbound with the head commit folding displaced multi-ERROR reasons into the content. Re-verified at head 548ba65 by a scratch rebuild (528 module tests pass, spotless clean) and probes confirming the model receives [ERROR] sandbox unavailable with no duplicate tool-call emission, and that backward compatibility holds (5-arg constructor retained, error omitted when null, prior content-only [ERROR] ... failures still realign via core's prefix fallback). The previous review's warnings are resolved; the one substantive residual issue is that outbound ERROR mirroring is not role-gated, so an assistant/server-tool ERROR result loses its text into error/null content — worth fixing or explicitly bounding before merge. The remaining notes (content-only SUCCESS-state edge and missing end-to-end converter test) are minor and non-blocking.
Re-reviewed at head 548ba65387 (the previous approval was on an older commit). Inline anchoring was rejected by GitHub for this diff, so findings are listed here.
Findings
- [WARNING]
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui/src/main/java/io/agentscope/core/agui/converter/AguiMessageConverter.java:172— [Warning] The mirroring is applied regardless of the message role, so a non-TOOL message that carries an ERRORToolResultBlocknow loses its text and gains anerrorfield the protocol defines only on tool messages.
An ERROR result does not only come from the inbound path. Provider server tools put ERROR-state results inside the assistant response content: AnthropicServerToolHelper.decodeResult builds "[ERROR] <tool> failed: <code>" with state = ERROR (model-anthropic, AnthropicServerToolHelper.java:246-259), and GeminiResponseParser.codeExecutionResultState maps OUTCOME_FAILED the same way. For such a message this branch consumes the text into error and never appends it to content, while wireContent stays null for non-TOOL roles (lines 208-211). Verified against the head revision with a probe: an assistant Msg holding that block projects as
{"role":"assistant","content":null,"toolCallId":"srv-1","error":"web_search failed: too_many_requests", ...}instead of the previous "content":"[ERROR] web_search failed: too_many_requests". Three consequences, all silent: a client that reads only content no longer sees the failure at all; error (unlike toolCallId, which was already emitted) is off-protocol on an assistant message, and the javadoc on AguiMessage.getError() says "Only tool messages carry it"; and re-feeding that message produces an empty Msg (toMsg yields no content blocks, confirmed by the same probe), so the information is gone rather than relocated. toAguiMessage/toAguiMessageList are public API with no in-tree production caller today, which limits the blast radius to library consumers. Gating the mirroring on msg.getRole() == MsgRole.TOOL and keeping the previous content behaviour for other roles would close it without affecting the tool path this PR targets.
- [INFO]
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui/src/main/java/io/agentscope/core/agui/converter/AguiMessageConverter.java:402— [Info] A frontend tool whose failure is reported only as[ERROR] ...text incontent(noerrorfield) is still classified as a success, so the class of misclassification this PR fixes survives for that client shape.
This builder sets ToolResultState.SUCCESS explicitly, and ReActAgent.determineToolResultState returns at its explicit-state branch (agentscope-core/.../ReActAgent.java:3505-3508) before it ever reaches the [ERROR] prefix fallback (3512-3517). The state therefore propagates as SUCCESS through the runtime, including the returnDirect decision isReturnDirectToolCall (3786-3793): a returnDirect tool whose result arrives from the caller with "[ERROR] ..." in the text takes the caller-supplied short-circuit at 1907/1913 and its [ERROR] ... text is published as the agent's final answer via finalizeReturnDirect — the same failure mode failedToolResultIsNotProjectedAsTheFinalAnswer pins for the error-field path. If core's marker convention is meant to be honoured here, either check the prefix in this method or leave the state unset so core's fallback decides. Not a blocker: the protocol's field for this is error, and reading arbitrary content as an error reason carries false-positive risk, so this may be a deliberate boundary worth one line of javadoc either way.
- [INFO]
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui/src/test/java/io/agentscope/core/agui/adapter/ReturnDirectAguiProjectionTest.java:199— [Info] The new adapter-level regression test exercises a backend tool that returnsToolResultBlock.error(...), but nothing covers the path issue #3307 actually reports end to end: a client sending{role:"tool", toolCallId:"tc-1", error:"..."}and the model seeing the failure. The converter tests stop at theMsgboundary, so a future regression between the converter and the runtime (id pairing, pending-result validation, event conversion, returnDirect handling) would not be caught by this PR's suite.
A test in this file is a natural home for it and is cheap: build the same RunAgentInput with AguiMessage.userMessage(...), an assistant message carrying an AguiToolCall for tc-1, and a tool message with error = "sandbox unavailable", then assert on the model's received messages that the ToolResultBlock has state ERROR and text "[ERROR] sandbox unavailable" (a capturing ChatModelBase variant of the existing ScriptedModel works, since the scripted model already sees List<Msg>). I ran exactly that against the head revision and it passes, so it is a regression guard rather than a bug report. It also pins the negative: no ToolCallStart events are re-emitted for a tool call the client already resolved.
Automated review by github-manager-bot
Provider server tools report their failures as an ERROR result inside the assistant response — `AnthropicServerToolHelper.decodeResult` and `GeminiResponseParser.codeExecutionResultState` both build one, and `ReasoningContext` places them in an `AssistantMessage`. The outbound mirroring applied to every role, so for such a message it moved the text into `error` and left `content` null: the reason left the wire under a field the protocol defines only on tool messages, which the class's own javadoc already said. The mirroring is now gated on the role, and other roles keep the text in the content as before. Also reads core's `[ERROR]` marker when a tool message reports a failure purely as content text. The state was asserted SUCCESS here, which pre-empts `ReActAgent.determineToolResultState` — it consults the marker only for a result whose state is unasserted — so such a client was recorded as a success, and a returnDirect tool in that state took the short-circuit and had its text published as the final answer. The converter keeps asserting SUCCESS otherwise. The predicate is core's own, the marker without a separator, so `[ERROR]boom` is caught as well. Adds the end-to-end test the issue actually describes — a client resolving a tool call through the `error` field, asserted on the messages the model is called with — which the converter tests could not cover, since they stop at the Msg boundary. Each change is pinned by a test that fails when it is reverted; coverage on the changed lines stays complete. Co-Authored-By: Claude Code <[email protected]>
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-review approves the new commits. They resolve the prior outbound-error, tool-call pairing, prefix handling, role-gating, schema-content, and end-to-end coverage concerns without introducing a new correctness, compatibility, performance, or test issue.
Findings
- None
Next step
Merge when the required checks are green.
Automated review by github-manager-bot
|
Following up on the The evidence: this PR touches five files, all in What I have still not established is the root cause, and I am not claiming one. The earlier note that All five checks are green on |
Brings main (incl. agentscope-ai#2697, agentscope-ai#3324, agentscope-ai#2751, agentscope-ai#3129) into the branch. Only conflict: ReActAgentStructuredOutputTest.java — this branch's added test (testToolBasedExtractionPreservesMessageIdentity) sat exactly where agentscope-ai#2697 later appended its new tests; kept both sides (our test plus the incoming suite) and both import sets. ReActAgent.java auto-merged. Verified: ReActAgentStructuredOutputTest 16 tests green including both this branch's identity test and the merged-in tests.
) Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs. (cherry picked from commit da3b867) Backport-review-patch: f235d005d9a357bbda42d6afd3eec7e344eee0ab Constraint: No AgentScope Service or SDK migration Confidence: high Not-tested: Whole-repository verification pending after lane integration
Description
Fixes #3307.
Inbound
AguiMessagenow binds the AG-UI tool messageerrorfield.erroris mapped toToolResultState.ERROR.contentis also present, it is preserved alongside the error.errorstill maps toSUCCESS.Outbound
toAguiMessage()mirrorsToolResultState.ERRORinto the AG-UIerrorfield.[ERROR]text marker; it relies on the explicit state and the protocol’serrorfield.Multiple tool results
AguiMessageConverternow exposestoAguiMessages(Msg).toAguiMessageList()expands a TOOLMsgcontaining multipleToolResultBlocks into one AG-UI tool message per result.toolCallId,content, anderror.toAguiMessage()remains for messages with at most one tool result and throws if asked to convert multiple results, so the old lossy projection is no longer silent.Compatibility
AguiMessageconstructor is preserved.erroris omitted when null.content, using an empty string when there is no ordinary output.Docs and tests
errortoAguiMessage()rejection for multi-result messages