Basic checks
What's broken?
Hey, folks,
I think I've discovered a bug, unless, of course, I'm not missing something. I think RubyLLM won't retry POST requets, because it doesn't set the methods option on faraday-retry and also doesn't provide a way to set it.
- The faraday-retry middleware accepts a methods option and falls back to
%i[delete get head options put], if no methods are given.
- RubyLLM doesn't set the
methods option, hence only idempotent methods are retried, post requests are never retried.
I'm hitting this on Anthropic's POST v1/messages endpoint. Tagging @tpaulshippy here as well, as I know he uses Anthropic heavily as well.
How to reproduce
-
RubyLLM has a default config for automatic retries, so need for additional configuration regarding retries. Set Anthropic as provider or make sure that the ask method will issue a POST request.
-
Stub an error response and see, that requests are not retried. Something like:
context "when Anthropic API returns an error" do
before do
# Stub the Anthropic Messages API endpoint with proper error format
stub_request(:post, "https://api.anthropic.com/v1/messages")
.to_return(
status: 500,
body: {
type: "error",
error: {
type: "api_error",
message: "An unexpected error has occurred internal to Anthropic's systems."
},
request_id: "req_018EeWyXxfu5pfWkrYcMdjWG"
}.to_json,
headers: {
"Content-Type" => "application/json",
"request-id" => "req_018EeWyXxfu5pfWkrYcMdjWG"
}
)
end
it "retries the request" do
RubyLLM.ask "Something"
expect(WebMock).to have_requested(:post, "https://api.anthropic.com/v1/messages").times(4) # 1 call + 3 (default) retries, this should fail
end
end
Failure/Error: expect(WebMock).to have_requested(:post, "https://api.anthropic.com/v1/messages").times(4)
The request POST https://api.anthropic.com/v1/messages was expected to execute 4 times but it executed 1 time
Expected behavior
POST requests should be retried.
What actually happened
POST requests are not retried.
Environment
Basic checks
What's broken?
Hey, folks,
I think I've discovered a bug, unless, of course, I'm not missing something. I think RubyLLM won't retry POST requets, because it doesn't set the
methodsoption on faraday-retry and also doesn't provide a way to set it.%i[delete get head options put], if no methods are given.methodsoption, hence only idempotent methods are retried,postrequests are never retried.I'm hitting this on Anthropic's POST
v1/messagesendpoint. Tagging @tpaulshippy here as well, as I know he uses Anthropic heavily as well.How to reproduce
RubyLLM has a default config for automatic retries, so need for additional configuration regarding retries. Set Anthropic as provider or make sure that the
askmethod will issue a POST request.Stub an error response and see, that requests are not retried. Something like:
Expected behavior
POST requests should be retried.
What actually happened
POST requests are not retried.
Environment