Просмотр исходного кода

fix: ctx.collections READS keep the database's classification too

On the function surface the WRITE paths carry a database arm and the READ
paths did not. `insert` and `store` both do

    catch (const Client::Error& e) { throw apiErrorFor(e); }

while `find`, `get` and the vector `search` had no such arm at all. So a
Client::Error from a read fell through to `guarded()`, which catches
std::exception and converts it to ApiError(Internal, "internal"), and
`details` went with it. `apiErrorFor` sits in the same file: the
classification existed and was discarded one frame short of the script.

The live consequence, measured: a cold similarity search overran the 5 s
DbGateway deadline, the client raised DeadlineExceeded, and the function
was told `internal` / 500 about what is really `db_unavailable` / 503 with
a Retry-After. A consumer who had deliberately made `e.code` load-bearing
for their database bucket could not see a database fault as one - so the
remedy ("wait") was unreachable from the only channel they branch on.

Same shape as the sibling commit: the instrument reports the shape it was
designed to report and the mechanism arrives stripped.

WHAT IS PINNED AND WHAT IS NOT, written beside the arms because the suite
looks like it covers this. test_db_errors.cpp pins the MAPPING these arms
rest on - a reason-less DeadlineExceeded on a read is db_unavailable, 503,
with a retry hint. Nothing pins the ARM, because making a read fail needs
a database that fails and these tests share a live one, so deleting these
three catches would leave the suite entirely green.

Note what this does NOT buy on `get`: Client::get returns nullopt for both
"absent" and "the call failed" (the reason CollectionRegistry::get retries
and health-checks), so a transport failure the client swallows still reads
as a missing document. The arm fixes only the case the client raises.
fszontagh 3 недель назад
Родитель
Сommit
891373676b
1 измененных файлов с 46 добавлено и 5 удалено
  1. 46 5
      runner/src/host_context.cpp

+ 46 - 5
runner/src/host_context.cpp

@@ -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