Parcourir la source

docs: the snapshot is not a complete backup - 2.20.2's boot audit found 7219 LMDB-only rows on prod

Also: prod's disk now fails the database preinst's own 1.2x space check, so
every future DB upgrade is blocked until it is freed; and the 'one ordering
rule everywhere' claim is false - 0.17.0's own ttl_seconds refusal on PUT sits
behind the collection lookup, measured as 422 on an existing collection and
404 on one that does not exist.
fszontagh il y a 1 mois
Parent
commit
29542fc5da
1 fichiers modifiés avec 8 ajouts et 1 suppressions
  1. 8 1
      CLAUDE.md

+ 8 - 1
CLAUDE.md

@@ -455,7 +455,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **THE HISTORY QUESTION TO ASK OF ANY COLLECTION IS WHAT ITS WRITES TRACK, NOT HOW BIG IT IS TODAY.** A consumer found the sharp version of this in their own code after reading per-collection numbers we sent them: `touchFacts` patched `last_retrieved_at` on EVERY recalled fact on EVERY recall, so one search returning 8 hits wrote 8 full copies of documents whose CONTENT had not changed - while the only reader, a ranking function, asks nothing finer than "inside 30 days? inside 180 days?". They were paying a version per hit for precision nothing reads. Their fix is the shape worth copying: skip the write when the stored timestamp is already inside the last day, which bounds it at one version per field per day **and leaves the ranking unchanged BY CONSTRUCTION rather than by judgement**, since at 30-day granularity this morning and this second are the same input.
   **The dangerous class is history that grows with READ traffic**, because it has no natural ceiling and looks harmless in exactly the period before anyone uses the feature - theirs measured 266 KiB with only 16 of 122 rows ever touched, purely because the customer had barely used the assistant since cutover. Three shapes, needing different answers: read-driven (unbounded, fix the write), content-driven like their `calls` at ~13 KiB per call for transcript-then-analysis patches (bounded by real volume, fine), and human-driven like their `settings/main` at version 172 (bounded by how often a person changes a setting, fine).
   **Audited OURS against that: we are clean, and the audit is the point rather than the result.** `function_registry.cpp` writes only in `put` (a code push), `setPolicy` and `setEnabled` - nothing stamps the row on a read or a run. So the 195 MiB over 18 rows is genuinely push-driven: `put` upserts the WHOLE row including the script source at ~199 KiB, so ~1000 pushes accounts for it exactly. And `default:vectorapi_keys.hlog` measures 0.0 MB, which is the measurement that rules out a per-request `last_used_at` stamp on the key store - the one place this pathology would have grown with every API call we serve.
