Jelajahi Sumber

docs: 2.21.2 on prod with an honest memory budget, and adopt is proven by disk_only 0 (SV-27)

fszontagh 1 bulan lalu
induk
melakukan
c6e00b267f
1 mengubah file dengan 10 tambahan dan 1 penghapusan
  1. 10 1
      CLAUDE.md

+ 10 - 1
CLAUDE.md

@@ -642,11 +642,20 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **`estimated` ROSE +18 MB AGAINST A ~40 MiB PRICE, AND THE EXPLANATION IS NOT ANY OF THE THREE I OFFERED - THE 1,970 VECTORS WERE ALREADY IN MEMORY AND HAD BEEN ALL ALONG, SO ADOPT ADDED NOTHING FOR THEM.** I sent upstream three candidate readings (the vector branch did not fire / `storeVector` does not increment on this path / `estimated` is a per-doc heuristic) and named the first as the one to rule out first because it was the only one where vectors would still be LMDB-only. They answered from their code with a fourth that rules out all three: **eviction never touches `coll.vectors`, and the snapshot writes a collection's VECTOR section independently of its documents** - so when the old writer dropped an evicted document's body, the vector stayed in memory, every later snapshot carried it, and every boot loaded it back through the uncounted `loadVector`. At adopt, `storeVector` found the entry already there and added `new - old` = 16,416 - 16,416 = **0**.
   **So the ~31 MiB "permanent cost" was never real, and the price of adopt was the bodies alone.** `estimated` is a sum of per-row estimates rather than an average-based heuristic - my reading (3) was half right - and `estimateDocumentSize` sizes the PARSED TREE at roughly 2x the JSON bytes, which turns 8.8 MiB of sampled bodies into ~18 MB and matches the observation exactly. Their earlier "expect `estimated` to fall ~31 MiB after the next restart" is void with it: **expect no step there**, and do not read its absence as something having gone wrong.
   **The useful consequence is that a VECTOR OUTLIVES ITS OWN DOCUMENT BODY IN MEMORY, which widens the headroom defect rather than narrowing it.** Vectors are uncounted at boot, are never freed by eviction, and survive the eviction of the row they belong to - so prod's ~615 MiB of resident vectors is not merely missing from `237 MB estimated (46%, pressure=normal)`, it is missing in a way no amount of eviction can reduce. The lesson for next time is about the shape of the question, not the number: **three readings offered with one named as "rule this out first" still missed the answer, because all three assumed the adopt path was what put the vectors there.** The premise under all of them went unstated and therefore unchecked, and only the owner of that code could see it.
-  **SCOPED TO 2.21.1 AND EARLIER, WHICH IS WHAT PROD RUNS TODAY: DATABASE 2.21.2 MAKES EVICTION RELEASE A DOCUMENT'S VECTOR TOO, AND COUNTS VECTORS WHEREVER THEY ENTER MEMORY INCLUDING BOOT.** The claim above was accurate when measured and the mechanism it describes is why 2.21.2 exists, so it is labelled rather than rewritten. From 2.21.2 an eviction releases body AND vector - but **only while the LMDB mirror is healthy with zero drift**, a reload reads the vector back from LMDB, and eviction candidates are sized body plus vector. The snapshot writer changes with it, for the vector section only: it writes resident vectors plus released ones read back from LMDB, a batch at a time under the collection lock, where it used to iterate the live map with NO lock. Format stays v4 in both directions. **The one-way edge on a rollback: a vector deleted while a 2.21.2 snapshot is being written becomes a zero-length entry, which a 2.21.2 loader skips and a 2.21.1 loader stores as an EMPTY vector that scores nothing** - findable by id, retrievable by no search, which is exactly the unsearchable-junk-row failure this file already records. So the door is still two-way for reading and is NOT clean for vectors, and a downgrade wants a search-based read-back rather than a count.
+  **SCOPED TO 2.21.1 AND EARLIER: DATABASE 2.21.2 MAKES EVICTION RELEASE A DOCUMENT'S VECTOR TOO, AND COUNTS VECTORS WHEREVER THEY ENTER MEMORY INCLUDING BOOT.** The claim above was accurate when measured and the mechanism it describes is why 2.21.2 exists, so it is labelled rather than rewritten. From 2.21.2 an eviction releases body AND vector - but **only while the LMDB mirror is healthy with zero drift**, a reload reads the vector back from LMDB, and eviction candidates are sized body plus vector. The snapshot writer changes with it, for the vector section only: it writes resident vectors plus released ones read back from LMDB, a batch at a time under the collection lock, where it used to iterate the live map with NO lock. Format stays v4 in both directions. **The one-way edge on a rollback: a vector deleted while a 2.21.2 snapshot is being written becomes a zero-length entry, which a 2.21.2 loader skips and a 2.21.1 loader stores as an EMPTY vector that scores nothing** - findable by id, retrievable by no search, which is exactly the unsearchable-junk-row failure this file already records. So the door is still two-way for reading and is NOT clean for vectors, and a downgrade wants a search-based read-back rather than a count.
   **AND THE ACCOUNTING CHANGE IS A STEP THAT MUST BE PLANNED BEFORE THE FIRST BOOT, BECAUSE THE HONEST NUMBER BREACHES A BUDGET THE DISHONEST ONE FITTED.** Prod's `storage.memory.max_memory_mb` is **512** with soft 70 / hard 85 / emergency 95, and the live line reads `272 MB estimated (53%, pressure=normal)` - counting bodies only. Measured rather than assumed, all five vector collections on prod are dim 4096 (`justice-pa:facts` 121, `justice-pa:summaries` 66, `novitax:kb_chunks` 13014, `novitax:kb_fact_answers` 13093, `novitax:kb_facts` 13093), so 39,387 rows x 16,416 B = **647 MB** of vectors join the estimate and it becomes ~919 MB, i.e. **179% of 512 - past the 95% emergency line, where writes answer RESOURCE_EXHAUSTED until eviction has drained.** Nothing about the box changes; only the measurement does, which is the point worth keeping: **a budget that was never counting the largest thing in the store was never a budget, and the release that starts counting it is the release that appears to break it.**
