Skip to content

fix: add ToolErrorMiddleware#76

Merged
barredterra merged 2 commits into
version-16from
tool-error-middleware
Jul 20, 2026
Merged

fix: add ToolErrorMiddleware#76
barredterra merged 2 commits into
version-16from
tool-error-middleware

Conversation

@barredterra

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — additive middleware wiring with a well-tested sanitisation callback, and the api.py hardening removes an information-leakage path.

All three agent entry points now wrap exceptions before they reach the model or the user. Sanitisation logic correctly separates intentional Frappe messages (exposed) from unexpected exceptions (type-name only), and the test suite explicitly exercises the secret-scrubbing path.

No files require special attention.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant User
    participant api as api.py
    participant Runner as AgentRunner
    participant Agent as Coordinator
    participant MW as ToolErrorMiddleware
    participant Tool as Frappe Tool

    User->>api: HTTP request
    api->>Runner: run_message(...)
    Runner->>Agent: invoke
    Agent->>MW: wrap_tool_call
    MW->>Tool: handler(request)
    alt ValidationError or PermissionError
        Tool-->>MW: raises exc
        MW-->>Agent: "ToolMessage(status=error, detail)"
    else Unexpected Exception
        Tool-->>MW: raises exc
        MW-->>Agent: "ToolMessage(status=error, type-name only)"
    else Unhandled escape
        Agent-->>api: raises
        api->>api: log_error
        api-->>User: generic message
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant User
    participant api as api.py
    participant Runner as AgentRunner
    participant Agent as Coordinator
    participant MW as ToolErrorMiddleware
    participant Tool as Frappe Tool

    User->>api: HTTP request
    api->>Runner: run_message(...)
    Runner->>Agent: invoke
    Agent->>MW: wrap_tool_call
    MW->>Tool: handler(request)
    alt ValidationError or PermissionError
        Tool-->>MW: raises exc
        MW-->>Agent: "ToolMessage(status=error, detail)"
    else Unexpected Exception
        Tool-->>MW: raises exc
        MW-->>Agent: "ToolMessage(status=error, type-name only)"
    else Unhandled escape
        Agent-->>api: raises
        api->>api: log_error
        api-->>User: generic message
    end
Loading

Reviews (2): Last reviewed commit: "fix: translate error messages" | Re-trigger Greptile

Comment thread ask_alyf/ask_alyf/test_tool_error_middleware.py
@barredterra

Copy link
Copy Markdown
Member Author

@Mergifyio backport version-15 develop

@mergify

mergify Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

backport version-15 develop

✅ Backports have been created

Details

@barredterra
barredterra merged commit 0711bbd into version-16 Jul 20, 2026
5 checks passed
@barredterra
barredterra deleted the tool-error-middleware branch July 20, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant