|
|
@@ -128,6 +128,13 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
|
|
|
- **A refused call is NOT written to the run log**, which is a security decision rather than an oversight: the run log lives in the database, so logging refusals would let an unauthenticated caller append a row per request and turn a public URL into a write amplifier against the tenant's own storage.
|
|
|
**What it still does NOT do, stated because the limit is easy to overread:** the ceiling is per FUNCTION, not per caller, so it bounds the DAMAGE - mail sent, paid API spend - and not the denial. One abusive caller can still exhaust a public function's minute. Per-caller throttling needs an identity, which is exactly what `auth: 'key'` provides and an anonymous request does not have.
|
|
|
**And a test-writing trap met while proving it, worth more than the feature:** the first throttle test set `incoming.policy` on the record it pushed and the limit silently did not apply, because `mergeForCodePush` takes the policy from the STORED row and never reads the one in the push - the "a code push can never widen access" invariant, working exactly as written. The test therefore "disproved" a throttle that worked. A first registration inherits the `projectDefault` argument, so that is where a test's policy has to go. The same test was also **flaky on the real clock**, because the limiter buckets by `now / 60` and two requests straddling a minute boundary land in different windows; it now freezes the clock, since a test that fails once an hour teaches people to re-run rather than to read.
|
|
|
+- **THE RATE LIMIT IS PER KEY, IN A FIXED WINDOW, AND A REFUSAL COSTS NOTHING - NONE OF WHICH A CONSUMER CAN LEARN BY READING.** Asked by novitax 2026-10-22 while chasing 429s, and every part of the answer had to come out of `rate_limiter.cpp` because none of it was written down anywhere a caller can see.
|
|
|
+ - **Keyed on the KEY id** (`allow(p.id, ...)`), not the project and not the source IP. So two callers share a bucket only if they present the same key - which is the question that was actually being asked, because a reviewer refreshing and a batch script are the same project and different keys. A `rate_limit_per_min` of **0 means UNLIMITED**, not "no requests", so moving batch work onto an unlimited key needs no change on our side.
|
|
|
+ - **A FIXED window** (`now / 60`), not sliding. A burst spends the whole allowance at once and then every remaining call in that wall-clock minute is refused, rather than draining smoothly - measured in their log as **seven 200s and then four 429s inside one second**, and 36 refusals in one minute. It also means a burst straddling a boundary can land 2x the limit in a rolling 60 s.
|
|
|
+ - **A refused request does NOT charge the bucket**: `allow()` increments only on the admitting path. So a client retrying a 429 is not digging its own counter deeper, which is the opposite of what a caller reasonably assumes and is the half of the answer that changes their tuning. Measured cost of a refusal: `urt=0.001`, i.e. refused before any database work.
|
|
|
+ - **But retries DO compound the latency**, because prod is a single vCPU - so the honest answer is "your backoff need not be aggressive to protect the limit, and your concurrency is what is hurting you". Their one page load put 126 requests into a single minute.
|
|
|
+ **The listing route is the deliberate exception and stays so:** it charges the limiter ONCE for the whole request rather than once per collection examined, because fifty collections would otherwise spend fifty tokens and rate-limit a caller for one request.
|
|
|
+
|
|
|
- **A write is validated on a runner before storage**, so the engine that validates is the engine that executes; with no healthy runner the write is refused **503** rather than stored unchecked.
|
|
|
- **`RunnerPool` retry is three-way, not two.** Never connected → retry (nothing ran). Answered, whatever the answer → never retry (the runner did its job). **Delivered then unanswered** (read timeout, non-200, unparseable body) → **do not retry**, mark unhealthy: the handler may be running right now, and a retry would run a side-effecting function twice. `validate()` retries everything, because compiling has no side effects. Also: `RunnerPool::Options::readTimeoutSec` **must exceed** the runner's `max_wall_time_ms`, or our read times out before the runner can report its own timeout and the caller gets a misleading 503 instead of a 504.
|
|
|
- **`ctx.collections(...)` is a direct gateway call, never loopback HTTP**, and `ctx.fetch` pins the connection to the single address the guard approved (`set_hostname_addr_map`) rather than re-resolving - re-resolving IS the rebinding window. One resolution, one classification.
|
|
|
@@ -280,6 +287,20 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
|
|
|
**GREPPING AN OOM LINE FOR A SERVICE NAME MISREADS IT, AND THE MISREADING IS THE FLATTERING ONE FOR WHOEVER IS GREPPING. `cpuset=` NAMES THE CGROUP THAT TRIGGERED THE ALLOCATION; `task=` AND `task_memcg=` NAME THE VICTIM.** Five kernel lines on 2026-10-19 read `cpuset=smartbotic-vectorapi.service ... task_memcg=/system.slice/smartbotic-database.service, task=smartbotic-data`, so a grep for our own service name matched them and they look exactly like vectorapi being OOM-killed. It never was: ours asked for memory, that request tripped the GLOBAL OOM killer, and the kernel chose the database as the victim because it was the largest. `NRestarts=0` on all three of our units is the control, against 183 on the database from the same command. Under global memory pressure the process that triggers a kill and the process that dies are routinely different, which also means **a service can be a repeated CAUSE of another service's death while its own logs stay perfectly clean** - worth knowing before taking "my service shows nothing wrong" as exculpatory. Read `task=`.
|
|
|
**vectorapi itself came through untouched**, up since 2026-10-15 15:56 (the supervised restart after the client library moved) and the runner since 2026-10-13, and it answered **1664 requests with 503** during the permanent phase - correctly classified, naming the real condition, which is the error-slug work doing its job under the one condition nobody arranges deliberately.
|
|
|
**The pre-flight rule that follows: a headroom measurement needs a RE-MEASUREMENT TRIGGER, not just a date.** "The snapshot survives hourly" was true, dated, and silently became false through ordinary growth - no deploy, no config change, nothing to review. Tie it to a quantity that moves: snapshot file size against free memory, or doc count against the figure the headroom was measured at. A dated measurement with no trigger is a claim that will be believed long after it stops being true, which is precisely the failure this file's maintenance rule exists to prevent - and here the stale claim was MINE, in this file, and it read as reassuring right up to the outage.
|
|
|
+ **RE-MEASURED 2026-10-22, AND THE TRIGGER THIS FILE ASKED FOR HAS FIRED: PROD IS NOW SURVIVING ITS HOURLY SNAPSHOT ONLY BECAUSE OF THE SWAPFILE, AND THE MARGIN ABOVE THE BOX IS GONE RATHER THAN THIN.** The entry above demanded a re-measurement trigger tied to a quantity that moves instead of a date. Here is that quantity, moved:
|
|
|
+
|
|
|
+ | | 2026-10-19 (the outage) | 2026-10-22 |
|
|
|
+ |---|---|---|
|
|
|
+ | documents | 65,030 at recovery | **94,805** |
|
|
|
+ | serialised snapshot | ~370-399 MB | **685 MB** |
|
|
|
+ | process `VmHWM` | ~1514 MB at the kill point | **1794 MB** |
|
|
|
+ | cgroup `memory.peak` | - | **1860 MB** |
|
|
|
+ | swap in use by the database | 847 MB | **863 MB** |
|
|
|
+
|
|
|
+ Box is **1973 MB** and other services take ~264 MB, so the peak now EXCEEDS what the box could give it: the process holds 871 MB resident plus 863 MB paged out, i.e. ~1.73 GB of anonymous demand, and without the 4 GB swapfile it would be dead every hour. Doc count grew **42% in three days** (the step came 19th to 20th, +21,035 in one day - a consumer backfill - while the last four hours moved the snapshot only 88 KB, so this is step-change growth, not a smooth ramp, which is the harder kind to leave a margin for).
|
|
|
+ **The healthy signals are genuinely healthy and must not be read as "fine", because they are the output of the swapfile doing its job:** snapshots complete hourly in ~9 s, 14 of them that day, **the WAL directory is EMPTY** - which is the exact inverse of the Oct 17-19 state where nothing completed so nothing truncated - zero OOM kills since Oct 20, `NRestarts=0`, and `si=0 so=0`, so the swapped pages are the cold boot transient rather than working set being thrashed. Everything works. It works with no headroom.
|
|
|
+ **So the 2.20.1 window moved from "the structural fix for a solved outage" to "the thing standing between us and the same outage at the next step-change", and the distinction this file already draws decides what it buys:** streaming the snapshot writer removes the hourly peak and therefore prevents phase 1 and the WAL growth that made phase 2 unsurvivable - but **boot still holds the whole dataset in memory, which 2.20.1 does NOT fix**, and the dataset is now 42% larger than the one that could not boot on 2026-10-19. The swapfile is what covers that today. Quote both halves when asking for the window.
|
|
|
+
|
|
|
- **A SECOND RESTART IS NOT NEEDED ON 2.17.2, measured rather than reasoned.** Our `KeyStore`/`SettingsStore` bootstraps DO perform the online upgrade after the migration, and the log says so - but with **0 rows and 0 history versions rewritten**, because the collections are already ciphertext through the bare-alias merge. `encryption-verify` then reports `sealed: yes`, `CLEAN`, exit 0. So the window is TWO steps and ONE compaction (upgrade, then start vectorapi), with verify as the branch: plain `CLEAN` means done, `CLEAN (UNSEALED: ...)` means take the reseal inside the window. On 2.17.1 that same flag move requested a reseal that compacted every project, which is where the obsolete three-step plan came from.
|
|
|
Note the upstream log line still says "old plaintext copies are removed at the next restart" even when it rewrote NOTHING, which contradicts verify's `sealed: yes` and would have an operator restart for no reason. Trust verify.
|
|
|
- **MOVING THE CLIENT PACKAGE UNDER AN EXISTING BINARY IS AN ABI QUESTION, AND IT IS CHEAP TO TEST.** Every 2.x client shares one SONAME, so apt will happily put a 2.17.2 `libsmartbotic-db-client.so.2` under a server binary compiled against 2.14.0 headers - and the documented failure mode is that it installs fine and segfaults later. Verified before deploying rather than hoped: a Debian 13 container holding the real `smartbotic-vectorapi 0.12.0-1` deb plus `libsmartbotic-db-client 2.17.2-1`, against a 2.17.2 server, answered **21 of 21 calls** correctly - including `POST /indexes` with `unique`, which exercises `CreateIndexResult`, the by-value struct whose SIZE is the thing that would break, and a 409 duplicate refusal, which proves `duplicateExamples` crossed the boundary intact. `/api/v1/version` reported `db_client: 2.17.2` so the new library really was loaded. Repeat this whenever `DB_CLIENT_VERSION` and the deployed client diverge; it takes minutes and the alternative is a restart days later.
|
|
|
@@ -309,6 +330,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
|
|
|
**The one way this switch bites: a wrong base returns HTML, not JSON.** Outside `/api/` the new host answers nginx's own branded 404 page, so a base string that still contains `/rag` gives the caller `text/html` and a JSON parse failure rather than our `{"error":{...}}` envelope. On the old host everything under `/rag/` reaches vectorapi, so a bad path there still returns JSON. The failure therefore does not name its own cause, and it lands at CONFIG time - which is why the advice to a consumer is to test one real write against the new base before flipping prod, and never to flip it the day before a go-live.
|
|
|
**THE ACCESS LOG NOW CARRIES TIMING, AND IT IS `combined` PLUS THREE APPENDED FIELDS RATHER THAN A NEW SHAPE.** Done 2026-10-16 (task #84), after a consumer's latency question turned out to be unanswerable retrospectively: the built-in `combined` format records no time at all, so "was it slow yesterday" had no evidence in either direction. `/etc/nginx/conf.d/log-format-timing.conf` defines `log_format timing` as combined plus `host=$host rt=$request_time urt=$upstream_response_time`, and the two API server blocks set `access_log ... timing`. Appended, never reshaped, so anything parsing the combined prefix keeps working - the same additive discipline as `details.unsupported`.
|
|
|
**`host=` is the field that is easy to leave out and then need**: prod serves two hostnames with different surfaces, so without it a line cannot be attributed to either. And **the GAP between `rt` and `urt` is usually the answer**, because it is the part a consumer cannot see from their own side: a slow client or a large body rather than a slow backend. `urt` is `-` when nothing was proxied, which is correct rather than zero.
|
|
|
+ **AND THE ACCESS LOG IS NOT ROTATED - IT RUNS BACK TO 2025-11-24, SO ANY "BY HOUR" AGGREGATE OVER IT IS ELEVEN MONTHS BUCKETED BY HOUR-OF-DAY.** Met 2026-10-22: asked how a consumer's 429s were distributed, I grouped by the hour field and produced a clean, plausible histogram peaking at 09:00 with 305 refusals. It was every 09:00 since November. Scoped to the actual day the answer was **44**. The artefact is convincing precisely because the shape looks like a working day. Scope the date first (`grep 22/Oct`), and check `head -1` for the log's real start before quoting any total as "today".
|
|
|
+ **Two more traps in the same file, both of which produced wrong numbers before anything caught them.** `grep " 503 "` matches the BODY-SIZE field as well as the status, so it counts `200 503` lines as failures - it reported 1685 where `awk '$9==503'` reports 1. And a request count is not a concurrency measurement: 126 requests in a minute is what explained a timeout here, while the same count spread evenly would have explained nothing, so read the per-second clustering rather than the per-minute total.
|
|
|
+
|
|
|
**It went in `conf.d` and in the SITE files, never in `nginx.conf`, which is an nginx-common CONFFILE** - `dpkg -S` first, per the trap above. `conf.d` is included at line 60 and `sites-enabled` at 61, so a format defined there is visible to the site files. A second `access_log` at the http level would have DOUBLE-logged every request rather than replacing the default, which is why it is set per server block.
|
|
|
**The qdrant site file has three identical `server_name` lines**, so the edit was placed by LINE NUMBER and then asserted by printing the surrounding lines - the scripted-edit-landed-in-the-wrong-handler trap, in config form.
|
|
|
**And a reload does NOT re-format existing keepalive connections, which looks exactly like a config that did not take.** Measured: immediately after the reload, requests from an external `node` client with persistent connections were still logged in the OLD format while fresh requests carried the new fields, because old workers keep serving established connections. The cut-over was visible at a single second and resolved in about five. So verify a log-format change on a NEW connection, and do not read a few old-format lines after a reload as failure.
|
|
|
@@ -326,6 +350,16 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
|
|
|
**The UNIFORMITY is the finding, and it refutes the per-collection reading.** `justice-pa` and `creditforte` share no collection with novitax, and the 2.17.2 history lock is per-collection, so contention there cannot explain it. `nproc` is **1**. cpp-httplib's default pool is `max(8u, hardware_concurrency - 1)`, so vectorapi runs **8 request threads on one core** (max 32) - concurrency without parallelism, where 8 busy threads each take about 8x longer. The measured 5.6-9.5x lands on that number, which is why this is corroboration rather than a coincidence.
|
|
|
**So "can one tenant's load block the server" has a two-part answer worth giving precisely: it DEGRADES everyone proportionally and it did not BLOCK anyone.** Every other tenant stayed under 250 ms, which no caller would notice. The blocking regime is further out and is reached through the thread pool rather than the core: once 8 (then 32) concurrent requests are queued, new connections wait, and the ceiling becomes nginx's `proxy_read_timeout 180s` on our side rather than anything the database reports. **The thing to measure before promising a tenant a throughput is therefore CONCURRENCY, not request rate** - 6 writes a second cost nothing on its own, and 6 concurrent slow requests cost everyone a factor of 8.
|
|
|
Note what this also means for any latency number in this file: a p50 taken while the box is quiet is not a property of the service, and the single core makes every measurement here sensitive to what else is running. The provider round trip dominates a vector search, so search latency hides this; a pure DB read at 8-35 ms does not.
|
|
|
+- **THE COLLECTIONS LISTING COSTS 2 gRPC ROUND TRIPS PER COLLECTION, WHICH MAKES IT ~200x AN ORDINARY READ AND THE FIRST ROUTE TO TIME OUT UNDER LOAD.** Measured on prod 2026-10-22 diagnosing a consumer's single 503. `handlers/collections.cpp` enriches every row inside the loop with `count(qc)` plus `getCollectionInfo(qc)`, so N collections cost **2N sequential calls** - 22 of them for novitax's 11 collections, for what a caller reasonably reads as a cheap inventory call.
|
|
|
+
|
|
|
+ | call | time, idle box |
|
|
|
+ |---|---|
|
|
|
+ | collections listing (11 collections) | 0.428 / 0.409 / 0.492 s |
|
|
|
+ | **control: one document listing, no fan-out** | **0.002 s** |
|
|
|
+
|
|
|
+ **The control is what makes this a measurement rather than "that route feels slow"** - it removes the per-collection fan-out and nothing else, and the gap is three orders of magnitude. On a SINGLE vCPU, under the consumer's own 126-requests-in-a-minute burst, that 0.43 s stretches past the client deadline: their only 503 of the day was `GET .../collections` at `rt=9.693`, and the journal names the call - `Client::getCollectionInfo failed: Deadline Exceeded`.
|
|
|
+ **The diagnosis that this is NOT the database needed four controls, because "the database is slow today" is the reading every signal superficially supports:** snapshots completed hourly (14 that day), zero OOM kills since Oct 20, `NRestarts=0`, the database's own minute line reading `pressure=normal, 0 evicted` on both sides of the failure, and the consumer's own p50 at **0.049 s over 2014 requests**. A consumer about to retune their pagination against a database that was fine would have been fixing the wrong layer, which is exactly what they asked us to rule out first.
|
|
|
+ **It is the same shape as the rate-limiter decision one layer down, and worth noticing that we got it right there and not here:** that route deliberately charges the limiter ONCE because "one request is one request", and then fans out 22 round trips for the same single request. Tracked as SV-16; no fix shipped, because making the stats opt-in changes the response shape and caching them makes an exact `document_count` stale, and this file already records an exact count finding a real data defect (13093 against 13092).
|
|
|
- **Prod's database binds `localhost`, not `0.0.0.0`** (`storage.bind_address`), which is why it is only reachable from vectorapi on the same box - correct, and worth knowing before wondering why a port-mapped copy refuses connections.
|
|
|
- **`policy-rc.d` DOES NOT HOLD THE DATABASE PACKAGE. It blocks `invoke-rc.d`, and that postinst calls `systemctl` DIRECTLY.** Measured the hard way on 2026-10-12: a `policy-rc.d` returning 101 was in place, the pinned install ran at 18:21:12, and the service restarted anyway - the 2.17.2 first-boot migration ran to completion before the install command had even returned. **A hold point three consumers had been promised simply did not exist**, and that cost TWO separate things, not one. One consumer lost the chance to say "wait, a call is live" that they had explicitly been offered. **And because the install itself triggered the migration, the outage happened at 18:21 rather than in the 18:30 slot all three had approved** - it ran NINE MINUTES EARLY, outside the approved window, which is a governance failure distinct from the missing check. A consumer put that second point in the record; my own account had blurred it into the first, which understated it.
|
|
|
**The error was verifying the mechanism's PURPOSE instead of its EFFECT.** `policy-rc.d` genuinely is the standard Debian way to prevent a maintainer script starting a service; it is just not effective against a script that bypasses `invoke-rc.d`. Checking that it is the right tool is not the same as checking that it works here, and one `systemctl show -p ActiveEnterTimestamp` before the install - or one `grep systemctl` over the postinst - would have shown it. **A control nobody has seen fire is not a control.** If a window needs a pause, REHEARSE THE PAUSE, not just the migration: install on a scratch box and confirm the service did NOT start. The consumer's framing is the one to keep - they asked for a pause and then treated it as load-bearing without either of us testing that it pauses.
|