+  **DEPLOYED 2026-10-27 AND THE PREDICTION HELD, WITH ONE UNIT ERROR WORTH MORE THAN THE RESULT.** Prod is on `2.21.2 (commit fe9b15b)`, client unchanged at 2.20.0, in a 134 s window (16:08:07-16:10:16 UTC; the stop alone took 53 s writing its shutdown snapshot). `max_memory_mb` was raised to **1536** FIRST, in a `conf.d` drop-in, and the first line on the new build read **`889 MB estimated (57%, pressure=normal), of which vectors 616 MB, 118247 docs, 0 evicted`** - honest, in `normal`, with no warning or error anywhere in the boot.
+  **I predicted 919 MB and the answer was 889, because I added DECIMAL MB of vectors to a MEBIBYTE estimate.** 39,387 rows x 16,416 B is 646.6 MB **or** 616.6 MiB, and the server reports the second: 272 + 616 = 888 against 889 observed. The mechanism was right and the units were mixed, which here erred pessimistically - but **a unit mismatch inside a headroom calculation has no preferred direction**, and this one was 30 MB on a figure being compared against a pressure threshold. State MiB or MB whenever a number is going to be divided by a budget.
+  **The budget must be chosen against the LIVE estimate, not a quoted one.** The database session recommended 1300 from a `258 MB` line; the live figure was 272, so the real requirement was 919/0.7 = 1313 and 1300 would have landed at **70.7% - inside `soft` pressure**, which is not the "behaviour unchanged, numbers honest" it was offered as. 1536 puts it at 57.9% with 186 MB of growth before soft, against the 138 MB of body growth the old 512 budget allowed, so eviction is marginally EARLIER than before rather than later.
+  **The drop-in carried all TWELVE keys of the `memory` object with only `max_memory_mb` changed, because whether the loader merges drop-ins deeply INSIDE a nested object was unknown.** A one-key drop-in would have been correct under a deep merge and would have reset the eviction thresholds to defaults under a shallow one - the same shape as a key PATCH replacing a whole scope, and as `createCollection` clearing a default TTL when 0 is passed back. Carrying every current value makes the question moot rather than answered, and a pre-flight assertion proved exactly one key differed. The boot log then confirmed `Merging drop-in: .../60-memory.json` and `Config assembled from 3 file(s)`.
+  **VERIFICATION, and the one that counts is the SEARCH rather than the counts.** 2.21.2 rewrites the snapshot's vector section, so a count cannot see the failure that matters. A **fixed explicit `query_vector`** (seeded, dim 4096) was run against all five vector collections before and after: **top-5 ids AND scores identical to 8 decimal places in every one**. Counts unchanged on seven collections, a body read back with `_created_by` still `fn:justice-pa/compress` at `_version` 8, a negative control 404, and a deliberate write probe (create collection, insert, read back, delete, control 404) proving writes are accepted - which is the precise thing an emergency-pressure boot would have refused. Swap in use FELL 1147 -> 521 MB.
+  **What is NOT verified, stated because the headline invites the opposite reading: the vector-release-on-eviction path was never exercised.** Prod sits at `0 evicted, pressure=normal`, so nothing has evicted anything and the new behaviour is dormant. It becomes live only under pressure, and its own precondition is a healthy LMDB mirror at zero drift - which prod does currently satisfy (`memory_only: 0`). **The feature was deployed, not tested, and the first eviction episode is the measurement nobody has taken.**
+  **AND MY PROBE SWALLOWED AN ERROR WHILE TAKING THE BASELINE, WHICH WOULD HAVE POISONED THE COMPARISON.** The first pre-upgrade run reported `novitax:kb_fact_answers` as `top: []` with a null `filter_mode`; that was an error envelope with no `results` key, not an empty result, and the parser turned it into a legitimate-looking empty baseline that the post-upgrade run would have "matched" or "fixed" for reasons unrelated to the upgrade. A retry succeeded immediately. The rewrite distinguishes a missing `results` key from an empty one, records the envelope verbatim and retries three times - **an absent field and an empty field must never render the same in a baseline you intend to diff.**
   **RSS IS DELIBERATELY NOT QUOTED AS THE COST: 1232 MB was a 19-hour-old process and 1595 MB is a fresh boot**, so that difference is the restart. `VmHWM` moving 1,771,136 -> 1,780,676 kB is the only clean statement available and says the boot peak barely changed. Box-wide swap in use FELL, 646 MB to 259 MB.
   **Provenance survives adoption, and it had to be checked rather than assumed:** `justice-pa:facts/01a116ef1b2edf735dd281c3f564` reads back at `_version` 2 with `_created_by` still `fn:justice-pa/compress`, control a neighbouring id that never existed still `not found`. An adoption that took the insert path would have re-created rows at version 1 with a fresh creator - which is exactly the pre-2.20.2 ghost-clobber behaviour, and novitax now depends on `_created_by` as their only after-the-fact attribution channel.
   **WHAT IS STILL OWED, WITH ITS TRIGGER: the POINT of adopt is that the next SNAPSHOT carries these rows, and that is provable only at the next boot reporting `disk_only: 0`.** Verified today is "adopted into memory", not "carried by a snapshot", and the two must not be conflated in a later reading of this entry.
