Pārlūkot izejas kodu

docs: 2.21.1 pruned 1.9 GB, and the memory budget does not bound vectors

The prune landed as predicted - 1.925 GB to 30.2 MB across the two capped
history files, on the first snapshot after the 2.21.1 boot - and is verified
by reading a document body back out of each collection rather than by the
file sizes, since a 98.7% smaller file beside a healthy count is exactly the
pair that cannot see unreadable data.

Four instrument findings, all of which produced or nearly produced a wrong
answer first:

- `smartbotic-db-cli get` never returns a vector, so a script flagging rows
  that carry `_vector` flagged nothing across 39 collections and read as
  "no vectors involved". The control refuted it: kb_facts is kind=vector
  dim=4096 and returns no vector field either. The flag could not fire.
- `count` prints a bare number while `info` prints the labelled `documents:`
  field, so this file's own "parse the labelled field" rule only applies to
  one of them - and I reached the resulting silence by redirecting the CLI's
  stderr, which this file warns against for precisely that reason.
- nine clean snapshots since 2.20.1 with zero stalls, but 0 requests in every
  snapshot minute, so only the internal arm carries evidence. "No stall" and
  "no traffic" are indistinguishable without that check, and the by-minute
  grep first returned zero for all nine at once.
- I reported a log line's misleading hint as something the database "still"
  does; all 69 occurrences are from 2.17.2 and it has been gone since 2.21.0.
  A tense error is a measurement error.

And the finding that outlives the window: asking rather than estimating the
adopt cost established that eviction never frees a vector and that vectors
loaded at boot are not counted at all, so prod's ~615 MiB of resident vectors
sits outside the `237 MB estimated (46%)` line this file has been reading as
headroom. The percentage is silent about ~2.6x more memory than it reports.
fszontagh 1 mēnesi atpakaļ
vecāks
revīzija
f3731edcab
1 mainītis faili ar 27 papildinājumiem un 0 dzēšanām
  1. 27 0
      CLAUDE.md

+ 27 - 0
CLAUDE.md

@@ -610,6 +610,33 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **AND PROD HAS RUN THE PAIRING, 47 SECONDS CLEAR.** Hunting back-to-back EQUAL sequences found 91; 87 are ~3600 s apart (an idle hour, the timer firing with nothing written - benign), three are 180-710 s, and **one is 51 s apart and is the periodic snapshot followed by the shutdown's final one**: `10:46:41 Created snapshot at sequence 96309`, `10:47:28 Received signal 15`, `10:47:32 Created snapshot at sequence 96309 / Final snapshot taken on shutdown`. Same two writers, same state, both completing, separated by 47 s of luck rather than by any mechanism. On a slower snapshot or an earlier stop that is an overlap.
   **The count on its own meant nothing, and I nearly reported it: "91 back-to-back equal sequences" sounds alarming and is almost entirely idle hours. Only the GAP DISTRIBUTION separates an idle timer from two writers at the same state** - median 3604 s, min 51 s. A frequency without its distribution is the same error as a rate without its base rate.
 
