Sfoglia il codice sorgente

docs: the client pin ALREADY moved - encrypted_field is live on prod, measured

Our notes said in several places that we ship client 2.14.0 and that
read-path slugs stay dormant until DB_CLIENT_VERSION moves. The pin moved
2.14.0 -> 2.17.2 in commit 9534794, which IS the 0.13.0 bump, confirmed by
the debs: 0.12.0-1 depends on >= 2.14.0, 0.13.0-1 and 0.15.0-1 on >= 2.17.2.

Measured on prod (0.13.0 against server 2.17.2): filtering password, token
or api_key answers encrypted_field with details.field, while the control
nosuchfield answers 200 - selective, not blanket. So the slug is live.

Two corrections follow: message_too_large should also be live on reads via
the same reason-carrying path, and invalid_pattern is blocked on the SERVER
(2.20.0) rather than on the client, which was already satisfied. Also drops
the long-stale '2.17.2 is NOT released' line.
fszontagh 1 mese fa
parent
commit
97059459f2
1 ha cambiato i file con 4 aggiunte e 2 eliminazioni
  1. 4 2
      CLAUDE.md

+ 4 - 2
CLAUDE.md

@@ -323,7 +323,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **Client ABI pin:** the server deb is compiled against `DB_CLIENT_VERSION` (`packaging/Dockerfile.base`). Every 2.x client shares one SONAME, so a deb built against a newer client installs fine and only segfaults on the next restart - keep the pin equal to the deploy target, and ship a DB upgrade and a vectorapi rebuild together.
 - **The apt repo now indexes EVERY published version, so a rollback is an ordinary apt command.** It used to list only the newest, which made `pkg=<old version>` uninstallable the moment anything newer was published - and that was never retention, only indexing: `dpkg-scanpackages` emits one version per package unless given `-m`, while the pool had kept every `.deb` all along (a publish reported "3 added, 309 unchanged"). Fixed 2026-10-08 in the deb-repo tooling; the trixie index went from 33 stanzas to 1191. **A downgrade needs `--allow-downgrades`** (`apt-get install --allow-downgrades pkg=0.7.1-1 ...`), and downgrade the three app packages TOGETHER or apt resolves a split version set. A plain `apt install pkg` still picks the newest, so ordinary installs are unaffected. The backup step still stages the installed `.deb`s out of `/var/cache/apt/archives/`, which stays the right belt-and-braces for a rollback when the repo itself is unreachable.
 - **"The dev host cannot build the C++" was a misdiagnosis - it was a stale `protoc`.** The host builds everything natively; use `scripts/host-build.sh`. The old symptom was real: generated protos wanted `google/protobuf/map_field_inl.h`, a header protobuf 35 removed. But nothing in the database's tree includes that header - an **old protoc emits the include**. The host had libprotobuf 35.1 and gRPC 1.83 from the distro, and a hand-dropped static **protoc 25.2 in `~/.local/bin`** shadowing everything, while the distro's compiler package (`protobuf-35.1`, separate from `protobuf-devel`, which ships no protoc) was never installed. `find_program(PROTOC protoc REQUIRED)` took the 25.2 binary from PATH, generated code for a protobuf 25 runtime and compiled it against 35 headers. With a matching protoc the client and all of vectorapi compile and link natively. `host-build.sh` therefore picks protoc **by version rather than PATH order** and refuses to run on a mismatch, because the failure otherwise surfaces as a missing header deep in generated code rather than as a version complaint.