+  **PAID 2026-10-27, AND THE ANSWER IS `disk_only: 0`: THE ADOPTED ROWS ARE CARRIED BY SNAPSHOTS.** The 2.21.2 boot was the first restart since the adopt (prod had been up since 2026-10-23 15:15:23 with `NRestarts=0`), and its audit reports `{"adopted": 0, "compared": 72, "disk_only": 0, "memory_only": 0, "not_adoptable": 0}` with ZERO per-collection entries, against 7217 on the adopt boot. SV-27 closed on that.
+  **THE LOG LINE CHANGED WORDING AND MY GREP MISSED IT, WHICH IS THE REUSABLE PART: an audit with nothing to report says `key audit: 72 collection(s) consistent (2040 ms)` at INFO, not `N collection(s) compared ... 0 row(s) on disk only` at WARNING.** So a grep written against the alarming form returns NOTHING on a clean boot, which is indistinguishable from the audit never having run - and I read that absence as a missing audit for a minute. Two things rescued it: **`consistency-report.json` is written every boot regardless and is the authoritative artefact**, and a **control proved the grep worked** by matching the 10-23 boot 43 times. **A check keyed to the wording of a failure cannot confirm a success**, and the file beats the journal for this question.
   **A BACKUP OF A `conf.d` FILE MUST NOT LIVE IN `conf.d`.** The first instinct was `50-consistency.json.bak-20261023` beside the original; a loader that globs the directory would have read the backup as a second config file, and the boot log confirms the loader does merge drop-ins by name (`Merging drop-in: ...`). It went to `/var/backups/` instead. The dpkg-conffile rule says WHERE a drop-in goes; this is the matching rule for where its backup goes.
   **AND THE WINDOW'S REAL LESSON: THE SCRIPT DISCOVERED A MISSING TOOL WITH THE DATABASE ALREADY STOPPED. `rsync` IS NOT INSTALLED ON PROD.** The plan was a hot `cp -a` followed by a cold `rsync` delta, to keep downtime near the approved 90 s; `set -e` stopped the script at `rsync: command not found` after `systemctl stop smartbotic-database` had already returned. It failed safe - nothing was modified, the config was untouched and the service was simply down - and recovery was one `cp -a` of the full 5.1 GB, 29 s, so the window still came in at 88 s. **The generalisable form is the `pkill`-not-installed trap one layer up: verify every tool the window's script needs BEFORE the step that takes the service down**, because the cost of a missing binary is not the error, it is where in the sequence the error lands. A dry run of the script against a running box would have found it for nothing.