+- **PROD IS ON DATABASE 2.21.1, AND ITS FIRST SNAPSHOT RECLAIMED 1.90 GB OF HISTORY THAT NO SUPPORTED OPERATION COULD REACH.** Deployed 2026-10-22 19:53:14 UTC, 89 s window, own full pre-upgrade backup, `2.21.1 (commit 8c1c452)`, client 2.20.0, vectorapi 0.18.0, `NRestarts=0` on all three. The cap ran AFTER the snapshot completed (20:53:23, sequence 763785), one collection at a time, each holding only its own collection's history lock:
+
+  | file | before | after | took |
+  |---|---|---|---|
+  | `justice-pa%3avectorapi_function_runs.hlog` | 479,861,762 | 11,972,573 | 24 s |
+  | `default%3avectorapi_function_jobs.hlog` | 1,444,948,719 | 18,186,095 | 76 s |
+
+  1.925 GB to 30.2 MB. Nothing waited on it that a caller could see: the memory line continued every minute and the document counts went UP across the prune.
+  **THE SIZE DROP IS NOT THE VERIFICATION AND CANNOT BE. A 98.7% SMALLER FILE BESIDE A HEALTHY COUNT IS EXACTLY THE PAIR THAT CANNOT SEE UNREADABLE DATA** - the same shape as a restore whose ids all match while the vectors rank nowhere. A document BODY was therefore read back out of each pruned collection, and the useful one is a `_version 3` job row: the cap kept the newest version of a document that HAD three, which is what "newest 1 per document" has to mean and what a count can never show.
+  **The forward half, which the sizes alone also cannot say: both files are still byte-identical to those numbers while the collections take writes** (runs 1284 to 1296, jobs 43779 to 43793 over six minutes). So versioning-off genuinely appends nothing once replay is out of the path, and the 1.9 GB does not come back absent another unclean shutdown.
+- **`smartbotic-db-cli get` NEVER RETURNS A VECTOR, SO ANY SIZE OR CONTENT CHECK BUILT ON ITS OUTPUT IS BLIND TO THE VECTOR HALF OF A ROW.** Met 2026-10-22 pricing the adopt step. A sampling script flagged any sampled document carrying `_vector`/`vector` and flagged NOTHING across all 39 collections, which reads as "no vectors are involved". **The control refuted it: `novitax:kb_facts` is `kind=vector dim=4096`, consumers run similarity search against it daily, and `get` returns no vector field for it either.** The flag was incapable of firing. Read `kind` and `vector_dimension` from the vectorapi collections route, which does report them; `smartbotic-db-cli info` prints neither, the same silence it keeps about the default TTL - and its silence is not a zero in either case.
+- **`count` PRINTS A BARE NUMBER AND `info` PRINTS THE LABELLED `documents:` FIELD - and this file's own warning to parse the labelled field only works against one of them.** The earlier entry says parse `documents: 43370` rather than the first integer, which is right, and that line comes from `info`. A `grep documents:` over `count` output therefore matches nothing and returns silence, which on a first reading looks like the collection being unreadable. Worse, I reached that silence by redirecting the CLI's stderr inside the remote shell, which this file already warns against for exactly this reason: never redirect the error away from a command whose success you are about to interpret.
+- **NINE CLEAN SNAPSHOTS SINCE 2.20.1 AND ZERO STALLS - BUT THE EVIDENCE SPLITS IN TWO, AND ONLY ONE HALF COUNTS.** Owed to the database owner after the single clean snapshot that was correctly reported as weak. Measured: **9 snapshot completions since the 14:45 upgrade, 0 `Deadline Exceeded` anywhere in vectorapi's journal**, against a prior base rate of 43 stalls over ~44 snapshots - so roughly 0.2% to 4% if nothing had changed, which clears the bar.
+  - **The INTERNAL arm is real evidence.** 35 of the original 43 were our own metadata calls (`getCollectionInfo` 30, `getMemoryStats` 5) issued by the scheduler, event watcher and job reclaim, which run every minute whatever the traffic. The positive control that makes their silence informative is that cron rows kept landing at ~2/min straight through the prune, so the paths that warn were being exercised and stayed quiet.
+  - **The TENANT arm is worth nothing.** Checked minute by minute, there were **0 requests in every snapshot minute**, so the 5 `similaritySearch` and 3 `insert` failures in the original 43 had no chance to recur and their absence proves nothing. **"No stall" and "no traffic" are indistinguishable without that check**, and the by-minute grep first returned zero for all nine at once - the signature of a check that cannot fail. A positive control (12 requests at 21:0x) showed the grep worked and that the log only starts at 17:42 because rotation was forced that afternoon, so two of the nine zeros are "no log" rather than "no traffic".
+  The honest form is therefore "no internal stall across 9 snapshots, tenant exposure not re-measured for want of tenant traffic" - not "the fix is confirmed".
+- **`rt` AND `urt` IN THE ACCESS LOG ATTRIBUTE A SLOW CALL WITHOUT ANY GUESSING, AND THAT IS WHAT THE TIMING FIELDS WERE ADDED FOR.** A novitax collections listing took 5.14 s by the client's clock; the log line reads `rt=4.952 urt=4.952`, so it was upstream-side rather than network, while three immediate repeats read `rt=0.398/0.373/0.427` and a no-fan-out control read `rt=0.003` against 0.112 s client-side (the difference being RTT from the dev host, which is why an on-box figure and a remote one are not comparable). **Still unattributed: one unreproduced sample, no snapshot or prune running, and the nearest memory line reads `pressure=normal, 0 evicted`, which removes eviction as a candidate without supplying another.** Recorded as unexplained rather than explained - a tidy cause that fits is more expensive than no cause, because no cause keeps someone looking.
+- **A TENSE ERROR IS A MEASUREMENT ERROR: I REPORTED A LOG LINE'S WRONG HINT AS SOMETHING THE DATABASE "STILL" DOES, AND IT HAD BEEN FIXED TWO RELEASES EARLIER.** The evicted-document snapshot warning ending "Likely a pre-v1.7.3 snapshot already lost them" named the wrong cause on prod and is worth knowing about - **in the past tense only.** Swept after the owner pushed back: **69 occurrences, all on 2026-10-20, the last at 17:57:43, every one written by 2.17.2.** Zero from any 2.21.x process, which boots at 18:30 and 19:53 on 10-22. In 2.21.x an unreadable evicted document FAILS the snapshot and keeps the WAL instead of logging anything, which is strictly better than a reworded warning because a failure cannot be read past. **What I had supported "this message existed and misdirected me"; I upgraded it to a claim about current code without checking the version of the process that wrote the line.** Same family as reading a requirement off traffic measured after the fix that removed it - the data describes a superseded state, and the remedy had already shipped.
+- **ADOPT IS PRICED FOR THE BODIES AND NOT FOR THE VECTORS, AND THE GAP SHOWS UP AS AN ARITHMETIC CONTRADICTION RATHER THAN A MISSING NUMBER.** 2.21.1's report answers what 2.21.0's could not - each entry now reads `"action": "reported (adopt would load them)"` with `"collection_in_memory": true`, upstream having taken the suggestion - so prod is `7217 disk-only, 0 not adoptable, all 39 collections in memory`, unlike their staging's 25 of 100. Sampling up to 5 bodies per collection x its row count gives **8.8 MiB** of document bodies, the id count matching `disk_only` exactly. The vector-kind collections among them are `novitax:kb_chunks` (1964) and `justice-pa:facts` (6), 1970 rows at dim 4096, nominally 30.8 MiB as float32 - **but 39,387 vector-kind documents live on prod and 16 KiB each would be 615 MiB against the server's own `237 MB estimated` over 96,320 docs (~2,580 B/doc).** 615 does not fit in 237, so I asked rather than estimating, and the answer came back from their code within the hour.
+  **ANSWERED: ADOPT LOADS BODY *AND* VECTOR, SO THE FIGURE IS ~40 MiB - AND THE CONTRADICTION RESOLVED INTO A FINDING FAR MORE IMPORTANT THAN THE WINDOW.** `adoptFromDocStore` reads the body from LMDB and, when `vector_dimension > 0`, also reads `_vectors_<coll>` and calls `storeVector`. So 1,970 vector rows bring 1,970 x (16,384 + 32) B = ~30.8 MiB of float32 plus ~8.8 MiB of bodies. The counting is where it gets interesting, and all three parts matter to us:
+  - a **body** is counted in `estimated` and can be evicted;
+  - an **adopted vector** is counted, but **eviction NEVER frees a vector** - `evictDocument` erases the body and leaves `coll.vectors` alone, so only a delete or a vector-replacing write releases one. Eviction cannot trim that 30.8 MiB; it can only evict OTHER bodies to make room for it;
+  - a vector loaded at **BOOT** (snapshot load or WAL replay, through `loadVector`) **is not added to the estimate at all.**
+  **SO PROD'S ~615 MiB OF RESIDENT VECTORS SITS ENTIRELY OUTSIDE THE `237 MB estimated (46%, pressure=normal)` LINE, AND THAT LINE IS THE ONE THIS FILE HAS BEEN READING AS HEADROOM.** The percentage is a fraction of a budget that does not bound the largest thing in the store. It is not wrong about what it measures; it is silent about roughly 2.6x more memory than it reports, on a 1973 MB box. Their own defect, raised with their owner, and it does not change the adopt step - but it does mean **`pressure=normal` and a low percentage are not evidence of memory headroom here**, which is exactly the shape of claim this file keeps having to retract.
+  Practical effect of the window itself: RSS up ~40 MiB, of which ~31 MiB is permanent and ~9 MiB evictable; `estimated` rises by about the same until the next restart, then falls back ~31 MiB with RSS unchanged, because the adopted vectors return through `loadVector` and drop out of the count while staying resident. **A metric that falls while nothing is freed is worth knowing about before it is read as an improvement.**
+- **A WATCHER THAT COMBINES THE SUDO PASSWORD PIPE WITH A HEREDOC FAILS AT THE REPORTING STEP, AFTER THE DETECTION STEP HAS ALREADY SUCCEEDED - WHICH IS THE WORST PLACE FOR IT AND WAS WRITTEN DOWN AS FORBIDDEN BEFORE I DID IT.** The 2.21.1 prune watcher polled correctly for 58 checks, detected the first snapshot, and then printed `sudo: 3 incorrect password attempts`, because the reporting half piped the password AND a heredoc into one `ssh` so the password was consumed as the script's first line. It failed SAFE - nothing ran, the detection was still right, and the measurement was simply retaken one command per call - but the hour of waiting was spent and the result had to be reconstructed. **The trap was in this file already. Writing a trap down does not stop it; only a control does.** For a long wait, make the reporting step the part you have already exercised, because the detection step is the one that gets tested by the wait itself.
+
 ## Deploy / publish
 
 **`VERSION` and `api/openapi.json`'s `info.version` must agree, and `packaging/build.sh` now refuses to build unless they do** (`scripts/check-version-sync.sh`, run at the top level so it covers the local, Docker and publish paths alike). They drifted once: 0.10.0 was published with the docs claiming 0.9.2, and since `openapi.json` ships in the server package and is served at `/openapi.json`, the stale value was live. **Correcting it cost a whole release**, because a published version number is never reused for different content - which is why 0.10.0 exists but must never be deployed. A release step that relies on remembering is a release step that gets skipped, so it is a check rather than a checklist line.