Browse Source

fix: 2.12.4 - a failed read throws instead of answering "nothing there"

Reported by smartbotic-vectorapi: Client::get returned nullopt for every failed
status except PERMISSION_DENIED, so UNAVAILABLE / DEADLINE_EXCEEDED was the same
value as "no such document". A transient blip became a definite 404 - which a
careful client cannot retry - and cost a consumer a six-minute ingest.

The same shape was on about twenty reads: exists (false), count (0), find and
findWithMetrics (empty; they threw only on NOT_FOUND), setMembers,
setIsMember, both version reads, every list read, getCollectionInfo,
getViewInfo, getRelationInfo, hasCollectionConfig (false) and
getCollectionConfig (the defaults). They now throw Client::Error with the code
on any failed status. Safe because the server reports every absence in-band;
only Find uses a NOT_FOUND status, and that already threw.

Exempt by design: healthCheck, getHealthInfo, getStats, getRelationsEnforced,
tryGetRelationsEnforced; writes keep their return values. update() read
through get() and reported an outage as NotFound; it now records the real code.

ERROR-SHAPE CHANGE under the same soname, chosen over additive overloads: a
caller with no try around these reads now sees a throw during an outage. A
denied schema read on a secured project now throws PermissionDenied instead of
answering empty (test_policy_enforcement updated to assert the denial).

Test: test_read_failures (port 9022): 24 reads through three server states -
up (genuine absences still empty, never thrown), SIGSTOPped (DeadlineExceeded)
and stopped (Unavailable). Reverting the client fails 49 of 54 frozen checks.
ctest 23/23, 17/17 e2e. ABI: soname 2, no type or signature change.
fszontagh 1 month ago
parent
commit
6fe5ffaf8e

File diff suppressed because it is too large
+ 0 - 0
CLAUDE.md


+ 1 - 1
VERSION

@@ -1 +1 @@
-2.12.3
+2.12.4

+ 14 - 2
client/include/smartbotic/database/client.hpp

@@ -69,6 +69,15 @@ public:
      * Thrown by the calls that throw (insert, upsert, find, findWithMetrics,
      * Thrown by the calls that throw (insert, upsert, find, findWithMetrics,
      * similaritySearch, the file calls, and get/exists/count on a denial).
      * similaritySearch, the file calls, and get/exists/count on a denial).
      *
      *
+     * v2.12.4: every READ whose "nothing there" value (nullopt, false, 0, an
+     * empty list, a default config) is also a valid answer now throws this on
+     * ANY failed status - get, exists, find, findWithMetrics, count,
+     * setMembers, setIsMember, the version reads, and the collection, index,
+     * view, relation and project reads. The empty value now means only that
+     * the server answered "absent"; an outage (Unavailable, DeadlineExceeded)
+     * is no longer indistinguishable from it. Exempt: healthCheck,
+     * getHealthInfo, getStats, getRelationsEnforced, tryGetRelationsEnforced.
+     *
      * Derives from std::runtime_error with what() unchanged, so every
      * Derives from std::runtime_error with what() unchanged, so every
      * existing `catch (const std::runtime_error&)` and
      * existing `catch (const std::runtime_error&)` and
      * `catch (const std::exception&)` behaves exactly as before. New code can
      * `catch (const std::exception&)` behaves exactly as before. New code can
@@ -300,7 +309,9 @@ public:
                       const std::string& actor = "");
                       const std::string& actor = "");
 
 
     /**
     /**
-     * Get a document by ID.
+     * Get a document by ID. nullopt means the server answered "no such
+     * document" (or no such collection). A failed call throws Client::Error
+     * with its code (v2.12.4; before it, an outage also returned nullopt).
      */
      */
     [[nodiscard]] std::optional<nlohmann::json> get(const std::string& collection, const std::string& id);
     [[nodiscard]] std::optional<nlohmann::json> get(const std::string& collection, const std::string& id);
 
 
@@ -540,7 +551,8 @@ public:
                                                   FailureDetail& failureOut);
                                                   FailureDetail& failureOut);
 
 
     /**
     /**
-     * Check if a document exists.
+     * Check if a document exists. false means the server answered "absent";
+     * a failed call throws Client::Error (v2.12.4).
      */
      */
     [[nodiscard]] bool exists(const std::string& collection, const std::string& id);
     [[nodiscard]] bool exists(const std::string& collection, const std::string& id);
 
 

+ 64 - 25
client/src/client.cpp

@@ -119,6 +119,21 @@ struct DetailedPermissionDenied : Client::PermissionDenied, DetailCarrier {
         : Client::PermissionDenied(m), DetailCarrier(std::move(d)) {}
         : Client::PermissionDenied(m), DetailCarrier(std::move(d)) {}
 };
 };
 
 
