Bläddra i källkod

docs: adopt is done on prod, and a vector outlives its own document body (SV-27)

disk_only=adopt went live 2026-10-23 in an 88 s window: 7217 adopted, 0 failed,
0 not adoptable. Verified by the document count rather than by the report, since
the recovery line is logged before the audit runs.

The memory finding is worth more than the window. `estimated` rose +18 MB
against a ~40 MiB price, and the reason is none of the three readings I offered
upstream: eviction never touches a collection's vectors and the snapshot writes
the vector section independently of the documents, so those 1970 vectors had
been resident all along and storeVector added new - old = 0. All three of my
readings assumed the adopt path was what put them there, and that shared
premise went unstated and therefore unchecked.

Also records the window's own lesson: the script met rsync's absence with the
database already stopped. It failed safe, but verify every tool a window needs
before the step that takes the service down.

Closes SV-28, SV-14, SV-21, SV-15, SV-25, SV-26, SV-29, SV-18.
fszontagh 1 månad sedan
förälder
incheckning
a3189edf14
1 ändrade filer med 11 tillägg och 0 borttagningar
  1. 11 0
      CLAUDE.md

+ 11 - 0
CLAUDE.md

@@ -637,6 +637,17 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   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.
 
+- **`disk_only: adopt` IS TAKEN ON PROD AND ALL 7217 ROWS WERE ADOPTED IN AN 88-SECOND WINDOW - AND THE MEMORY ESTIMATE ROSE BY LESS THAN HALF THE PRICE, WHICH IS A FINDING RATHER THAN A SAVING.** 2026-10-23 15:13:55-15:15:23 UTC on 2.21.1, cold whole-data-directory backup first, the flip one line in the package-unowned `conf.d` drop-in. Report: `{"adopted": 7217, "disk_only": 7217, "memory_only": 0, "not_adoptable": 0, "failed": 0, "milliseconds": 1239}`, 39 collections, every one `adopted into memory (loaded unchanged)`.
+  **THE REPORT IS NOT THE VERIFICATION; THE DOCUMENT COUNT IS.** `Recovery complete: 98821 docs` is logged at 15:15:12, BEFORE the audit runs at 15:15:21, and the first memory check after it reads **106,041 docs** - a delta of 7,222 for 7,217 adopted plus three live writes. A report saying "adopted" beside a count that never moved would have read identically, which is this file's oldest shape.
+  **`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.
+  **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.
+  **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.
+
 ## 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.