-- **DO NOT SET `encrypted=true` ON A COLLECTION THAT STILL RECEIVES VECTORS. On database 2.17.0 and 2.17.1 as released, an encrypted collection REFUSES every new insert carrying a vector**, failing with `Invalid JSON: type must be number, but is string` - the handler encrypts the whole body, `_vector` included, before the store extracts the vector. So an encrypted RAG collection is FROZEN for new embeddings. Not silent loss, since the write is refused, but broken. Fixed on their `main` as 2.17.2 (`_vector` is never encrypted, everything else still is); **2.17.2 is NOT released and is not in apt**, so the constraint stands for anything we can actually deploy.
+- **DO NOT SET `encrypted=true` ON A COLLECTION THAT STILL RECEIVES VECTORS. On database 2.17.0 and 2.17.1 as released, an encrypted collection REFUSES every new insert carrying a vector**, failing with `Invalid JSON: type must be number, but is string` - the handler encrypts the whole body, `_vector` included, before the store extracts the vector. So an encrypted RAG collection is FROZEN for new embeddings. Not silent loss, since the write is refused, but broken. Fixed as 2.17.2 (`_vector` is never encrypted, everything else still is). **That sentence used to read "2.17.2 is NOT released and is not in apt", which is long stale: 2.17.2 was released, is in apt and has been PROD's server since 2026-10-12** - so the vector-insert freeze is fixed on the deployed server, not only on their main. What remains true regardless, and is usually the decisive cost, is the FILTER consequence in the paragraphs below.
   **MY OWN MEASUREMENT MISSED THIS, AND THE WAY IT MISSED IT IS THE POINT.** I tested a populated collection flipped to `encrypted=true` and verified: every row still its own nearest neighbour at 1.0 before, after and across the seal restart; the export BYTE-IDENTICAL with the same `content_sha256`; and a re-import retrieving correctly at 1.000000 with a fixed `query_vector` scoring identically to eight decimals. All of that is true and still holds - vectors stored BEFORE the flip live in the vector sub-db rather than the body, so they are untouched. **What I never did was insert a NEW row after the flip**, and my re-import went into a fresh collection which our own route creates `encrypted=false`, so it could not have caught it either. I then wrote "safe for search and for backup", which was broader than what I had measured. Same shape as everything else in this file: a check that answers a narrower question than the one being asked, committed by the person who had spent the day pointing that out to others. **When testing whether a state change is safe, test WRITES INTO the new state, not only reads of what was there before it.**
   **What this does NOT affect:** our three credential collections are not vector collections, so encrypting them is unaffected; and `handlers/collections.cpp` creates every user collection `encrypted=false`, so a tenant cannot reach this unless someone deliberately flips one.
   **The cost that remains true either way, and is usually decisive: FILTERS.** A filter on an encrypted field is refused outright ("its stored form is ciphertext, so any comparison would be silently wrong"), so encrypting a collection trades every filter, sort, index and unique constraint on it. For a consumer that was decisive on three grounds without needing the write freeze: it removes the retrieval model on one collection, and on another it would silently convert a UNIQUE INDEX underpinning retry idempotency into a duplicate-write hazard.
@@ -331,7 +331,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **`encrypted_field` (422) is its own slug, not `validation`.** Database 2.17.0 encrypts any field named `password`, `secret`, `token`, `api_key`, `apiKey` or `credentials` at ANY depth in EVERY collection, and then REFUSES a filter, sort, index, unique constraint, relation or increment on one. It needs its own slug because the remedy is unlike every other validation failure: the request is well formed, the field name is correct, and no correction of the body helps - the caller must stop querying that field, storing a non-sensitive duplicate (a hash, or a boolean "set") or renaming it if it was never a credential. Folding it into `validation` would send them hunting a typo. Note what it REPLACES is worse than itself: before 2.17.0 a top-level field of those names was plaintext and filterable, and a NESTED one compared ciphertext and **silently matched nothing** - so the refusal turns a silently empty result into a visible error. **Our `/documents` filter grammar, `?sort=` and the index route all accept ANY field name with no validation, so a TENANT can trigger this; we cannot.** Our own tests use `password` only as a `ctx.mail` option key, never as a stored field being queried.
   **MOVING THE CLIENT PIN WIDENS THE OBSERVABLE SLUG SET ON EVERY READ ROUTE, AND IN ONE CASE IT FIXES A RETRY-FOREVER BUG.** `translate()` branches on NINE server reasons - `delete_restricted`, `document_too_large`, `duplicate_id`, `encrypted_field`, `memory_pressure`, `message_too_large`, `missing_parent`, `outcome_unknown`, `read_only` - and forwarding the reason on READ calls (`find`, a filtered search) is a 2.17.0 CLIENT change, so on anything older every one of those collapses on a read into whatever the bare code maps to. **The important instance: `ResourceExhausted` with no reason falls through to 429 `rate_limited`, which says WAIT AND RETRY. A document grown too large to read back (repeated patches, measured) is exactly that case, and no amount of waiting fixes it.** With the reason it becomes 422 `message_too_large`, which is permanent and honest. So the pin move does not merely add `encrypted_field`: it corrects a read failure that is currently reported as retryable when nothing can ever succeed.
   **Tell consumers the GENERAL form before the pin moves, not the one slug.** A consumer with an exhaustive code map plus a default branch starts meeting codes it has never seen, and the dangerous default is not "unknown error" but "retry" - a caller that retries its default would begin retrying a permanent verdict. The consumer who raised this is inert by construction (their retryable set is keyed on STATUS, not on code, which is the design that makes a widening slug set safe), and that is the right question to ask each consumer: not "do you handle this slug" but **"what does your default branch do, and is your retry decision keyed on status or on code"**. Filing this as "additive, becomes live" understates it in the asymmetric direction - the same understatement I made about `filter_mode`, where being wrong cost an opportunity rather than a retry loop.