+// v2.12.4 - THE RULE FOR READS: a read whose "nothing there" value (nullopt,
+// false, 0, an empty list, a default config) is also a valid answer must THROW
+// on a failed status, never return that value. Returning it made a transport
+// blip (UNAVAILABLE, DEADLINE_EXCEEDED) indistinguishable from absence, so a
+// consumer reported a definite 404 for a collection that existed and lost a
+// six-minute ingest to it. v2.4.2 (find on a missing collection) and v2.8.0
+// (permission denials) applied this rule one status code at a time; it now
+// applies to every code. Absence is always reported IN-BAND by the server
+// (found=false, exists=false, an empty list); only Find uses a NOT_FOUND
+// status, and that already threw. Exempt, deliberately: healthCheck /
+// getHealthInfo / getStats (their job is to answer "unreachable"),
+// getRelationsEnforced (fails toward enforced) and tryGetRelationsEnforced
+// (declines to answer). Writes keep returning false/0 - false already means
+// "did not happen", and they have Failure& overloads carrying the code.
+//
 // Throw the Client::Error subtype matching a failed status. `message` becomes
 // Throw the Client::Error subtype matching a failed status. `message` becomes
 // what(): every site passes what it threw before 2.11.4, so the text an
 // what(): every site passes what it threw before 2.11.4, so the text an
 // existing consumer logs or matches on is unchanged. v2.12.0: the thrown
 // existing consumer logs or matches on is unchanged. v2.12.0: the thrown
@@ -444,7 +459,7 @@ public:
                 throw Client::PermissionDenied("access denied: get");
                 throw Client::PermissionDenied("access denied: get");
             }
             }
             spdlog::error("Client::get failed: {}", status.error_message());
             spdlog::error("Client::get failed: {}", status.error_message());
-            return std::nullopt;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         if (!response.found()) {
         if (!response.found()) {
@@ -478,8 +493,21 @@ public:
         // 2. Call updateIfVersion
         // 2. Call updateIfVersion
         // 3. On version conflict (another writer), re-read and retry
         // 3. On version conflict (another writer), re-read and retry
         for (uint32_t attempt = 0; attempt <= config_.maxRetries; ++attempt) {
         for (uint32_t attempt = 0; attempt <= config_.maxRetries; ++attempt) {
-            // Get current version
-            auto current = get(collection, id);
+            // Get current version. v2.12.4: get() now throws on a failed read
+            // instead of returning nullopt. Before, an unreachable database
+            // was reported here as "document not found" - the same conflation
+            // get() had. update() still reports failure by returning false,
+            // so the real code is recorded instead. A permission denial threw
+            // out of here before 2.12.4 too, and still does.
+            std::optional<nlohmann::json> current;
+            try {
+                current = get(collection, id);
+            } catch (const Client::PermissionDenied&) {
+                throw;
+            } catch (const Client::Error& e) {
+                failureOut.record(e.code(), e.what());
+                return false;
+            }
             if (!current) {
             if (!current) {
                 // The one failure here the client can name itself, without
                 // The one failure here the client can name itself, without
                 // reading a server message: get() just said there is no
                 // reading a server message: get() just said there is no
@@ -801,7 +829,7 @@ public:
                 throw Client::PermissionDenied("access denied: exists");
                 throw Client::PermissionDenied("access denied: exists");
             }
             }
             spdlog::error("Client::exists failed: {}", status.error_message());
             spdlog::error("Client::exists failed: {}", status.error_message());
-            return false;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         return response.exists();
         return response.exists();
@@ -849,8 +877,8 @@ public:
         if (status.error_code() == grpc::StatusCode::NOT_FOUND) {
         if (status.error_code() == grpc::StatusCode::NOT_FOUND) {
             // Surfaced rather than logged: an unknown collection or view is a
             // Surfaced rather than logged: an unknown collection or view is a
             // caller bug, and returning {} here is indistinguishable from a
             // caller bug, and returning {} here is indistinguishable from a
-            // legitimately empty result. Other failures keep the old
-            // log-and-return-empty behaviour.
+            // legitimately empty result. Since v2.12.4 every other failure
+            // throws too (below).
             throwStatus(status, status.error_message());
             throwStatus(status, status.error_message());
         }
         }
         if (!status.ok()) {
         if (!status.ok()) {
@@ -864,7 +892,7 @@ public:
                 throw Client::PermissionDenied("access denied: find");
                 throw Client::PermissionDenied("access denied: find");
             }
             }
             spdlog::error("Client::find failed: {}", status.error_message());
             spdlog::error("Client::find failed: {}", status.error_message());
-            return {};
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         std::vector<nlohmann::json> results;
         std::vector<nlohmann::json> results;
@@ -934,7 +962,7 @@ public:
                 throw Client::PermissionDenied("access denied: findWithMetrics");
                 throw Client::PermissionDenied("access denied: findWithMetrics");
             }
             }
             spdlog::error("Client::findWithMetrics failed: {}", status.error_message());
             spdlog::error("Client::findWithMetrics failed: {}", status.error_message());
-            return {};
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         Client::FindResult result;
         Client::FindResult result;
@@ -989,7 +1017,7 @@ public:
                 throw Client::PermissionDenied("access denied: count");
                 throw Client::PermissionDenied("access denied: count");
             }
             }
             spdlog::error("Client::count failed: {}", status.error_message());
             spdlog::error("Client::count failed: {}", status.error_message());