-  **What disabling versioning costs**, confirmed from their code rather than assumed, because the plan is to turn it OFF for the queue and the run log and keep a small N (5-10) on the registry: version history and `restoreVersion`/`restoreToDate` stop working for new writes, and **a DELETED row can no longer be restored**, because restore-after-delete reads the pre-delete state from history. That is why the REGISTRY keeps versions - an accidentally deleted function is exactly the row worth recovering - while a claimed-and-deleted queue row has no reader. It does NOT touch the WAL, replication, the event stream (actor included) or `_version`, which still increments; none of them read history, and recovery is snapshots plus WAL.
+  **What disabling versioning costs**, confirmed from their code rather than assumed, because the plan is to turn it OFF for the queue and the run log and keep a small N (5-10) on the registry: version history and `restoreVersion`/`restoreToDate` stop working for new writes, and **a DELETED row can no longer be restored**, because restore-after-delete reads the pre-delete state from history. That is why the REGISTRY keeps versions - an accidentally deleted function is exactly the row worth recovering - while a claimed-and-deleted queue row has no reader. It does NOT touch the WAL, replication, the event stream (actor included) or `_version`, which still increments; none of them read history, and recovery is snapshots plus WAL. **Read that last clause as the SERVER's recovery input and never as a backup rule - measured 2026-10-22, the snapshot does not carry rows that live only in LMDB, so a copy of `snapshots/` and `wal/` is not a copy of the dataset; see the boot-audit entry below.**
 - **`Retry-After` IS KEYED ON THE CAUSE, AND ITS ABSENCE ON MOST 503s IS THE INFORMATION - WHICH IS WHY IT CANNOT BE SET AT THE HANDLER THAT MAPS THE STATUS.** 0.15.0+. `ApiError::retryAfterSec` is a 5th constructor parameter filled at the RAISE site, because that is the only place that knows whether a duration is the remedy; `retryAfterSeconds()` (`errors.cpp`, pure) prefers that hint, then gives a 429 the limiter's own window, then **returns 0**. The values are measured rather than round: `kRetryAfterDbUnreachableSec = 5` (the OOM crash loop recovered in 13-15 s a cycle), `kRetryAfterReadOnlySec = 30` (recovery, not a blip), `kRetryAfterRateLimitedSec = 60`. **The temptation is to stamp every 503, and that is the defect rather than the feature:** most of this service's 503s are `db_error` "insert failed" - a write that did not apply - or `no_runner`, which needs an operator. No duration makes either succeed, so a number there invents a remedy a caller would honour. So the tests that matter are the PAIRING ones (`AnOrdinary503SaysNOTHING`, `NoRunnerConfiguredSaysNOTHING`), deliberately falsified by making the mapping blanket for `Unavailable`: exactly those two go red and the four positive ones stay green, which is the only way to know the four are testing selectivity rather than presence. Note `/fn` sets its own headers directly and CANNOT route through this (a function's error text must never reach an unauthenticated caller), so it shares the CONSTANTS instead - and its two `runner_unavailable` 503s differ on purpose: configured-and-silent carries 5, not-configured-at-all carries nothing. `api/openapi.json` had described that route as simply "carries Retry-After", which was a documented guarantee half of it does not meet.
   **The reason this is worth a note at all is that NEITHER consumer honours the header today** - one keys its retries on status alone, the other does not retry - so the numbers are for future callers and were chosen with the asymmetry stated: too LONG is far more expensive than too short, because a caller honouring 60 s on a transient blip converts a fast error into a stalled transaction, and on the one live public write path recorded here that is an abandoned customer order. The honest framing for a consumer is "read presence as a positive signal and absence as 'a timer is not the fix', never as 'the server forgot, so I will pick a number'".
 - **`FailedPrecondition` means three different things** and must be branched on `FailureDetail.reason`: `missing_parent` and `delete_restricted` are 422, `read_only` is **503**, and an absent or unrecognised reason is **500**, never a guessed 422. Mapping the bare code to 422 told a caller that a read-only database was its own validation mistake, so it would fix its payload and retry forever instead of waiting. Use the `FailureDetail&` overloads wherever a call offers one - the reason-less `Failure` form cannot tell these apart.
@@ -552,6 +552,13 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **Monaco** is bundled locally (`webui/src/monacoSetup.ts`) so the editor works offline - do not revert to the CDN loader.
 - systemd unit is `Type=notify`; the binary must be built with `libsystemd` (it is, when `libsystemd-dev` is present) or change to `Type=exec`.
 
+- **THE SNAPSHOT IS NOT A COMPLETE COPY OF THE DATASET, AND THIS FILE'S OWN "RECOVERY IS SNAPSHOTS PLUS WAL" IS THEREFORE AN INCOMPLETE BACKUP RULE. MEASURED ON PROD 2026-10-22 BY DATABASE 2.20.2's BOOT AUDIT: 7219 ROWS LIVE IN LMDB AND NOT IN THE MEMORYSTORE.** The audit compares LMDB's keys against the MemoryStore's per collection and prints both directions; prod's summary line reads `71 collection(s) compared, 7219 row(s) on disk only, 0 in memory only (349 ms)`, across 40 collections - `default:vectorapi_function_jobs` 3388, `novitax:kb_chunks` 1964, `novitax:sources` 1397, `justice-pa:vectorapi_function_runs` 143, `toloajto:catalog_materials` 70, and 10 of our 11 rows in `default:vectorapi_keys`.
+  **The inference that the snapshot omits them is a measurement rather than a reading of their code, and the control is what makes it one: the audit ran 40 seconds into a boot whose entire store came from a snapshot plus ZERO replayed WAL entries, and the memory check five seconds later reported `0 evicted`.** So nothing could have left memory after the load; if the snapshot had carried those rows they would have been in the MemoryStore and the audit would have found none. **Restore a data directory from `snapshots/` and `wal/` alone and those 7219 rows are gone**, while every reassuring signal stays green - `Recovery complete (TrivialSuccess): 95350 docs in 78 collections` counts what recovery loaded into MEMORY, not what the dataset holds, which is the diff-is-what-hides-it failure this file already records for TTL rows.
+  **I ACTED ON THE WRONG VERSION OF THIS DURING THE WINDOW, AND THE JUSTIFICATION WAS THE PART THAT WAS WRONG RATHER THAN THE OUTCOME.** The `smartbotic-database` preinst takes a FULL data-dir copy and refuses the install when free space is under 1.2x the data dir (6.9 GB data, 8.3 GB wanted, 7.7 GB free), so the upgrade failed on its own safety check. I re-ran it with `SMARTBOTIC_DB_SKIP_BACKUP=1` on the stated ground that my own delta backup - the newest snapshot plus the WAL, md5-verified - was "a proven equivalent", and cited the boot's own `95350 docs` as the proof. That proof measured what recovery loads into memory and could not see the 7219 rows, which were being listed in the very log I was reading. **The deep fallback that was actually complete was the 14:42 full cold copy of the whole data directory, which is 2.5 hours staler and was the real safety net all evening.** Nothing was lost and the reasoning was unsound; the correct ground for skipping would have been "I hold a complete full-dir copy from this afternoon and this is a tested two-way door", which is true and is a different sentence.
+  **So the backup rule is: copy the DATA DIRECTORY. A snapshot plus WAL is the server's own recovery input, not a backup of the dataset**, and the gap grows with however much has ever been evicted - which is invisible, has no trigger, and is largest in exactly the churny collections nobody thinks to check. The package's preinst is right and its space check is a control that fires; overriding it needs a complete copy in hand, not a smaller one that recovers cleanly.
+- **PROD'S DISK NOW BLOCKS EVERY DATABASE UPGRADE BY ITSELF, AND THAT IS A STANDING BLOCKER RATHER THAN A ONE-OFF.** `/` is 50 GB at 83%, the data directory is 6.9 GB and `/var/backups` holds 23 GB - a 6.9 GB full cold copy from 2026-10-22 14:42, the package's own 6.9 GB pre-upgrade copy, a 5.6 GB nightly, a 2.5 GB prune-era copy and an 831 MB October 13 one. The preinst's 1.2x requirement therefore fails before any upgrade starts, and **a deb whose preinst refuses leaves the package at its old version while an `apt-get install` of other packages in the same script succeeds**, so the failure can easily be read as "the window worked" if only the app versions are checked afterwards. It is also entangled with the plaintext-credentials decision (every one of those backups holds readable API keys), so freeing the space and resolving that are the same conversation and both are the owner's call.
+- **THE "ONE ORDERING RULE EVERYWHERE" CLAIM IS NOT TRUE, AND THE EXCEPTION IS A CHECK I ADDED IN 0.17.0 WHILE THE RULE WAS ALREADY WRITTEN DOWN HERE.** This file states the order as authorize, then the server's own capability (501), then the REQUEST (422), then the resource (404), and says a request-level fault no amount of creating the resource fixes must not hide behind the resource. `PUT /documents/{id}`'s `ttl_seconds` refusal sits BEHIND the collection lookup, because the handler calls `scoped()` first and that helper both authorizes and raises the 404. Measured on prod: the same refused parameter answers **422 on a collection that exists and 404 on one that does not**. The cost is small and specific - a caller who misspells the collection never learns the parameter is unsupported, and fixes the name only to meet the 422 afterwards - but it is the exact shape the rule exists to prevent, and the rule was in this file before the check was written. **Writing the rule is not applying it, and the gap is one release.**
+
 ## 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.