-  **IT IS DORMANT UNTIL THE CLIENT MOVES TO 2.17.x, AND I TOLD A CONSUMER IT WAS LIVE.** Measured against a 2.17.1 server with our shipped 2.14.0 client: a filter on an encrypted field comes back as slug **`validation`**, not `encrypted_field`, even though the server's message arrives intact. The reason is the client, not our mapping - carrying the server's error reason on READ calls (`find`, `similaritySearch`) is a 2.17.0 client change, so on 2.14.0 the reason is simply absent and `translate()` falls through to `validation`. So the slug shipped in 0.12.0 cannot fire on prod today. It starts working when `DB_CLIENT_VERSION` moves, which is the same dependency as the index-route mapping, and it covers the FILTER path too rather than only indexes.
+  **IT WAS DORMANT UNDER THE 2.14.0 CLIENT AND IT IS LIVE ON PROD NOW - THE CLAIM BELOW WAS RIGHT WHEN MEASURED AND THE WORLD MOVED, SO READ THE CORRECTION FIRST.** Measured on prod 2026-10-22, vectorapi 0.13.0 against server 2.17.2: `?filter=password:eq:x` answers **`encrypted_field`** with `details.field`, and so do `token` and `api_key`, while the control `nosuchfield:eq:x` answers **200** - so the refusal is selective and genuinely firing rather than a blanket failure. **The reason it works is that `DB_CLIENT_VERSION` ALREADY MOVED, and this file said otherwise in several places.** The pin went 2.14.0 -> 2.17.2 in commit `9534794`, which IS the 0.13.0 version bump (2026-10-13), confirmed independently by the built debs: `0.12.0-1` declares `Depends: libsmartbotic-db-client (>= 2.14.0)` and `0.13.0-1` and `0.15.0-1` declare `>= 2.17.2`. **So "we ship 2.14.0" is true of 0.12.0 and FALSE of everything prod has run since 2026-10-13.** Anywhere this file still says we ship 2.14.0, or that a read-path slug is dormant until the pin moves, is stale for the same reason.
+  **Two consequences, and the second is the one that was costing us.** `message_too_large` on a READ should likewise be live now, because the same mechanism carries it - `apiErrorFor(Client::Error)` extracts `errorDetail(e)` and passes `d->reason`, and `encrypted_field` arriving proves the reason does reach `translate()` on a read path (that is an inference from the proven mechanism, not a separate measurement - triggering it needs a document too large to read back). And **`invalid_pattern` is blocked on the SERVER, not on the client**: it is a 2.20.0 server reason, prod runs 2.17.2, and the client side of the dependency is already satisfied. This file previously filed both under one "pin move" dependency, which is wrong in opposite directions - one is already done, the other never needed the client at all.
+  **What the original measurement said, kept because the mechanism is still the thing to understand:** against a 2.17.1 server with a 2.14.0 client, a filter on an encrypted field came back as slug `validation`, not `encrypted_field`, even though the server's message arrived intact. The cause was the client, not our mapping - carrying the server's error reason on READ calls (`find`, `similaritySearch`) is a 2.17.0 client change, so on 2.14.0 the reason was simply absent and `translate()` fell through to `validation`.
 - **DONE 2026-10-15: THE OPERATIONAL COLLECTIONS ARE CAPPED, 316 MB OF HISTORY DOWN TO 117 MB.** Run with `smartbotic-db-cli configure <coll> [--versioning on|off] [--max-versions N]` (client 2.18.1), after a full data+config backup copied OFF the box and verified there. Measured, each collection in turn:
 
   | collection | before | after | time | setting |