codex - 💡(How to fix) Fix Feature: PostToolUseFailure hook (failure-branch sibling of PostToolUse)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  • handler error — tool identity recomputed from the pre-tool-use payload, tool_response: null;

Fix Action

Fix / Workaround

  • Matcher-bearing (matches on tool name) and turn-scoped — identical dispatch semantics to PostToolUse.
  • Input mirrors the PostToolUse contract plus an error_message field describing why the invocation failed.
  • Two failure sources are covered:
    • handler error — tool identity recomputed from the pre-tool-use payload, tool_response: null;
    • unsuccessful result — identity and the partial response taken from the post-tool-use payload.
  • Fail-open: a failing hook subprocess never changes the underlying tool outcome.

Per the contributing guidelines, I'm raising this as an issue first rather than an unsolicited PR. I have a complete, tested reference implementation against current main (enum variant, schema input/output wires + generated fixtures, dispatcher/runtime/registry wiring, unit tests; cargo fmt and clippy clean) and would be glad to submit a PR if the team feels this aligns with the roadmap and would like to invite one. Happy to iterate on the design (e.g. trimming the output contract to informational-only) based on your preferences.

RAW_BUFFERClick to expand / collapse

Problem

The PostToolUse hook fires only after a tool produces a successful output — run_post_tool_use_hooks is gated on success in core/src/tools/registry.rs. There is currently no hook surface for the failure branch: when a tool invocation errors, exits non-zero, times out, or returns an unsuccessful result. Hook authors who want to react to tool failures (diagnostics, automated retry guidance, failure telemetry, post-mortem capture) have no event to attach to.

Proposed design

Add a PostToolUseFailure hook event — the failure-branch sibling of PostToolUse:

  • Matcher-bearing (matches on tool name) and turn-scoped — identical dispatch semantics to PostToolUse.
  • Input mirrors the PostToolUse contract plus an error_message field describing why the invocation failed.
  • Two failure sources are covered:
    • handler error — tool identity recomputed from the pre-tool-use payload, tool_response: null;
    • unsuccessful result — identity and the partial response taken from the post-tool-use payload.
  • Fail-open: a failing hook subprocess never changes the underlying tool outcome.

This follows the established hook-event pattern (e.g. the recent SubagentStart / SubagentStop additions), so it is additive and low-risk to the rest of the hook system.

Why this is generic

Reacting to tool failures is a need independent of any particular integration — observability, retry/recovery UX, and failure analytics all want a hook here, and PostToolUse deliberately excludes the failure case. It rounds out the tool-lifecycle hook surface (PreToolUsePostToolUsePostToolUseFailure).

Offer

Per the contributing guidelines, I'm raising this as an issue first rather than an unsolicited PR. I have a complete, tested reference implementation against current main (enum variant, schema input/output wires + generated fixtures, dispatcher/runtime/registry wiring, unit tests; cargo fmt and clippy clean) and would be glad to submit a PR if the team feels this aligns with the roadmap and would like to invite one. Happy to iterate on the design (e.g. trimming the output contract to informational-only) based on your preferences.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING