|
@@ -373,3 +373,113 @@ TEST(Embeddings, ARefusedConnectionNamesTheCONNECTphaseInstead) {
|
|
|
EXPECT_NE(msg.find("establish"), std::string::npos) << msg;
|
|
EXPECT_NE(msg.find("establish"), std::string::npos) << msg;
|
|
|
EXPECT_EQ(msg.find("read"), std::string::npos) << msg;
|
|
EXPECT_EQ(msg.find("read"), std::string::npos) << msg;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// THE DEFECT: a provider that answered 429 or 5xx and a provider that refused
|
|
|
|
|
+// our request both came back as 422. 422 means "your request is unprocessable,
|
|
|
|
|
+// correct it", which is the wrong instruction for a provider's own 503 and the
|
|
|
|
|
+// reason three of novitax's 26,186 writes were lost on 2026-11-05 instead of
|
|
|
|
|
+// retried - their retry set is keyed on STATUS and 422 is not in it. An
|
|
|
|
|
+// immediate retry of the same three texts then succeeded, so the class was
|
|
|
|
|
+// provably wrong rather than merely unhelpful.
|
|
|
|
|
+//
|
|
|
|
|
+// These two tests are a PAIR and are worth nothing apart. The first alone
|
|
|
|
|
+// passes against a mapping that answers 503 for EVERY non-200, which would
|
|
|
|
|
+// turn a misspelled model name into an endless retry; the second alone passes
|
|
|
|
|
+// against the old blanket 422. What has to hold is that they DIFFER, so each
|
|
|
|
|
+// arm asserts the absence of the other's answer.
|
|
|
|
|
+TEST(Embeddings, AProviderFivexxIsRetryableWithAShortRetryAfter) {
|
|
|
|
|
+ httplib::Server mock;
|
|
|
|
|
+ mock.Post("/v1/embeddings", [](const httplib::Request&, httplib::Response& res) {
|
|
|
|
|
+ res.status = 503;
|
|
|
|
|
+ res.set_content(R"({"error":"upstream busy"})", "application/json");
|
|
|
|
|
+ });
|
|
|
|
|
+ int port = mock.bind_to_any_port("127.0.0.1");
|
|
|
|
|
+ std::thread t([&]{ mock.listen_after_bind(); });
|
|
|
|
|
+ EmbeddingClient cli("http://127.0.0.1:" + std::to_string(port), "k");
|
|
|
|
|
+ try {
|
|
|
|
|
+ cli.embed("baai/bge-m3", "ordinary Hungarian prose");
|
|
|
|
|
+ FAIL() << "a provider 503 must throw";
|
|
|
|
|
+ } catch (const ApiError& e) {
|
|
|
|
|
+ EXPECT_EQ(e.slug, "embedding_failed"); // slug deliberately unchanged
|
|
|
|
|
+ EXPECT_EQ(e.code, ErrCode::Unavailable); // NOT Unprocessable
|
|
|
|
|
+ EXPECT_NE(e.code, ErrCode::Unprocessable);
|
|
|
|
|
+ EXPECT_EQ(httpStatus(e.code), 503);
|
|
|
|
|
+ // The header is the half a status-keyed caller cannot infer.
|
|
|
|
|
+ EXPECT_EQ(retryAfterSeconds(e), kRetryAfterEmbeddingProviderSec);
|
|
|
|
|
+ EXPECT_GT(retryAfterSeconds(e), 0);
|
|
|
|
|
+ // The provider's own status survives into the message, which is the
|
|
|
|
|
+ // only place it is recorded: our access log keeps no slug for a 4xx.
|
|
|
|
|
+ EXPECT_NE(std::string(e.what()).find("503"), std::string::npos) << e.what();
|
|
|
|
|
+ }
|
|
|
|
|
+ mock.stop(); t.join();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(Embeddings, AProviderFourxxStaysPermanentAndSaysNOTHINGaboutRetrying) {
|
|
|
|
|
+ // An unknown model or a rejected key. Waiting cannot help, and a
|
|
|
|
|
+ // Retry-After here would invite exactly the hot loop the split avoids.
|
|
|
|
|
+ httplib::Server mock;
|
|
|
|
|
+ mock.Post("/v1/embeddings", [](const httplib::Request&, httplib::Response& res) {
|
|
|
|
|
+ res.status = 400;
|
|
|
|
|
+ res.set_content(R"({"error":"no such model"})", "application/json");
|
|
|
|
|
+ });
|
|
|
|
|
+ int port = mock.bind_to_any_port("127.0.0.1");
|
|
|
|
|
+ std::thread t([&]{ mock.listen_after_bind(); });
|
|
|
|
|
+ EmbeddingClient cli("http://127.0.0.1:" + std::to_string(port), "k");
|
|
|
|
|
+ try {
|
|
|
|
|
+ cli.embed("baai/bge-m3-nonexistent", "ordinary Hungarian prose");
|
|
|
|
|
+ FAIL() << "a provider 400 must throw";
|
|
|
|
|
+ } catch (const ApiError& e) {
|
|
|
|
|
+ EXPECT_EQ(e.slug, "embedding_failed"); // same slug, different class
|
|
|
|
|
+ EXPECT_EQ(e.code, ErrCode::Unprocessable);
|
|
|
|
|
+ EXPECT_NE(e.code, ErrCode::Unavailable);
|
|
|
|
|
+ EXPECT_EQ(httpStatus(e.code), 422);
|
|
|
|
|
+ EXPECT_EQ(retryAfterSeconds(e), 0); // silence, not a guess
|
|
|
|
|
+ EXPECT_NE(std::string(e.what()).find("400"), std::string::npos) << e.what();
|
|
|
|
|
+ }
|
|
|
|
|
+ mock.stop(); t.join();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 429 is the one status that is NOT 5xx and is still the provider's problem, so
|
|
|
|
|
+// it is the single case a `status >= 500` test would miss entirely.
|
|
|
|
|
+TEST(Embeddings, AProvider429IsTransientDespiteBeingA4xx) {
|
|
|
|
|
+ httplib::Server mock;
|
|
|
|
|
+ mock.Post("/v1/embeddings", [](const httplib::Request&, httplib::Response& res) {
|
|
|
|
|
+ res.status = 429;
|
|
|
|
|
+ res.set_content(R"({"error":"rate limited"})", "application/json");
|
|
|
|
|
+ });
|
|
|
|
|
+ int port = mock.bind_to_any_port("127.0.0.1");
|
|
|
|
|
+ std::thread t([&]{ mock.listen_after_bind(); });
|
|
|
|
|
+ EmbeddingClient cli("http://127.0.0.1:" + std::to_string(port), "k");
|
|
|
|
|
+ try {
|
|
|
|
|
+ cli.embed("baai/bge-m3", "t");
|
|
|
|
|
+ FAIL() << "a provider 429 must throw";
|
|
|
|
|
+ } catch (const ApiError& e) {
|
|
|
|
|
+ EXPECT_EQ(e.code, ErrCode::Unavailable) << "429 from the PROVIDER is not our rate limit";
|
|
|
|
|
+ EXPECT_GT(retryAfterSeconds(e), 0);
|
|
|
|
|
+ EXPECT_NE(std::string(e.what()).find("429"), std::string::npos) << e.what();
|
|
|
|
|
+ }
|
|
|
|
|
+ mock.stop(); t.join();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// A 200 carrying a body we cannot parse is a THIRD thing and must not have been
|
|
|
|
|
+// swept into the transient arm: the provider answered, so retrying is pointless.
|
|
|
|
|
+// This is the branch the gzip forensics below eliminated, and it is the one a
|
|
|
|
|
+// careless "any failure here is transient" change would silently reclassify.
|
|
|
|
|
+TEST(Embeddings, AMalformedTwoHundredStaysPermanent) {
|
|
|
|
|
+ httplib::Server mock;
|
|
|
|
|
+ mock.Post("/v1/embeddings", [](const httplib::Request&, httplib::Response& res) {
|
|
|
|
|
+ res.set_content(R"({"data":[{"embedding":[]}]})", "application/json");
|
|
|
|
|
+ });
|
|
|
|
|
+ int port = mock.bind_to_any_port("127.0.0.1");
|
|
|
|
|
+ std::thread t([&]{ mock.listen_after_bind(); });
|
|
|
|
|
+ EmbeddingClient cli("http://127.0.0.1:" + std::to_string(port), "k");
|
|
|
|
|
+ try {
|
|
|
|
|
+ cli.embed("m", "t");
|
|
|
|
|
+ FAIL() << "an empty embedding[] must throw";
|
|
|
|
|
+ } catch (const ApiError& e) {
|
|
|
|
|
+ EXPECT_EQ(e.slug, "embedding_failed");
|
|
|
|
|
+ EXPECT_EQ(e.code, ErrCode::Unprocessable);
|
|
|
|
|
+ EXPECT_EQ(retryAfterSeconds(e), 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ mock.stop(); t.join();
|
|
|
|
|
+}
|