Ver Fonte

fix: a project with no functions is a normal state, not a warning every 20s

Found by creating one. The function registry collection is made by the first
function PUSH, not at project creation - project-create materialises the
COLLECTION registry, a different collection. So every project that has never
had a function pushed made FunctionRegistry::list throw, and BOTH the scheduler
and the event watcher logged a warning for it on every tick: one line per
project per 20 s, 4,320 a day for a single such project.

That is worse than untidy, and it is the mirror of the failure this repo keeps
recording. Most entries here are about a failure nothing reports; a warning that
fires constantly for a benign condition teaches whoever reads the journal to
skip the line, so the next genuine "could not read registry" - a transport
failure, or a registry that really has gone missing on a project that DOES have
functions - arrives looking exactly like the noise.

Classified on the CODE, never the message text: NotFound means the collection is
absent, so the project has no functions and an empty vector is the honest
answer. Unavailable, a permission denial or a malformed row still propagate, so
a real fault stays as loud as it was. 1349/1349 pass.

Prod was fixed at the data layer in the meantime - every one of the seven
projects now has the collection, verified, and registry warnings are at zero.
That handles today's instances without a release; this handles the recurrence,
including projects created by any route other than ours.

Also adds /fn/ to the customer-facing nginx host and syncs the live file back
into packaging/nginx so prod and git cannot drift. Deliberately done AFTER
0.16.0 was deployed rather than before: until then /fn was unauthenticated AND
unthrottled on prod, and adding the location would have duplicated an unbounded
surface onto the one hostname kept narrow on purpose.

Verified with the control that discriminates, since both nginx and the app can
answer 404: a nonexistent function under /fn/ now returns 404 **application/
json** (the app answered, so it is proxied) while /docs still returns 404
**text/html** (nginx answered, so the whitelist is intact). With a key, through
the new host, end to end: 200 in 78 ms. The old /rag/ mount, /api/, /healthz
and qdrant on :6333 all unaffected.
fszontagh há 1 mês atrás
pai
commit
5c0ae58d1b

+ 25 - 0
packaging/nginx/global-api-01.smartbotics.ai.conf

@@ -24,6 +24,7 @@
 # this hostname and would fail verification in every client.
 server {
     server_name global-api-01.smartbotics.ai;
+    access_log /var/log/nginx/access.log timing;
 
     # Branded error pages for the errors nginx itself raises. See the snippet:
     # proxied responses keep their JSON envelope, which must not change.
@@ -52,6 +53,30 @@ server {
     # page and its asset, /openapi.json and /llms.txt. All of it stays
     # reachable on the old name under /rag/, which is where we read it.
     # 404 rather than 403: a 403 would confirm something is there.
+    # Published HTTP functions, served to the world at /fn/{project}/*.
+    #
+    # Added 2026-10-22, deliberately AFTER vectorapi 0.16.0 was deployed and not
+    # before. This route is unauthenticated BY DESIGN - a published function is
+    # published - and until 0.16.0 it was also UNTHROTTLED, because the limiter
+    # charge and `auth: 'key'` only landed in 0.15.0, which was never published.
+    # Measured on prod before the upgrade: an anonymous POST with no credential
+    # answered 200 in 0.106s. Adding this location then would have duplicated an
+    # unbounded surface onto the one hostname kept narrow on purpose.
+    #
+    # It is defensible now because the function's `rate_limit_per_min` is charged
+    # on the CALL as well as on its data access, and a descriptor may declare
+    # `auth: 'key'` to require a key per caller - verified live: anonymous 401
+    # against 200 with a key.
+    #
+    # NO trailing slash on proxy_pass, so /fn/... reaches vectorapi unchanged.
+    # The /rag/ mount on the old hostname DOES strip its prefix; the two are
+    # different on purpose. The shared snippet carries the timeouts and body
+    # limit so this location cannot drift from /api/.
+    location /fn/ {
+        proxy_pass http://127.0.0.1:8080;
+        include /etc/nginx/snippets/vectorapi-proxy.conf;
+    }
+
     location / {
         return 404;
     }

+ 31 - 2
src/function_registry.cpp

@@ -29,8 +29,37 @@ std::vector<FunctionRecord> FunctionRegistry::list(const std::string& project) {
     std::vector<FunctionRecord> out;
     smartbotic::database::Client::QueryOptions opts;
     opts.limit = 100000;
-    for (const auto& doc : db_.client().find(coll(project), opts))
-        out.push_back(FunctionRecord::fromJson(doc));
+    try {
+        for (const auto& doc : db_.client().find(coll(project), opts))
+            out.push_back(FunctionRecord::fromJson(doc));
+    } catch (const smartbotic::database::Client::Error& e) {
+        // A PROJECT WITH NO FUNCTIONS HAS NO REGISTRY COLLECTION, AND THAT IS A
+        // NORMAL STATE RATHER THAN A FAILURE.
+        //
+        // The collection is created by the first function PUSH (`ensure` in
+        // `put`), not when the project is created - project-create materialises
+        // the COLLECTION registry, which is a different collection. So every
+        // project that has never had a function pushed made this throw, and the
+        // scheduler and the event watcher each logged a warning for it on EVERY
+        // tick: one line per project per 20 s, 4,320 a day for a single such
+        // project. Found 2026-10-22 by creating one.
+        //
+        // That is worse than untidy. This file is full of warnings about a
+        // failure nothing reports; the mirror is a warning that fires constantly
+        // for a benign condition, because it teaches whoever reads the journal
+        // to skip the line - and the next genuine "could not read registry",
+        // from a transport failure or a registry that really has gone missing
+        // on a project that DOES have functions, arrives looking exactly like
+        // the noise.
+        //
+        // Classified on the CODE, never on the message text, which is the rule
+        // everywhere else here: NotFound means the collection is absent, so the
+        // project has no functions and the empty vector is the honest answer.
+        // Anything else - Unavailable, a permission denial, a malformed row -
+        // still propagates, so a real fault is as loud as it ever was.
+        if (e.code() == smartbotic::database::Client::ErrorCode::NotFound) return out;
+        throw;
+    }
     return out;
 }