Add distinct ToolError variant for user-declined approvals

Open 💬 0 comments Opened Jul 18, 2026 by trac3r00

[Bob] Problem

When a user declines a tool-call approval, the error propagated back to the model is a generic ToolError without a distinct variant for user-declined actions. This makes it impossible for the model (or any downstream consumer) to differentiate between:

  • User explicitly declined the tool call
  • Tool execution failed due to a runtime error
  • Tool call was malformed

The existing TODO at codex-rs/core/src/tools/events.rs:414 confirms this gap:

// TODO: We should add a new ToolError variant for user-declined approvals.

Impact

  • The model cannot adjust its behavior when a user declines (e.g. stop retrying the same tool, propose an alternative approach)
  • Logging/observability cannot distinguish approval-declined from actual failures
  • Downstream consumers (CLI, TUI, desktop app) cannot show appropriate UX for declined vs failed

Proposed solution

Add a UserDeclined (or ApprovalDenied) variant to ToolError enum with:

  • The original tool call info (name, arguments summary)
  • Optional user-provided reason if the platform supports it

This is a targeted change to the error type + the approval flow in events.rs, with no impact on the tool execution hot path.

Happy to submit a PR if the team agrees on the variant name.

View original on GitHub ↗