Просмотр исходного кода

docs: ask what a collection's writes TRACK, not how big its history is today

A consumer read the per-collection history numbers we sent them and
found a read-driven leak in their own code: a last-retrieved timestamp
patched on every recalled fact on every recall, writing full copies of
documents whose content had not changed, for precision their only reader
never asks for. Their fix coalesces to one version per field per day and
leaves the ranking unchanged by construction rather than by judgement,
which is the detail worth copying.

The class is history that grows with READ traffic: no natural ceiling,
and it looks harmless precisely while nobody is using the feature. Theirs
measured 266 KiB only because the customer had barely used the assistant.

Audited ours and we are clean, though the audit matters more than the
result. The function registry is written only by a code push, setPolicy
and setEnabled, so its 195 MiB over 18 rows is push-driven: put upserts
the whole row including ~199 KiB of script, and ~1000 pushes accounts for
it exactly. vectorapi_keys history measures 0.0 MB, which rules out a
per-request last-used stamp on the key store - the one place this would
have grown with every API call we serve.
fszontagh 1 месяц назад
Родитель
Сommit
31acf4f7d1
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      CLAUDE.md

+ 3 - 0
CLAUDE.md

@@ -250,6 +250,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **And it cannot be done BEFORE the encryption migration.** There is no mode that boots 2.17.1 without migrating - it runs before the listener opens - so "prune first to shorten the migration" is unreachable. Just as well: the prune path had no test against an unmigrated store (**and this note used to add "its test asserts only counts, not that surviving versions decrypt", which is out of date: as of 2.17.1 the e2e test prunes 12 versions to a cap of 3 and reads the newest version's CONTENT back through `getVersionHistory`, plus the live document unchanged, and the unit test asserts exactly the newest 3 per document remain, oldest first and readable, with a second prune to the same cap changing nothing**), so the escape hatch would have exercised new code against old on-disk format in a configuration nobody upgrades into. **The consumer who would have gained most from it was the one who decomposed the question correctly - "can it be deferred" is the easy half, "is the prune path safe against an unmigrated store" is the half that bites - and said they would rather have the long window.** Worth remembering as a pattern: when an optimisation needs a state that only the optimisation produces, the question is never whether you can get into that state.
   **"DISABLE VERSIONING" AND `maxVersions = 0` ARE OPPOSITES, AND OUR OWN PLAN HAD THEM THE WRONG WAY ROUND.** `maxVersions = 0` means **keep unlimited history** - it is the setting that CREATED these files. The off switch is `configureCollection(coll, {versioningEnabled = false})` (client 2.4.5+, settable on an EXISTING collection, and reversible because history already written stays readable). `client.hpp:547` states the distinction outright. Our written plan said "disable versioning by setting maxVersions=0 on the queue and the run log", which would have re-applied the defect while believing it was the fix, and it survived unchallenged until a consumer attached a CONDITION to their approval that forced the mechanism to be checked. **The approval that costs something is the one that finds a defect; an approval that only says yes tells you nothing you did not already believe.**
   **It also follows that disabling versioning RECLAIMS NOTHING.** It stops new versions; the bytes already written stay. Stopping the growth and recovering the space are two operations, and only the second needs a quiet moment. There is **no supported way to discard a collection's history outright** while keeping the collection: the floor is `maxVersions = 1`, which keeps the newest version of every document id ever written, deleted rows included, since history outlives a delete so the row can be restored. `dropCollection` does remove the history file and is not an option for a live queue. A "discard history" operation is upstream ROADMAP.
+  **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.
 - **`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.
 - **A version conflict is `ErrorCode::Aborted`** (client 2.12.0) carrying `currentVersion`, and maps to **409** `version_conflict`. It used to arrive as `Unknown` and fold into 503 "retry as-is", which is the opposite of the required instruction: re-read first. Never match on the message text for this.