Просмотр исходного кода

docs: the client pin move widens the slug set, and fixes a retry-forever read

A consumer pointed out I had under-filed "encrypted_field becomes live" as
additive. The general form is that the observable slug set widens on every
READ route at that moment, because forwarding the server's reason on reads is
a 2.17.0 client change and translate() branches on nine reasons.

Checked rather than generalised loosely, and one case inverts the concern:
ResourceExhausted with no reason falls through to 429 rate_limited, which
means wait and retry. A document grown too large to READ back - which we have
measured happening through repeated patches - is exactly that case, and no
wait fixes it. With the reason it becomes 422 message_too_large, permanent
and honest. So the pin move corrects a read failure currently reported as
retryable, rather than only adding a slug.

The consumer's framing is the part to keep: the dangerous default branch is
not "unknown error" but "retry", so the question to ask each consumer is not
"do you handle this slug" but "what does your default branch do, and is your
retry decision keyed on status or on code". They are inert because theirs is
keyed on status, which is the design that makes a widening set safe.

They also named the asymmetry in my phrasing: understating filter_mode cost
an opportunity, understating this would cost a retry loop against a permanent
error. Same words, different blast radius.
fszontagh 1 месяц назад
Родитель
Сommit
c1e3a38b03
1 измененных файлов с 2 добавлено и 0 удалено
  1. 2 0
      CLAUDE.md

+ 2 - 0
CLAUDE.md

@@ -167,6 +167,8 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **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.
 - **`encryption-verify` REPORTS CLEAN WHILE THE PLAINTEXT IS STILL ON DISK.** Measured in the same run: immediately after the online upgrade, `grep -F` found the plaintext label in BOTH `wal/wal-current.log` and the project's `data.mdb`, while verify printed `vecenc:vecs [encrypted] ... plaintext-required 0` and `CLEAN`. The only contrary signal is a separate line, `at-rest migration sealed: NO (restart pending)` - easy to read past. After a restart the plaintext was gone and the line read `sealed: yes`. **So CLEAN means "everything that must be ciphertext is ciphertext in the live store", NOT "no plaintext remains anywhere". Read the `sealed` line, and until it says yes the old copies are still readable.** Same family as the flag that recorded an intention: a check that answers confidently about a narrower question than the one being asked.
 - **`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.
 - **WE CREATE EVERY COLLECTION WITH UNLIMITED VERSION HISTORY, and most of prod's history is therefore our own operational churn.** `createCollection(..., maxVersions = 0, ...)` and 0 means "keep unlimited history", not "keep none" - so every code push to a function has appended a full copy of the script forever. Measured on prod: `justice-pa:vectorapi_functions.hlog` 114 MB (the function REGISTRY, a handful of rows), `default:vectorapi_function_jobs.hlog` 14 MB, `justice-pa:vectorapi_function_runs.hlog` 4.7 MB - about 133 MB of the box's 192 MB of history, roughly 69%, none of it data anyone would ever read. A consumer's 47 MB of `kb_chunks` history is retention of the same kind on a collection that has not changed size in days.
   **IT IS A DISK AND GROWTH PROBLEM ONLY. I claimed history bytes dominate the at-rest encryption migration, and measured on prod's own data they do not matter to it at all.** That claim was inherited from the database team's sizing model and amplified by me, and one measurement would have settled it before I asked them for a boot mode and asked a consumer to weigh an escape hatch. Measured with 2.17.1 on a copy of prod's data directory (1.6 GB, 24753 docs, 65 collections, prod's own config, 900 MB cap): **190 seconds total**, of which the ENCRYPTION pass was **13 seconds** (24733 rows scanned, 19 encrypted, 26 history versions) and **compaction was 176 seconds, 167 of them novitax's single 339 MB env**. The seal was under a second.