Преглед на файлове

fix(runner): the deadline-bounded startup and the vector-insert guard

These two changes belonged with ef760bd and 11a8fd7 and were left out of
both. My `git add` lines named `src tests api packaging` and never
included `runner/`, so the runner half of each fix sat unstaged while
the server half was committed - and then got swept into a commit I had
labelled "docs", which would have told anyone reading the history that
the runner was never touched.

Nothing shipped wrong: packaging/build.sh builds from the working tree,
so 0.8.2 and 0.8.3 both contain this code, and 884 tests ran against it.
But the repository did not describe the artifact, which is its one job.
Recording it honestly rather than leaving a commit message that says
documentation over a source change.

The content, for the record:
- runner/src/main.cpp: the startup wait bounded by a wall deadline via
  db_await.hpp, matching src/main.cpp. Both binaries had the same
  attempt-count loop and must not drift.
- runner/src/host_context.cpp: `ctx.collections(...).insert()` refuses a
  vectorless document in a vector collection, and `text` does NOT
  satisfy it because .insert() does not embed - only .store() does.
  Same rule as the HTTP route, for the same reason.

The lesson is the one the day kept teaching from other directions: `git
add <paths>` asserts a mechanism (these files are staged) rather than an
outcome (the commit contains the change). `git status` would have shown
it every time and I did not look.
fszontagh преди 1 месец
родител
ревизия
080e3d4fbb
променени са 2 файла, в които са добавени 24 реда и са изтрити 2 реда
  1. 15 1
      runner/src/host_context.cpp
  2. 9 1
      runner/src/main.cpp

+ 15 - 1
runner/src/host_context.cpp

@@ -1177,7 +1177,21 @@ struct HostContext::Impl {
         // expiry to preserve, so "say nothing" and "no expiry" are the same
         // thing - which is also what POST /documents does with the parameter.
         const uint32_t ttl = hostdetail::ttlFrom(payload).value_or(0);
-        meta(collection);
+        // The same refusal POST /documents makes, for the same reason: a
+        // document inserted into a VECTOR collection with no vector reads back
+        // perfectly and can never be found by a search. The two routes are the
+        // same operation and must not drift.
+        //
+        // `text` does not satisfy it here either, and for the identical reason:
+        // .insert() DOES NOT EMBED. Only .store() does. Accepting `text` would
+        // store an invisible row while appearing to permit ordinary ingest.
+        const CollectionMeta& m = meta(collection);
+        if (m.kind == "vector" && !doc.contains("_vector") && !doc.contains("vector"))
+            throw ApiError(ErrCode::Unprocessable, "vector_missing",
+                           "a document inserted into vector collection '" + collection +
+                               "' must carry '_vector', or it can never be found by a search. "
+                               ".insert() does not embed: use .store({text}) to have text embedded, "
+                               "or .store({vector}) to supply one");
         std::string newId;
         try {
             newId = db.client().insert(qualify(config.project, collection), doc, id, ttl,

+ 9 - 1
runner/src/main.cpp

@@ -10,6 +10,7 @@
 // It deliberately holds the only code here that links vectorapi_core and the
 // database client, which is what keeps run_service testable on a host where
 // that client cannot compile at all (CLAUDE.md).
+#include "db_await.hpp"
 #include "db_gateway.hpp"
 #include "errors.hpp"
 #include "function_env.hpp"
@@ -529,7 +530,14 @@ int main(int argc, char** argv) {
 
     svapi::DbGateway db(cfg.dbAddress);
     spdlog::info("connecting to smartbotic-database at {}", cfg.dbAddress);
-    for (int i = 0; i < 30 && !db.connect(); ++i) std::this_thread::sleep_for(std::chrono::seconds(1));
+    // Bounded by WALL TIME, not by an attempt count - see db_await.hpp. 60 s
+    // sits comfortably inside systemd's 90 s TimeoutStartSec, so an unreachable
+    // database produces a clean diagnostic and exit 1 rather than being killed
+    // mid-loop with a misleading "start operation timed out".
+    svapi::awaitConnectable([&db] { return db.connect(); },
+                            [] { return std::chrono::steady_clock::now(); },
+                            [](std::chrono::milliseconds d) { std::this_thread::sleep_for(d); },
+                            std::chrono::seconds(60), std::chrono::seconds(1));
     if (!db.healthy()) { spdlog::error("database not reachable at {}", cfg.dbAddress); return 1; }
 
     svapi::FunctionRegistry registry(db);