Skip to content

fix(api): Differentiate between setup and processing errors #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

RasheedAli-Shaik
Copy link

@RasheedAli-Shaik RasheedAli-Shaik commented Aug 6, 2025

Improved error handling in the /api/input_task endpoint by distinguishing between failures during service initialization and errors that occur during task processing.

Previously, any exception was caught and returned as a 400 Bad Request. This was misleading, as a failure to initialize the kernel or agents is a server-side issue (5xx), not a client-side one (4xx).

The logic is now wrapped in separate try...except blocks. Failures during the setup phase will correctly return a 500 Internal Server Error, providing a more accurate and actionable error response for both the client and for system monitoring.

Purpose

  • Solves Bug: Fixes a bug where server-side initialization failures in the /api/input_task endpoint were incorrectly reported to the client as a 400 Bad Request.
  • Improves Correctness: Aligns the API with HTTP standards by returning a 500 Internal Server Error for server-side exceptions, providing clearer and more accurate error feedback.
  • Enhances Debugging: Makes the system easier to debug for both client-side developers and operators by clearly distinguishing between a faulty client request (4xx) and a server failure (5xx).
  • Increases Robustness: Adds a finally block to ensure external client connections are closed, preventing potential resource leaks during an error state.

Does this introduce a breaking change?

  • Yes
  • No

Note: This is marked as a breaking change because the HTTP status code for a specific failure scenario (service initialization failure) has changed from 400 to 500. This is a corrective change that improves the API's contract, but clients may need to adjust if they were improperly handling this server-side error as a client-side one.

PR Title Recommendation: fix!: api: Differentiate between setup and processing errors

How to Test

*  Get the code

git clone https://github.com/microsoft/Multi-Agent-Custom-Automation-Engine-Solution-Accelerator.git
cd Multi-Agent-Custom-Automation-Engine-Solution-Accelerator
git checkout <branch-name>
  • Set up the backend environment as per the project's documentation (e.g., pip install -r requirements.txt).

  • Test the code

    1. Test the success case:

      • Run the backend server with valid environment variable configurations.
      • Send a valid POST request to the /api/input_task endpoint.
      • Expected: Receive a 200 OK response with the plan details.
    2. Test the server-error case:

      • Stop the server.
      • Temporarily invalidate a required environment variable for service initialization (e.g., set AZURE_SEARCH_ENDPOINT to an invalid URL).
      • Restart the server.
      • Send the same valid POST request to /api/input_task.
      • Expected: Receive an HTTP 500 Internal Server Error with the detail: "Could not initialize services for your request.". This confirms the fix.

What to Check

Verify that the following are valid

  • A standard, successful request to /api/input_task functions correctly and returns a 200 status.
  • When a service initialization fails due to a bad configuration, the endpoint correctly returns a 500 status code, not 400.
  • The error message for the 500 error is clear and does not expose internal implementation details.
  • Errors that occur later in the process (e.g., a malformed plan or a rate-limiting error) still result in the appropriate 4xx status code.

Other Information

This change is a foundational fix for API stability and correctness. It ensures the service behaves predictably and follows established web standards for error reporting.

Improved error handling in the `/api/input_task` endpoint
by distinguishing between failures during service initialization and
errors that occur during task processing.

Previously, any exception was caught and returned as a 400 Bad Request.
This was misleading, as a failure to initialize the kernel or agents
is a server-side issue (5xx), not a client-side one (4xx).

The logic is now wrapped in separate `try...except` blocks. Failures
during the setup phase will correctly return a 500 Internal Server
Error, providing a more accurate and actionable error response for
both the client and for system monitoring.
@RasheedAli-Shaik
Copy link
Author

@RasheedAli-Shaik please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement
@microsoft-github-policy-service agree

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