← Back to Pull requests

feat(core): define a stable agent-facing error contract #498

Open
unknown opened this pull request with 467 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 01, 2026 01:12 UTC
Author

Description

Eight failure paths returned a plain dict instead of the shared ToolError shape, so a client reading the structured body could not rely on success being present, and in two cases error_code was missing too. All eight now return ToolError(...).model_dump().

| Path | Location | Code |
|------|----------|------|
| Rate limiter rejected the call | _audit_wrap, core/server.py | RATE_LIMITED |
| Breaker open for the tool | _audit_wrap, core/server.py | CIRCUIT_OPEN |
| Tool name not registered | execute_tool, core/dynamic_tools.py | TOOL_NOT_FOUND |
| Arguments do not bind to the signature | execute_tool, core/dynamic_tools.py | VALIDATION_ERROR |
| Breaker open inside execute_tool | execute_tool, core/dynamic_tools.py | CIRCUIT_OPEN |
| Wrapped tool raised | execute_tool, core/dynamic_tools.py | SDK_ERROR |
| Too many names for describe_tools | core/dynamic_tools.py | VALIDATION_ERROR |
| Query over MAX_QUERY_LENGTH | find_tools, core/dynamic_tools.py | VALIDATION_ERROR |

The first six are the ones @abhishekKokadwar measured on main. The last two have the same defect, so they are included here.

Also:

  • ErrorCode.TOOL_NOT_FOUND, since RESOURCE_NOT_FOUND means a missing Kubernetes resource and should not be overloaded.

  • RETRIABLE_ERROR_CODES, CALLER_ERROR_CODES and is_retriable_error(), so the retry vs correct input vs ask permission decision is machine-readable rather than inferred from the code name.

  • ToolError.tool, optional, set when a wrapper reports the failure. Keeps the existing tool key on the execute_tool paths.

  • The execute_tool exception path logs WARNING with exc_info and carries structured context in details via exception_details(). Tracebacks stay DEBUG-only.

  • docs/design/error-contract.md documents the shape and the code table. CONVENTIONS.md points at it.
  • One choice worth a reviewer's eye: the retriable set is not is_infrastructure_error(). RATE_LIMITED and CIRCUIT_OPEN are worth retrying from the client side but must not count as breaker failures, or the breaker feeds on its own output.

    Additive for current clients: no success-path shape changed, no code renamed or removed.

    Related Issue

    Fixes #309

    #338 rewrites the breaker lines in execute_tool, which two of these changes touch. Happy to rebase onto it whenever it lands.

    Checklist

  • I have read the [CONTRIBUTING](../CONTRIBUTING.md) guide

  • Tests pass locally (make test-python)

  • Linting passes (make verify)

  • Documentation updated (if applicable)

  • My commits are signed off (git commit -s)
  • Testing

  • Unit tests

  • Integration tests

  • E2E tests

  • Manually tested (describe below)
  • kubeflow_mcp/core/error_contract_test.py adds one test per path, each asserting success is False, a documented code, a non-empty safe message, and no traceback in the response. A final test asserts a successful call is untouched.

    Full suite: 1178 passed, 8 skipped. ruff check and ruff format --check clean.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Errors now include consistent success status and stable error codes, making failures easier to identify and handle.
    Responses provide clearer recovery hints for unavailable tools and invalid arguments.
    Error responses identify the affected tool and indicate which failures may be retried.
    Documentation
    Added guidance on error response formats, retry behavior, and handling different types of errors.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 467 lines (+350 / -117) across 5 files Reviewer: abhijeet-dhumal Review duration: 31351m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.46) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 467 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.368
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #498"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26% · Safe to merge
    26%