Jelajahi Sumber

docs: the 7219 are eviction across a WAL rotation, and key revocation was exposed but never exercised

The database owner reproduced the cause on the released 2.20.2 binary: a
snapshot reads an evicted row back from the WAL only, the WAL rotates at
100 MB, and after that the row is written as absent. Their fix reads LMDB
first and fails the snapshot rather than dropping a row; when it lands,
disk_only=adopt loads prod's 7219 into memory at boot, so take report first on
a 2 GB box already on swap.

Also: 10 of 11 key rows were disk-only on 2.17.2, where a DELETE would have
404'd and left the key working. Swept the whole access log - 3 key DELETEs
ever, all 200, against a control of 24114 other DELETEs - and verified
create/authenticate/revoke/401 end to end today with a throwaway key.
fszontagh 1 bulan lalu
induk
melakukan
b2ee8835e4
1 mengubah file dengan 7 tambahan dan 0 penghapusan
  1. 7 0
      CLAUDE.md

+ 7 - 0
CLAUDE.md

@@ -568,6 +568,13 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **A CONTROL RATE HIGHER THAN THE TEST RATE IS THE CLEANEST POSSIBLE REFUTATION, AND THIS IS THE SPECIMEN TO REMEMBER IT BY.** Chasing the orphan hypothesis I had handed them, novitax measured 37 `sourceId`s holding chunks from two write epochs and found an older chunk substantially overlapping a newer-epoch chunk (8-word shingles) in **19 of 37** - which reads as 19 orphaned sources and is exactly the number anyone would report. The control: older chunks overlapping OTHER OLDER chunks of the same source, **24 of 35**. **The control rate is HIGHER**, so the overlap is simply how transcript chunks sit against each other and the test carries no signal whatsoever. Their words: they nearly reported the 19 first. The general form is that a rate means nothing without the base rate, and the base rate is almost never the one you assume - it is measured by running the identical test on a population where the effect cannot be present.
   **And my own contribution to that was the WEAKER instrument: I recommended a per-source count check, and the answer was in their control flow.** A 404 is not in their retryable set so the client throws, `deleteWhere` has no try/catch so it rejects, and the delete is awaited IN FULL before any insert runs - so a failed delete aborts the source before a single POST, and the orphan state I had described is **unreachable in that code rather than merely unobserved**. A structural argument settles an existence question that no amount of counting can close; counting was the right tool only for the hypothesis I could not read the code for. Ask for the control flow first.
 
+- **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.
+- **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.
+
 ## 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.