Repository navigation
fix: keep MCP tool error flag in interceptors and session memory - #2041
Conversation
|
🤖 review, judge if the suggestions are valid
|
|
🤖 says... No end-to-end test of an MCP error resulthigh · No test sends an MCP server error through the runtime, an interceptor and session memory. Nothing checks that the runtime takes the Incompatible MCP hooks adapter in PR #1995high · PR #1995 adds its own Once this PR is on main, #1995 does not compile. The two PRs also carry two adapters and two specs for the same code. A SessionMemoryInterceptor that rewrites a tool response drops the error flaghigh ·
On the next turn the model sees error text as normal tool data, which is the bug this PR fixes. The MCP Exact-match whenToolResult no longer matches error resultsmedium ·
User tests fail with toolName() javadoc does not state the new contractmedium ·
An interceptor that matched on the suffixed name stops matching without an error, and the contract does not tell the user. SessionMemoryInterceptor javadoc gives conflicting guidancemedium · The paragraph says to use the constructors without A reader who follows the first instruction drops the error flag. The sentence also uses "so that", which the project comment rules ban. isError javadoc omits failed tool callsmedium ·
The runtime also sets the flag when the tool call fails, for example when a Positional boolean constructors make sanitized and isError easy to swapmedium ·
An error result then gets Request-based Agent storage of the flag is untestedmedium · No test reaches Changing this line to Throwing interceptResponse is untestedmedium · The failure case throws only from The docs say an interceptor can deny a response by throwing, and the response path is new Event casts in SessionMemoryEntityTest repeat the history checklow · The test casts A change in event order breaks the test without a change in behaviour. Success path never asserts a non-error tool resultlow · The success-path matcher checks only A regression that marks every tool result as an error would pass. Passive voice in ToolResult @PARAM isErrorlow · "was sent to the model as an error result" names no actor. The project writing rules ask for active voice with a named actor. Guardrails and the compaction sample do not see the flaglow ·
A guardrail cannot tell an error result from a normal one, and a compaction summary loses the flag. Both are outside the diff. isError() is a constant false in the request phaselow · In A helper shared by both hooks cannot tell the two cases apart. The abstract method also breaks hand-written test doubles of the context, which users need to unit-test interceptors since there is no factory. interceptResponse javadoc repeats itself and leaves the contract openlow · The last two sentences say the same thing. The text does not say whether an interceptor can set the flag, or that a failed call such as a timeout never reaches A reader cannot tell from the javadoc which results reach the interceptor and what it may change. "so that" in SessionMemory javadoclow · The sentence uses "so that" and says "sends an error result to the model as an error result". The project comment rules ban "so that", and the sentence repeats itself. Unclear wording in the event javadoclow · "A stored event without one of these components reads it as false" has no actor and an unclear "it". "of the tool response" differs from "of the The project writing rules ask for a named actor and one term per concept. Tool response to event mapping is written twicelow ·
This PR had to add Hooks comment describes runtime behaviour in hard-to-parse wordinglow · "and with the tool name on the MCP server" is hard to parse. The comment is accurate. The comment describes what the runtime does. The project rules allow maintainer notes in toSpiMcpToolCallHooks is wider than neededlow · It is The wider visibility invites other callers in the package for no reason. No SDK null check on interceptor return valueslow · A null from The SDK relies on the runtime to reject null, and the runtime error does not name the user's interceptor. Identity check in interceptResponse and the test that pins itlow ·
The branch adds code for no behaviour, and the test pins an implementation detail. A change that builds a new, equal result fails the test. Test comments describe historylow · The comments here and at line 104 say "stored before the error flag existed". The project rules ban development history in comments. Missing-field tests cover only the text variantslow · No test reads a Each multimodal record now has three constructors, so a regression in old-data reading for those types would pass. New error-flag test duplicates the history helperlow · The test rebuilds The two setups can drift apart. Await in the new speclow · The spec uses Other specs in the module use Third copy of the same test fixtureslow · The new test adds a third identical Three copies of the same fixture must change together. New docs sentence sits before an unrelated snippetlow · The sentence about A reader looks for |
19c6565 to
c499049
Compare
|
Feedback mostly applied, some not: Not applied
Resolved in another way
|
|
When you rebase this, pay attention to some possible silent conflicts, see #1995 (comment) |
c499049 to
6ba0cd1
Compare
…onse Interceptors that use the constructors without isError no longer turn error results into normal results.
Code compiled against M1 can still call the constructors with a sanitized parameter.
Guardrail.Message.ToolCallResponse gets isError from the runtime.
6ba0cd1 to
b8b7dd6
Compare
MCP tool interceptors can now see whether a tool result is an error through
ToolInterceptorContext.isError(). Session memory stores the flag with tool call responses, so history replay keeps it, and the testkitToolResultexposes it. Follows lightbend/akka-runtime#5853.The interceptor now uses the runtime's
McpToolCallHooks. As a result,ToolInterceptorContext.toolName()is always the tool name on the MCP server, and the runtime records the tool call intent with the arguments thatinterceptRequestreturns.