feat(plugin): add tool.execute.error hook for failed tool calls#32542
Draft
haabe wants to merge 1 commit into
Draft
feat(plugin): add tool.execute.error hook for failed tool calls#32542haabe wants to merge 1 commit into
haabe wants to merge 1 commit into
Conversation
`tool.execute.after` only fires on success — when a tool's execute Effect fails, the error is routed to the message stream and no `after`-side plugin hook fires. Plugins doing admission control (reflexion/retry, fallback routing, circuit-breaking, policy gates) had no failure signal short of reconciling callIDs from `tool.execute.before` against the message stream. Add `tool.execute.error`, fired on failure of the built-in and MCP tool paths before the error propagates. The `callID` correlates deterministically with the matching `tool.execute.before`. The payload carries `error`, `retryable`, and `authority` (`tool` | `runtime` | `plugin`) so frameworks can make cross-runtime decisions without parsing error text. Interruptions (user aborts) are excluded — those are handled by the abort path. Additive and non-breaking: `after` still fires only on success. Closes anomalyco#27900 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
1 task
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.
Issue for this PR
Closes #27900
Type of change
What does this PR do?
tool.execute.afteronly fires on success. When a tool's execute fails,Tool.executeconverts the error to a defect viaEffect.orDie, so theaftertrigger site is never reached and the error just goes to the message stream. Plugins that need to react to failures (retry, fallback, circuit-breaking) have no hook to listen on.This adds
tool.execute.error, fired on failure in both the built-in and MCP tool paths insession/tools.ts, before the error propagates. Because failures are defects, I catch at the cause level withEffect.tapCause(nottapError) and skip interruptions withCause.hasInterruptsOnly, since user aborts are handled by the abort path. ThecallIDmatches thetool.execute.beforefor the same call, so plugins don't have to reconcile callIDs against the message stream.Payload is
{ error, retryable, authority }. Authority isruntimefor permission/question rejections,toolfor invalid-args and other tool errors, andpluginwhen a before/after hook throws. I used a separate event rather than adding astatusfield toafterso existingafter ⇒ successassumptions don't silently break.Happy to drop
retryable/authorityto just{ error }if you'd prefer a smaller surface — that's the part I'm least sure about.How did you verify your code works?
bun run typecheckpasses. Addedtest/session/tool-execute-error.test.ts, which drives the realSessionTools.resolvewith a recording plugin and asserts: success fires before+after (not error); failure fires before+error (not after) with the matching callID; a before-veto and an after-crash both reportauthority: plugin; both the built-in and MCP paths; plus a unit matrix for the classifier. The existingplugin/triggertest still passes.Checklist