-            return 0;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         return response.count();
         return response.count();
@@ -1047,7 +1075,7 @@ public:
         auto status = stub_->SetMembers(&context, request, &response);
         auto status = stub_->SetMembers(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::setMembers failed: {}", status.error_message());
             spdlog::error("Client::setMembers failed: {}", status.error_message());
-            return {};
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         return {response.members().begin(), response.members().end()};
         return {response.members().begin(), response.members().end()};
@@ -1066,7 +1094,7 @@ public:
         auto status = stub_->SetIsMember(&context, request, &response);
         auto status = stub_->SetIsMember(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::setIsMember failed: {}", status.error_message());
             spdlog::error("Client::setIsMember failed: {}", status.error_message());
-            return false;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         return response.is_member();
         return response.is_member();
@@ -1180,7 +1208,7 @@ public:
         auto status = stub_->ListCollections(&context, request, &response);
         auto status = stub_->ListCollections(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::listCollections failed: {}", status.error_message());
             spdlog::error("Client::listCollections failed: {}", status.error_message());
-            return {};
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         // v2.4.5 — round-trip the naming: callers pass bare names in, so they
         // v2.4.5 — round-trip the naming: callers pass bare names in, so they
@@ -1210,7 +1238,7 @@ public:
         auto status = stub_->GetCollectionInfo(&context, request, &response);
         auto status = stub_->GetCollectionInfo(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::getCollectionInfo failed: {}", status.error_message());
             spdlog::error("Client::getCollectionInfo failed: {}", status.error_message());
-            return std::nullopt;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         if (!response.found()) {
         if (!response.found()) {
@@ -1241,7 +1269,7 @@ public:
         auto status = stub_->ListProjects(&context, request, &response);
         auto status = stub_->ListProjects(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::listProjects failed: {}", status.error_message());
             spdlog::error("Client::listProjects failed: {}", status.error_message());
-            return {};
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         return {response.projects().begin(), response.projects().end()};
         return {response.projects().begin(), response.projects().end()};
     }
     }
@@ -1329,7 +1357,7 @@ public:
         auto status = stub_->GetCollectionConfig(&context, request, &response);
         auto status = stub_->GetCollectionConfig(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::getCollectionConfig failed: {}", status.error_message());
             spdlog::error("Client::getCollectionConfig failed: {}", status.error_message());
-            return out;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         out.timestampPrecision = response.config().timestamp_precision();
         out.timestampPrecision = response.config().timestamp_precision();
         if (out.timestampPrecision.empty()) out.timestampPrecision = "ms";
         if (out.timestampPrecision.empty()) out.timestampPrecision = "ms";
@@ -1352,7 +1380,10 @@ public:
         setDeadline(context);
         setDeadline(context);
 
 
         auto status = stub_->GetCollectionConfig(&context, request, &response);
         auto status = stub_->GetCollectionConfig(&context, request, &response);
-        if (!status.ok()) return false;
+        if (!status.ok()) {
+            spdlog::error("Client::hasCollectionConfig failed: {}", status.error_message());
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
+        }
         return response.found();
         return response.found();
     }
     }
 
 
@@ -1605,7 +1636,7 @@ public:
         auto status = stub_->ListIndexes(&context, request, &response);
         auto status = stub_->ListIndexes(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::listIndexes failed: {}", status.error_message());
             spdlog::error("Client::listIndexes failed: {}", status.error_message());
-            return out;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         out.reserve(response.indexes_size());
         out.reserve(response.indexes_size());
         if (uniqueFlags != nullptr) {
         if (uniqueFlags != nullptr) {
@@ -1687,7 +1718,7 @@ public:
         auto status = stub_->ListIndexes(&context, request, &response);
         auto status = stub_->ListIndexes(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::listCompositeUniqueIndexes failed: {}", status.error_message());
             spdlog::error("Client::listCompositeUniqueIndexes failed: {}", status.error_message());
-            return out;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         for (const auto& i : response.indexes()) {
         for (const auto& i : response.indexes()) {
             if (i.fields_size() > 0) out.emplace_back(i.fields().begin(), i.fields().end());
             if (i.fields_size() > 0) out.emplace_back(i.fields().begin(), i.fields().end());
@@ -1711,7 +1742,7 @@ public:
         auto status = stub_->GetIndexValues(&context, request, &response);
         auto status = stub_->GetIndexValues(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::indexValues failed: {}", status.error_message());
             spdlog::error("Client::indexValues failed: {}", status.error_message());
-            return out;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         out.reserve(response.values_size());
         out.reserve(response.values_size());
         for (const auto& v : response.values()) {
         for (const auto& v : response.values()) {
@@ -1754,7 +1785,7 @@ public:
         auto status = stub_->ListViews(&context, request, &response);
         auto status = stub_->ListViews(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::listViews failed: {}", status.error_message());
             spdlog::error("Client::listViews failed: {}", status.error_message());
-            return out;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         for (const auto& pb : response.views()) {
         for (const auto& pb : response.views()) {
             Client::ViewDefinition v;
             Client::ViewDefinition v;
@@ -1792,7 +1823,11 @@ public:
         setDeadline(context);
         setDeadline(context);
 
 
         auto status = stub_->GetViewInfo(&context, request, &response);
         auto status = stub_->GetViewInfo(&context, request, &response);
-        if (!status.ok() || !response.found()) {
+        if (!status.ok()) {
+            spdlog::error("Client::getViewInfo failed: {}", status.error_message());
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
+        }
+        if (!response.found()) {
             return std::nullopt;
             return std::nullopt;
         }
         }
         Client::ViewDefinition v;
         Client::ViewDefinition v;
@@ -1909,7 +1944,7 @@ public:
         auto status = stub_->ListRelations(&context, request, &response);
         auto status = stub_->ListRelations(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::listRelations failed: {}", status.error_message());
             spdlog::error("Client::listRelations failed: {}", status.error_message());
-            return out;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
         out.reserve(response.relations_size());
         out.reserve(response.relations_size());
         for (const auto& pb : response.relations()) {
         for (const auto& pb : response.relations()) {
@@ -1926,7 +1961,11 @@ public:
         setDeadline(context);
         setDeadline(context);
 
 
         auto status = stub_->GetRelationInfo(&context, request, &response);
         auto status = stub_->GetRelationInfo(&context, request, &response);
-        if (!status.ok() || !response.found()) {
+        if (!status.ok()) {
+            spdlog::error("Client::getRelationInfo failed: {}", status.error_message());
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
+        }
+        if (!response.found()) {
             return std::nullopt;
             return std::nullopt;
         }
         }
         return relationFromProto(response.relation());
         return relationFromProto(response.relation());
@@ -2135,7 +2174,7 @@ public:
         auto status = stub_->GetVersionHistory(&context, request, &response);
         auto status = stub_->GetVersionHistory(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::getVersionHistory failed: {}", status.error_message());
             spdlog::error("Client::getVersionHistory failed: {}", status.error_message());
-            return {};
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         Client::VersionHistoryResult result;
         Client::VersionHistoryResult result;
@@ -2172,7 +2211,7 @@ public:
         auto status = stub_->GetDocumentVersion(&context, request, &response);
         auto status = stub_->GetDocumentVersion(&context, request, &response);
         if (!status.ok()) {
         if (!status.ok()) {
             spdlog::error("Client::getDocumentVersion failed: {}", status.error_message());
             spdlog::error("Client::getDocumentVersion failed: {}", status.error_message());
-            return std::nullopt;
+            throwStatus(status, status.error_message());  // v2.12.4: never empty on failure
         }
         }
 
 
         if (!response.found()) {
         if (!response.found()) {

+ 6 - 2
docs/ROADMAP.md

@@ -1,6 +1,6 @@
 # Smartbotic Database - Status and Roadmap
 # Smartbotic Database - Status and Roadmap
 
 
-**Released version: 2.12.3** (see `VERSION`). Last reviewed: 2026-10-07.
+**Released version: 2.12.4** (see `VERSION`). Last reviewed: 2026-10-07.
 
 
 > 2.11.5 was prepared but never released on its own: its work (event actors,
 > 2.11.5 was prepared but never released on its own: its work (event actors,
 > `removeAs()`) ships inside 2.12.0. There is no 2.11.5 package.
 > `removeAs()`) ships inside 2.12.0. There is no 2.11.5 package.
@@ -56,7 +56,7 @@ Consequences of that substitution, which trip up readers:
 
 
 ## Shipped
 ## Shipped
 
 
-Every item below is in the installed product as of 2.12.3. `CLAUDE.md` has the
+Every item below is in the installed product as of 2.12.4. `CLAUDE.md` has the
 detail and the failure modes.
 detail and the failure modes.
 
 
 - JSON document store: collections, version history, field-level encryption, TTL
 - JSON document store: collections, version history, field-level encryption, TTL
@@ -87,6 +87,10 @@ detail and the failure modes.
   older version (2.12.2)
   older version (2.12.2)
 - File store: `dropProject` deletes the project's files, the upload size limit
 - File store: `dropProject` deletes the project's files, the upload size limit
   refuses mid-stream with `file_too_large`, downloads stream from disk (2.12.3)
   refuses mid-stream with `file_too_large`, downloads stream from disk (2.12.3)
+- A failed READ throws `Client::Error` with its code instead of answering
+  empty/nullopt/false/0, on every read whose empty value is also a valid
+  answer; `update()` reports an outage with its real code, not `NotFound`
+  (2.12.4)
 - Conditional partial update (`patchIfVersion`) and atomic increment
 - Conditional partial update (`patchIfVersion`) and atomic increment
   (`increment`) (2.12.0)
   (`increment`) (2.12.0)
 - Event provenance: the actor on every `DatabaseEvent`, `removeAs()`,
 - Event provenance: the actor on every `DatabaseEvent`, `removeAs()`,

+ 55 - 3
docs/integration-guide.md

@@ -226,9 +226,9 @@ longer look the same. Nothing here needs matching on message text.
 
 
 The client has two kinds of call, and each reports the code its own way.
 The client has two kinds of call, and each reports the code its own way.
 
 
-**Calls that throw** - `insert`, `upsert`, `find`, `findWithMetrics`,
-`similaritySearch`, the file calls, and `get`/`exists`/`count` on a denial -
-throw `Client::Error`, which carries `code()`. `Client::AlreadyExists`,
+**Calls that throw** - `insert`, `upsert`, `similaritySearch`, the file calls,
+and from 2.12.4 **every read** (see below) - throw `Client::Error`, which
+carries `code()`. `Client::AlreadyExists`,
 `Client::FailedPrecondition` and `Client::PermissionDenied` are subtypes for
 `Client::FailedPrecondition` and `Client::PermissionDenied` are subtypes for
 when you only care about one:
 when you only care about one:
 
 
@@ -275,6 +275,58 @@ if (!db.remove("workflows", "wf-1", why)) {
 
 
 `Failure` is reset at the start of every call, so it is safe to reuse.
 `Failure` is reset at the start of every call, so it is safe to reuse.
 
 
+#### A failed read throws; "not there" is an answer (2.12.4+)
+
+Before 2.12.4 most reads answered a failed call with the same value they use
+for "nothing there": `get` returned `nullopt`, `exists` false, `count` 0, `find`
+and every list an empty vector, `getCollectionConfig` the defaults. An
+unreachable database or a missed deadline was therefore indistinguishable from
+a genuine absence, and a transient blip reached an end user as a definite 404 -
+which a careful client cannot retry, since retrying every 404 retries every real
+absence too.
+
+From 2.12.4 those reads **throw `Client::Error` on any failed status**, with the
+code (`Unavailable`, `DeadlineExceeded`, `InvalidArgument`, ...), and keep
+returning the empty value **only** for a real absence, which the server always
+reports inside a successful reply:
+
+`get`, `exists`, `find`, `findWithMetrics`, `count`, `setMembers`,
+`setIsMember`, `getVersionHistory`, `getDocumentVersion`, `listCollections`,
+`getCollectionInfo`, `listProjects`, `getCollectionConfig`,
+`hasCollectionConfig`, `listIndexes`, `listCompositeUniqueIndexes`,
+`indexValues`, `listViews`, `getViewInfo`, `listRelations`, `getRelationInfo`.
+
+```cpp
+try {
+    auto doc = db.get("sources", id);
+    if (!doc) return notFound();            // the database answered: no such document
+    return ok(*doc);
+} catch (const Client::Error& e) {
+    if (e.code() == Client::ErrorCode::Unavailable ||
+        e.code() == Client::ErrorCode::DeadlineExceeded)
+        return unavailable(e.what());       // 503: retry; this is NOT an absence
+    return internal(e.what());
+}
+```
+
+The same applies to a refusal: with an access policy enabled, a read the caller
+may not make (for example `listRelations` by a non-admin) throws
+`Client::PermissionDenied` instead of answering empty.
+
+**Unchanged on purpose:** `healthCheck()` answers false (its job is to say
+"unreachable"), `getHealthInfo()`/`getStats()` return nullopt,
+`getRelationsEnforced()` fails toward `true`, `tryGetRelationsEnforced()`
+declines with nullopt, and writes keep reporting through their return value.
+`update()` reads before it writes; an outage there used to come back as
+`NotFound` ("document not found"), and now comes back with the real code in its
+`Failure`.
+
+**⚠ Migrating to 2.12.4.** A read that returned empty during an outage now
+throws. Code that called these reads without a `try` - in particular on a
+background thread, where an uncaught exception terminates the process - must
+catch `Client::Error` (or `std::exception`). The soname is unchanged, so this
+applies as soon as the library is upgraded, without a rebuild.
+
 #### The full reason: `FailureDetail` (2.12.0+)
 #### The full reason: `FailureDetail` (2.12.0+)
 
 
 A status code alone is ambiguous - `FailedPrecondition` means a missing parent,
 A status code alone is ambiguous - `FailedPrecondition` means a missing parent,

+ 20 - 8
tests/load_test/test_policy_enforcement.cpp

@@ -180,10 +180,15 @@ int main(int argc, char** argv) {
        "and 'docs_rel' still exists - the denied attempt did not drop it");
        "and 'docs_rel' still exists - the denied attempt did not drop it");
 
 
     {
     {
-        auto strangerList = stranger.listRelations();
-        bool sawDocsRel = false;
-        for (const auto& r : strangerList) if (r.name == "docs_rel") sawDocsRel = true;
-        ck(!sawDocsRel, "stranger's ListRelations does not include 'docs_rel'");
+        // v2.12.4: a denied read THROWS rather than answering empty, so the
+        // stranger is told it was refused instead of being shown an empty
+        // listing it could mistake for "no relations".
+        bool strangerDenied = false, sawDocsRel = false;
+        try {
+            for (const auto& r : stranger.listRelations()) if (r.name == "docs_rel") sawDocsRel = true;
+        } catch (const Client::PermissionDenied&) { strangerDenied = true; }
+        ck(strangerDenied && !sawDocsRel,
+           "stranger's ListRelations is refused with PermissionDenied, not an empty list");
 
 
         auto opsList = ops.listRelations();
         auto opsList = ops.listRelations();
         bool adminSawDocsRel = false;
         bool adminSawDocsRel = false;
@@ -193,10 +198,17 @@ int main(int argc, char** argv) {
                             "relation being gone");
                             "relation being gone");
     }
     }
 
 
-    ck(!stranger.getRelationInfo("docs_rel").has_value(),
-       "stranger is denied on GetRelationInfo for a relation that DOES "
-       "exist (proven by the admin listing above) - so this is a real "
-       "denial, not 'not found'");
+    {
+        // v2.12.4: before, this returned nullopt - indistinguishable from
+        // "not found", which is exactly what the assertion meant to rule out.
+        bool denied = false, leaked = false;
+        try { leaked = stranger.getRelationInfo("docs_rel").has_value(); }
+        catch (const Client::PermissionDenied&) { denied = true; }
+        ck(denied && !leaked,
+           "stranger is denied on GetRelationInfo for a relation that DOES "
+           "exist (proven by the admin listing above) - PermissionDenied, "
+           "not 'not found'");
+    }
     ck(ops.getRelationInfo("docs_rel").has_value(),
     ck(ops.getRelationInfo("docs_rel").has_value(),
        "admin's GetRelationInfo still works for the same name");
        "admin's GetRelationInfo still works for the same name");
 
 

+ 143 - 0
tests/load_test/test_read_failures.cpp

@@ -0,0 +1,143 @@
+// v2.12.4 client/server boundary test: a read that FAILS must not look like a
+// read that found NOTHING.
+//
+// Reported by smartbotic-vectorapi: Client::get() returned nullopt for every
+// failed status except PERMISSION_DENIED, so a transport blip (UNAVAILABLE,
+// DEADLINE_EXCEEDED) was the same value as "no such document". Their collection
+// lookup is one get(); a blip became a definite "no such collection" 404, which
+// a careful client cannot retry, and a consumer lost a six-minute ingest to it.
+// The same shape was on about twenty reads: exists() said false, count() said 0,
+// find() and every list said "empty", getCollectionConfig() returned defaults.
+//
+// Phases, each run by test_read_failures.sh against a different server state:
+//   absent  - server up. A genuine absence must still be reported as one
+//             (nullopt / false / 0 / empty) and must NOT throw, for every read;
+//             a fix that throws whenever the answer is empty fails here.
+//   frozen  - server SIGSTOPped: alive but unresponsive, the "blip". Every read
+//             must throw Client::Error with DeadlineExceeded.
+//   down    - server stopped. Every read must throw with Unavailable.
+// In both failure phases update() must still return false (writes report
+// through the return value) with the REAL code, not NotFound - before 2.12.4 it
+// read through get() and reported an outage as "document not found". The
+// exempt reads are pinned too: healthCheck() answers false,
+// tryGetRelationsEnforced() declines, getRelationsEnforced() fails toward true.
+
+#include <smartbotic/database/client.hpp>
+#include <functional>
+#include <iostream>
+#include <string>
+#include <utility>
+#include <vector>
+
+using namespace smartbotic::database;
+static int pass = 0, fail = 0;
+static void ck(bool c, const std::string& m) {
+    if (c) { ++pass; } else { ++fail; std::cerr << "FAIL: " << m << "\n"; }
+}
+
+// Each changed read, called on things that do not exist. In the absent phase
+// each lambda returns true when the answer was the "nothing there" value.
+static std::vector<std::pair<std::string, std::function<bool(Client&)>>> reads() {
+    return {
+        {"get",                 [](Client& c) { return !c.get("things", "nope").has_value(); }},
+        {"get (no collection)", [](Client& c) { return !c.get("no_such_coll", "x").has_value(); }},
+        {"exists",              [](Client& c) { return !c.exists("things", "nope"); }},
+        {"find",                [](Client& c) { return c.find("things", Client::QueryOptions{.filters = {Client::Filter::eq("k", "zzz")}}).empty(); }},
+        {"findWithMetrics",     [](Client& c) { return c.findWithMetrics("things", Client::QueryOptions{.filters = {Client::Filter::eq("k", "zzz")}}).documents.empty(); }},
+        {"count(filters)",      [](Client& c) { return c.count("things", {Client::Filter::eq("k", "zzz")}) == 0; }},
+        {"count",               [](Client& c) { return c.count("empty_coll") == 0; }},
+        {"setMembers",          [](Client& c) { return c.setMembers("sets", "no_set").empty(); }},
+        {"setIsMember",         [](Client& c) { return !c.setIsMember("sets", "s1", "nobody"); }},
+        {"listCollections",     [](Client& c) { auto v = c.listCollections(); (void)v; return true; }},
+        {"getCollectionInfo",   [](Client& c) { return !c.getCollectionInfo("no_such_coll").has_value(); }},
+        {"listProjects",        [](Client& c) { auto v = c.listProjects(); (void)v; return true; }},
+        {"getCollectionConfig", [](Client& c) { auto v = c.getCollectionConfig("no_such_coll"); (void)v; return true; }},
+        {"hasCollectionConfig", [](Client& c) { return !c.hasCollectionConfig("no_such_coll"); }},
+        {"listIndexes",         [](Client& c) { return c.listIndexes("things").empty(); }},
+        {"listCompositeUniqueIndexes", [](Client& c) { return c.listCompositeUniqueIndexes("things").empty(); }},
+        {"indexValues",         [](Client& c) { return c.indexValues("things", "unindexed").empty(); }},
+        {"listViews",           [](Client& c) { return c.listViews().empty(); }},
+        {"getViewInfo",         [](Client& c) { return !c.getViewInfo("no_such_view").has_value(); }},
+        {"listRelations",       [](Client& c) { return c.listRelations().empty(); }},
+        {"listRelations(project)", [](Client& c) { return c.listRelations("rf").empty(); }},
+        {"getRelationInfo",     [](Client& c) { return !c.getRelationInfo("no_such_rel").has_value(); }},
+        {"getVersionHistory",   [](Client& c) { return c.getVersionHistory("things", "nope").versions.empty(); }},
+        {"getDocumentVersion",  [](Client& c) { return !c.getDocumentVersion("things", "nope", 1).has_value(); }},
+    };
+}
+
+static int absent() {
+    Client c({.address = "127.0.0.1:9022", .project = "rf"});
+    c.connect();
+    // Something to be present, so the absences below are absences inside a
+    // working collection and not just a server with nothing in it.
+    c.insert("things", nlohmann::json{{"k", "v"}}, "t1");
+    c.setAdd("sets", "s1", "alice");
+    c.createCollection("empty_coll");
+    ck(c.get("things", "t1").has_value(), "present: get finds the seeded document");
+    ck(c.setIsMember("sets", "s1", "alice"), "present: setIsMember finds the member");
+
+    for (auto& [name, read] : reads()) {
+        bool empty = false, threw = false;
+        try { empty = read(c); } catch (const std::exception& e) {
+            threw = true;
+            std::cerr << "  " << name << " threw: " << e.what() << "\n";
+        }
+        ck(!threw, "absent: " + name + " does not throw for a genuine absence");
+        ck(empty, "absent: " + name + " reports the absence as empty");
+    }
+    // update() on a missing document still names it NotFound.
+    Client::Failure f;
+    ck(!c.update("things", "nope", nlohmann::json{{"k", 1}}, f), "absent: update of a missing doc is false");
+    ck(f.code == Client::ErrorCode::NotFound, "absent: update of a missing doc says NotFound");
+    return 0;
+}
+
+// Every read must throw Client::Error carrying `want`.
+static void failing(const char* phase, Client::ErrorCode want) {
+    Client c({.address = "127.0.0.1:9022", .timeoutMs = 700, .maxRetries = 0,
+              .writeRetries = 0, .project = "rf"});
+    c.connect();
+    const std::string p = phase;
+    for (auto& [name, read] : reads()) {
+        bool typed = false;
+        Client::ErrorCode got = Client::ErrorCode::Ok;
+        try { (void)read(c); }
+        catch (const Client::Error& e) { typed = true; got = e.code(); }
+        catch (const std::exception&) {}
+        ck(typed, p + ": " + name + " throws Client::Error instead of answering empty");
+        ck(got == want, p + ": " + name + " carries code " + std::to_string(int(want)) +
+                         " (got " + std::to_string(int(got)) + ")");
+    }
+
+    // Writes report through the return value, with the real code.
+    Client::Failure f;
+    bool ok = true, threw = false;
+    try { ok = c.update("things", "t1", nlohmann::json{{"k", 1}}, f); }
+    catch (const std::exception&) { threw = true; }
+    ck(!threw, p + ": update does not throw");
+    ck(!ok, p + ": update returns false");
+    ck(f.code == want, p + ": update reports the real code, not NotFound (got " +
+                       std::to_string(int(f.code)) + ")");
+
+    // The exempt reads keep their documented failure answers.
+    bool h = true; threw = false;
+    try { h = c.healthCheck(); } catch (const std::exception&) { threw = true; }
+    ck(!threw && !h, p + ": healthCheck answers false without throwing");
+    threw = false; std::optional<bool> t = true;
+    try { t = c.tryGetRelationsEnforced("things"); } catch (const std::exception&) { threw = true; }
+    ck(!threw && !t.has_value(), p + ": tryGetRelationsEnforced declines without throwing");
+    threw = false; bool g = false;
+    try { g = c.getRelationsEnforced("things"); } catch (const std::exception&) { threw = true; }
+    ck(!threw && g, p + ": getRelationsEnforced fails toward true without throwing");
+}
+
+int main(int argc, char** argv) {
+    const std::string phase = argc > 1 ? argv[1] : "";
+    if (phase == "absent") absent();
+    else if (phase == "frozen") failing("frozen", Client::ErrorCode::DeadlineExceeded);
+    else if (phase == "down") failing("down", Client::ErrorCode::Unavailable);
+    else { std::cerr << "usage: absent|frozen|down\n"; return 2; }
+    std::cout << phase << ": " << pass << " passed, " << fail << " failed\n";
+    return fail == 0 ? 0 : 1;
+}

+ 76 - 0
tests/load_test/test_read_failures.sh

@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+# v2.12.4 client/server boundary e2e - a read that FAILS must not look like a
+# read that found NOTHING. Three server states: up (genuine absences stay
+# empty), frozen with SIGSTOP (deadline), stopped (unavailable). See
+# test_read_failures.cpp for what each assertion covers.
+
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+cd "$SCRIPT_DIR"
+
+DIR=/tmp/sbdb-read-failures
+PORT=9022
+
+rm -rf "$DIR"
+mkdir -p "$DIR/data"
+
+cat > "$DIR/config.json" <<CFG
+{
+  "storage": {
+    "data_directory": "$DIR/data",
+    "bind_address": "127.0.0.1",
+    "rpc_port": $PORT,
+    "encryption": { "enabled": false },
+    "migrations": { "enabled": false },
+    "replication": { "enabled": false }
+  }
+}
+CFG
+
+echo "=== building test binary ==="
+g++ -std=c++20 -O1 -o "$DIR/t" test_read_failures.cpp \
+    -I"$ROOT/client/include" -I"$ROOT/build/client" \
+    -L"$ROOT/build/client" -lsmartbotic-db-client -lspdlog -lfmt -pthread
+
+SERVER_PID=""
+stop() {
+    [[ -n "$SERVER_PID" ]] || return 0
+    kill -CONT "$SERVER_PID" 2>/dev/null || true
+    kill "$SERVER_PID" 2>/dev/null || true
+    wait "$SERVER_PID" 2>/dev/null || true
+    SERVER_PID=""
+}
+trap stop EXIT
+
+"$ROOT/build/service/smartbotic-database" --config "$DIR/config.json" > "$DIR/server.log" 2>&1 &
+SERVER_PID=$!
+for _ in $(seq 1 60); do
+    grep -q "Notified systemd: READY" "$DIR/server.log" && break
+    sleep 0.5
+done
+grep -q "Notified systemd: READY" "$DIR/server.log" || { tail -30 "$DIR/server.log"; exit 1; }
+
+run() {
+    set +e
+    LD_LIBRARY_PATH="$ROOT/build/client" "$DIR/t" "$1" 2>&1 | grep -v '\[error\]' | tee "$DIR/out-$1.txt"
+    local rc=${PIPESTATUS[0]}
+    set -e
+    [[ $rc -eq 0 ]] || { echo "FAILED in phase $1"; exit $rc; }
+}
+
+echo "=== up: genuine absences ==="
+run absent
+
+echo "=== frozen (SIGSTOP): the blip ==="
+kill -STOP "$SERVER_PID"
+run frozen
+kill -CONT "$SERVER_PID"
+
+echo "=== down ==="
+stop
+run down
+
+echo ""
+echo "OK - read failures e2e passed"

Some files were not shown because too many files changed in this diff