Return 429 and 503 for semantic search backend failures

Description

EE::API::Search::SemanticCodeSearch (the semantic_code_search MCP tool, also reachable directly via GET /projects/:id/search/semantic) only rescued Ai::ActiveContext::Queries::Code::NotAvailable. Every other downstream failure fell through to Grape's generic error handler and returned a bare 500 Internal Server Error, even though the endpoint's own docs already promised a 429 response.

Production Sentry data showed two recurring failure modes hitting this gap, reached both through the MCP tool and the direct REST route:

  • AI Gateway rate-limit exhaustion (Gitlab::Llm::Concerns::ExponentialBackoff::RateLimitError)
  • Elasticsearch/network timeouts (Elastic::TimeoutError, Faraday::TimeoutError, Net::ReadTimeout)

This adds rescue_from handlers for both, returning 429 Too Many Requests (with Retry-After) and 503 Service Unavailable respectively, so callers get a standard retriable signal instead of an opaque failure.

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/627763

Edited by Arturo Herrero

Merge request reports

Loading
Loading