fix(ai): respect failureMode when tool-call parameter decoding fails#6432
Open
tsushanth wants to merge 1 commit into
Open
fix(ai): respect failureMode when tool-call parameter decoding fails#6432tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
Tool-call parameter decode errors were thrown before the handler queue existed, bypassing the failureMode gate entirely. Both the streaming and generateText paths now use a relaxed schema (Schema.Unknown) for the initial LLM-output decode pass, deferring strict validation into Toolkit.handle where failureMode is available. When decoding fails inside handle, failureMode:"return" now emits a tool-result part with isFailure:true and the encoded AiError instead of propagating the error as an effect failure. failureMode:"error" (and the default) continues to fail the effect as before. Updated two tests that were asserting the old broken behavior. Fixes Effect-TS#6335
|
IMax153
self-requested a review
July 16, 2026 21:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #6335
When a language model returns tool-call parameters that fail schema validation, the decode error was thrown before the handler queue was set up, bypassing the
failureModegate entirely. This meantfailureMode: "return"had no effect for parameter errors — the effect always propagated the failure.Root cause
Two decode sites were responsible:
LanguageModel.ts— TheResponse.StreamPart/Response.Partdecoders were applied to the raw LLM output before routing toToolkit.handle. A parameter schema mismatch here caused an immediate effect failure, skippinghandlecompletely.Toolkit.ts— Insidehandle,decodeParametersfailed with an uncaught error before the queue existed, so thefailureModecheck inStream.catchwas never reached.Fix
Site 1: Pass
{ relaxParams: true }toResponse.StreamPart/Response.Partfor the tool-resolution decode pass. This substitutesSchema.Unknownfortool.parametersSchema, allowing raw params through tohandleregardless of shape.Site 2: Wrap
decodeParametersinEffect.matchEffect. On failure, checktool.failureMode:"error"→ propagate viaEffect.fail(existing behavior)"return"→ encode theAiErrorviaschemas.encodeResultand emit it as a tool-result stream with{ result, encodedResult, isFailure: true, preliminary: false }Tests updated
Two existing tests asserted the old broken behavior (expecting
Effect.flipto yield anAiErrorfor parameter errors onfailureMode: "return"tools). Updated them to assert the correct behavior: the effect succeeds andresponse.toolResultscontains a part withisFailure: trueand the encoded validation error.