Explorar o código

docs: correct the adopt cost - 2.20.1 streams the snapshot, so re-including rows grows the FILE not the peak

I named the snapshot peak as the deciding figure for disk_only=adopt; this
file already recorded that 2.20.1's writer streams a chunk at a time whatever
the store's size. The real costs are the adopted rows resident until eviction
trims them, and the larger snapshot file landing on a disk that already fails
the preinst space check.
fszontagh hai 1 mes
pai
achega
6fcdb66296
Modificáronse 1 ficheiros con 1 adicións e 0 borrados
  1. 1 0
      CLAUDE.md

+ 1 - 0
CLAUDE.md

@@ -571,6 +571,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **THE CAUSE OF THE 7219 IS NOW KNOWN AND IT IS NOT EVICTION BY ITSELF - IT IS EVICTION ACROSS A *WAL ROTATION*, AND THE DATABASE OWNER REPRODUCED IT ON THE RELEASED 2.20.2 BINARY.** A snapshot includes an evicted row by reading it back, and that read scanned only the WAL; the WAL rotates at 100 MB and a snapshot deletes rotated files whose entries it covers, so a row that stays evicted past a rotation can no longer be read back and the next snapshot writes it as ABSENT, with a WARN nobody was reading. Reproduced deliberately: 600 rows of 200 KB with a 1 MB memory budget, two snapshots, restart - 597 docs in memory, 3 on disk only. So the window for this is "evicted and not written again before the WAL rotates", which is why the churny collections dominate prod's list.
   **Their fix, on their main and not yet released: the evicted-row read goes to LMDB first, and a row a snapshot still cannot read now FAILS THE SNAPSHOT instead of being silently dropped** - the two must ship together, since the throw alone would grow the WAL unboundedly. Tested by reverting the LMDB read: snapshots refuse 22 times and all 600 rows survive. There is also a `mirror-pending.log` so a failed copy to LMDB is replayed from memory at boot, and new `storage.consistency { disk_only: adopt|report|remove, memory_only: report|write|remove }` knobs with a full `consistency-report.json` per boot.
   **WHEN THAT VERSION LANDS, PROD TAKES A MEMORY STEP ON THE FIRST BOOT AND IT MUST BE PLANNED RATHER THAN MET.** The default `disk_only: adopt` loads all 7219 rows into memory at boot so the next snapshot carries them - and on a 1973 MB box already running on swap, `novitax:kb_chunks` alone is ~32 MB of 4096-dim vectors before anything else. Eviction will trim it and now does so safely, but the right first move is `disk_only: report`, which logs exactly what `adopt` would do without doing it. Same shape as every other number in this file: see it before it acts.
+  **I FIRST NAMED THE WRONG COST HERE, AND THE REFUTATION WAS ALREADY WRITTEN IN THIS FILE TWO SECTIONS UP.** I told the database owner the figure that would decide whether `adopt` needs its own window was the SNAPSHOT PEAK afterwards, since the adopted rows go back into the serialised image. That is false on 2.20.1+ and this file says so: the writer streams to disk a chunk at a time (16 MB staged, documents copied 256 at a time - the 51 MB-against-585 MB measurement), so a snapshot adds a few tens of MB **whatever the store's size**. Re-including 7219 rows grows the snapshot FILE, not the snapshot's peak. **The real costs are two and neither is the one I named:** the adopted rows sitting RESIDENT until eviction trims them (their JSON plus `kb_chunks`'s ~32 MB of 4096-dim vectors, which `adopt` loads too), and the bigger snapshot FILE landing on a disk that already fails the database preinst's own space check at 84% with several 685 MB snapshots retained. The measurable number is the sum of the stored sizes of the ids `consistency-report.json` names, which is ours to compute rather than theirs to estimate - they declined to invent a delta, correctly.
 - **THE EXPOSURE ON KEY REVOCATION WAS REAL AND WAS NEVER EXERCISED, AND BOTH HALVES NEEDED A CONTROL TO ESTABLISH.** 10 of prod's 11 rows in `default:vectorapi_keys` were disk-only on 2.17.2, and on that version a DELETE at such an id answered not-found and LEFT THE ROW - so a revocation would have returned 404 while the key went on working, which is the worst possible silent failure for a credential store. Swept the whole nginx access log (24/Nov/2025 to date, unrotated): **exactly 3 DELETEs against a key route ever, on 16/Sep and 13/Oct, all 200.** The control that makes that zero worth anything is 24114 DELETEs of other kinds in the same log with the same matcher, so the pattern does match when there is something to match. Limit worth stating: the log only sees requests through nginx, so a delete issued against 127.0.0.1:8080 directly would not appear.
   **Verified the path works TODAY rather than reasoning from the fix**, with a throwaway key: create returns 201 and 12 keys, the new secret authenticates 200, DELETE answers 200, the key leaves the listing, **the revoked secret then answers 401**, a second DELETE answers 404, and the admin key still answers 200 - so exactly one key was revoked and the revocation really took effect on authentication, not merely on the listing.
   **And my first attempt at that probe measured nothing while looking like it worked**, which is this file's oldest trap in a new costume: the create carried a `scope` the route rejected, my script parsed only for `id`, so `$ID` was empty - and the follow-on checks dutifully reported "not in the listing", "401", "DELETE 404" and read exactly like a successful revocation test. **An empty variable makes every subsequent assertion pass for the wrong reason.** Print the response body before parsing a field out of it, and assert the precondition - here, that a key was actually created - before interpreting anything downstream of it.