Browse Source

docs: snapshot-sequence monotonicity is the check validation cannot replace

2.21.1 fixes two races found by refusing to call a 1-in-7 flaky test noise.
Our exposure to the eviction one is currently nil because prod has stopped
evicting (0 evicted, against 33000 on 10-20 under 2.17.2) - a defect whose
precondition is a resource state, so the exposure moves with no deploy.

My framing that validation narrows the concurrent-snapshot race to a refused
rather than corrupt snapshot was too reassuring and they corrected it: a valid
file from one writer paired with the other's truncation point is invisible to
validation. The fingerprint is sequence monotonicity - 414 completions, all
increasing, no instance - and the boot identity is self-consistent whatever
was lost, so it cannot substitute.

Prod has run the pairing once with a 47-second margin, which is the strongest
argument for serializing the writers and comes from a real deployment.
fszontagh 1 tháng trước cách đây
mục cha
commit
f45d1b9697
1 tập tin đã thay đổi với 7 bổ sung và 0 xóa
  1. 7 0
      CLAUDE.md

+ 7 - 0
CLAUDE.md

@@ -601,6 +601,13 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   - **THE LAST TWO `exists()` PROBES ARE GONE, AND THE CONTRACT CHANGE THE TASK ASSUMED WAS NECESSARY WAS NOT.** The task said `bool` cannot express "the call failed" so a signature change was required. It is not: the function THROWS for a transport failure and keeps `bool` for the genuine present/absent answer, exactly as `CollectionRegistry` already does. `remove()`'s `Failure&` form distinguishes them - code `Ok` with a false return means "did not apply". **Worth generalising: before accepting that a return type must change, check whether the exceptional case is actually exceptional.**
   **Two instrument failures from the same evening, both caught by controls rather than by review.** A test I wrote against an invented fixture (`StoreFixture`, `db()`, `coll()`) that this project does not have - the file uses `SVAPI_REQUIRE_DB(db)` and bare `TEST()`; and extending the error mapping into a narrow test target needed a `Client::errorDetail` stub, whose first version omitted `noexcept` and failed to compile against the declaration. Neither reached a commit, both cost a build cycle, and the lesson is the cheap one: read the file's own idiom before adding to it.
 
+- **A SNAPSHOT RACE WE HAVE NOT HIT, A NEAR-MISS WITH A 47-SECOND MARGIN THAT WE HAVE, AND A CHECK THAT DISCRIMINATES WHERE VALIDATION CANNOT.** Database 2.21.1 fixes two races found by refusing to dismiss a 1-in-7 flaky test as noise - which is the headline lesson and belongs to them: **(a)** eviction removed a document from memory a moment before recording its stub, so a snapshot could write it as DELETED, and **(b)** the shutdown's final snapshot and the periodic one could run at once and clobber each other's file within a second. Neither is pinned by a test, stated plainly by them: once in ~20 runs, and the mutex revert passed 10/10, so a test there would be a coin flip pretending to be a check.
+  **OUR EXPOSURE TO (a) IS CURRENTLY NIL AND WAS REAL, AND THE DECIDING QUANTITY IS EVICTION.** The memory check now reads `95831 docs, 0 evicted` at 46% of budget, where on 2026-10-20 under 2.17.2 it read `52584 docs, 33000 evicted` - the streaming writer removed the pressure that drove eviction. So this is "promptly, not urgently", and it returns the day the store outgrows the budget again. Note the shape: a defect whose precondition is a RESOURCE STATE, so the exposure moves on its own with no code change and no deploy.
+  **MY FIRST FRAMING OF (b) WAS TOO REASSURING AND THEY CORRECTED IT.** I wrote that `validate_after_write` plus `cleanup_only_if_verified` narrow (b) to "a refused snapshot rather than a corrupt one". That is true of the failure they observed - the writer deletes the file and throws, so the WAL is not truncated and older snapshots are kept - and it is NOT true of every interleaving. The one they cannot exclude: **a valid, complete file from one writer passes verification while the OTHER writer's sequence is the one used to truncate the WAL, so the writes in between are in neither.** Validation cannot see that, because the file it checks is genuinely fine. Improbable, not impossible, and the reason 2.21.1 serializes the writers instead of trusting validation.
+  **THE FINGERPRINT FOR THAT CASE IS SNAPSHOT-SEQUENCE MONOTONICITY, AND THE BOOT IDENTITY CANNOT SUBSTITUTE FOR IT.** If A's file is kept while B's sequence truncates, the `Created snapshot at sequence N` series stops increasing. Measured: **414 completions retained, strictly increasing from 70,672 on 10-03 to 762,091 on 10-22 - no instance.** The boot arithmetic this file already recommends (`Replayed N from sequence X` plus `WAL sequence X`) is **self-consistent whatever was lost**, so a clean recovery line is not evidence either way - it reads like evidence, which is exactly why that has to be written down next to it.
+  **AND PROD HAS RUN THE PAIRING, 47 SECONDS CLEAR.** Hunting back-to-back EQUAL sequences found 91; 87 are ~3600 s apart (an idle hour, the timer firing with nothing written - benign), three are 180-710 s, and **one is 51 s apart and is the periodic snapshot followed by the shutdown's final one**: `10:46:41 Created snapshot at sequence 96309`, `10:47:28 Received signal 15`, `10:47:32 Created snapshot at sequence 96309 / Final snapshot taken on shutdown`. Same two writers, same state, both completing, separated by 47 s of luck rather than by any mechanism. On a slower snapshot or an earlier stop that is an overlap.
+  **The count on its own meant nothing, and I nearly reported it: "91 back-to-back equal sequences" sounds alarming and is almost entirely idle hours. Only the GAP DISTRIBUTION separates an idle timer from two writers at the same state** - median 3604 s, min 51 s. A frequency without its distribution is the same error as a rate without its base rate.
+
 ## 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.