fix: Circuit-breaker for Code Suggestions (Web IDE)
When receiving sequential error responses from the code suggestions API, lower the frequency of API requests while user types. After 4 sequential error responses, the code completions provider will only send a fetch completions HTTP request every 10 seconds. Every subsequent HTTP request will double the waiting time before another request is fired.
How does it work?
A CircuitBreaker
class tracks the number of HTTP request failures. When it counts 4 subsequent requests, it marks itself as "breaking" and it unmarks itself after X ms. GitLabCodeCompletionProvider
uses this state to decide if it should continue sending API requests or not.
How to test in your local environment
- Follow these instructions to test code suggestions in your local environment: https://gitlab.com/gitlab-org/gitlab-web-ide/-/blob/main/docs/dev/code-suggestions.md#ai-assisted-code-suggestions
- Change the following line in the
code-suggestions-proxy
project to return a500
error https://gitlab.com/a_akgun/code-suggestions-proxy/-/blob/main/server.js#L32. - In the Web IDE, start typing to get code suggestions. You should see that, with every error response, the fetch completions requests should happen less often.
Related gitlab#412326 (closed)
Edited by Enrique Alcántara