|
|
@@ -1798,8 +1798,30 @@ struct HostContext::Impl {
|
|
|
auto opts = hostdetail::queryOptionsFrom(payload);
|
|
|
meta(collection);
|
|
|
nlohmann::json out = nlohmann::json::array();
|
|
|
- for (const auto& doc : db.client().find(qualify(config.project, collection), opts))
|
|
|
- out.push_back(doc);
|
|
|
+ // THE SAME ARM THE WRITE PATHS HAVE. Without it a database failure
|
|
|
+ // escaped as a bare Client::Error, `guarded()` caught it on its
|
|
|
+ // std::exception arm, and the script saw code `internal` with status
|
|
|
+ // 500 - so a read that failed because the database was briefly
|
|
|
+ // unavailable was indistinguishable from a bug in the host, and the
|
|
|
+ // `Retry-After` that says waiting is the remedy was never sent. The
|
|
|
+ // classification exists and was being discarded one frame short of the
|
|
|
+ // caller. Measured as a live consequence: a consumer branching on
|
|
|
+ // `e.code` could not see a `similaritySearch` deadline as a database
|
|
|
+ // fault at all.
|
|
|
+ //
|
|
|
+ // WHAT IS PINNED AND WHAT IS NOT, stated because the suite looks like
|
|
|
+ // it covers this and does not: `test_db_errors.cpp` pins the MAPPING
|
|
|
+ // these arms depend on (a reason-less DeadlineExceeded on a read is
|
|
|
+ // `db_unavailable`, 503, with a retry hint). Nothing pins the ARM
|
|
|
+ // itself, because making a read fail needs a database that fails, and
|
|
|
+ // these tests share a live one. So a later edit that deleted these
|
|
|
+ // three catches would leave the suite entirely green.
|
|
|
+ try {
|
|
|
+ for (const auto& doc : db.client().find(qualify(config.project, collection), opts))
|
|
|
+ out.push_back(doc);
|
|
|
+ } catch (const smartbotic::database::Client::Error& e) {
|
|
|
+ throw apiErrorFor(e);
|
|
|
+ }
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
@@ -1811,7 +1833,18 @@ struct HostContext::Impl {
|
|
|
nlohmann::json get(const std::string& collection, const nlohmann::json& payload) {
|
|
|
const std::string id = documentId(payload);
|
|
|
meta(collection);
|
|
|
- auto doc = db.client().get(qualify(config.project, collection), id);
|
|
|
+ // Note what this arm can and cannot buy: `Client::get` returns nullopt
|
|
|
+ // for BOTH "absent" and "the call failed" (see CollectionRegistry::get,
|
|
|
+ // which retries and health-checks for exactly that reason), so a
|
|
|
+ // transport failure that the client swallows into nullopt still reads
|
|
|
+ // here as a missing document. What the arm fixes is the case the client
|
|
|
+ // DOES raise, which used to arrive as `internal`/500.
|
|
|
+ std::optional<nlohmann::json> doc;
|
|
|
+ try {
|
|
|
+ doc = db.client().get(qualify(config.project, collection), id);
|
|
|
+ } catch (const smartbotic::database::Client::Error& e) {
|
|
|
+ throw apiErrorFor(e);
|
|
|
+ }
|
|
|
return doc ? *doc : nlohmann::json(nullptr);
|
|
|
}
|
|
|
|
|
|
@@ -2036,8 +2069,16 @@ struct HostContext::Impl {
|
|
|
// that now includes how deep the walk goes.
|
|
|
loadSettings();
|
|
|
const uint32_t scanCap = global.vectorFilterScanCap;
|
|
|
- const VectorSearchResult found =
|
|
|
- vectorSearch(db.client(), c, q, topK, minScore, filters, scanCap);
|
|
|
+ VectorSearchResult found;
|
|
|
+ try {
|
|
|
+ found = vectorSearch(db.client(), c, q, topK, minScore, filters, scanCap);
|
|
|
+ } catch (const smartbotic::database::Client::Error& e) {
|
|
|
+ // The path that actually bit a consumer: a cold similarity search
|
|
|
+ // overran the gateway deadline, the client raised
|
|
|
+ // DeadlineExceeded, and the script was told `internal`/500 about
|
|
|
+ // what is really `db_unavailable`/503 with a retry hint.
|
|
|
+ throw apiErrorFor(e);
|
|
|
+ }
|
|
|
|
|
|
// The console warning STAYS - it is what an author reading a run log
|
|
|
// sees. But it is no longer the only signal, because a console line
|