ソースを参照

docs: a suggested schema encodes existing drift as if it were intended

NOT IN THE PUBLISHED 0.13.0 - that version is already in the apt repo and a
published number is never reused for different content. Ships with curl
tomorrow.

A consumer named a caution about schema/suggest that is sharper than the one
I documented. I had written that it never applies what it suggests and that
lengths and ranges are described rather than enforced. The more important
half: a schema inferred from the CURRENT rows encodes whatever is already
wrong as if it were intended. If a year field holds a stringified number
anywhere, suggest faithfully proposes type string - so applying a suggestion
unedited blesses the exact drift you were trying to find.

Which makes audit mode the more informative of the two, and they changed
their adoption plan on it: suggest tells you what the data looks like, while
setting a schema you CHOSE in audit mode tells you what it would have
rejected. The second is usually the question. On a populated collection it is
also the safe order - audit first, enforce once the counts are clean.

Also records a lesson from the same exchange: STATE THE RULE, NOT THE LIST. I
announced that index-values "now refuses offset, page, cursor, sort, fields,
after, skip", and a consumer had to gate their deploy approval on asking
whether it was a shared query-string validator, because they send offset and
sort to the documents listing where both are load-bearing. The rule is
"refuse what you cannot honour" - the documents route implements both, the
values route's client call has no offset parameter at all - and stated that
way the scope is derivable instead of something each consumer must ask about.

Paired with the verification half, because answering it needed both: reading
opts.offset = parseUInt(...) proves the parameter is CONSUMED; disjoint
page1/page2 proves it is HONOURED. Different claims.
fszontagh 1 ヶ月 前
親
コミット
ec044f5f54
3 ファイル変更、4 行追加、2 行削除
  1. 2 0
      CLAUDE.md
  2. 1 1
      api/llms.txt
  3. 1 1
      api/openapi.json

+ 2 - 0
CLAUDE.md

@@ -56,6 +56,8 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **A PERMISSIVE TEST ASSERTION'S STRENGTH DEPENDS ON THE SERVER'S STRICTNESS, so tightening a contract can silently promote a sloppy test elsewhere into a blind spot.** A consumer found this while checking whether the `unknown_option` refusal would break them: a test asserting their outgoing body with `expect.objectContaining({...})` tolerated extra keys by construction, so it could only ever fail in the direction that was already safe - add a stray key and the test stays green while production starts refusing every search with 422. They tightened it to an exact match. The lesson for asking consumers about a breaking change: the question is not only "do you send an extra key" but **"would your tests notice if you started"**.
 - **AN UNMEASURED CLAIM INHERITS THE CREDIBILITY OF ITS NEIGHBOURS. In a message where most assertions carry a file and line, the one that does not reads just as authoritative - and is believed just as hard.** 2026-10-13: I answered a consumer's four measured filter questions by citing `src/filters.cpp:33-38` for each, and in the same breath recommended `field:exists:true` as a guard against nulls in a range filter. I had not checked it. It is wrong - a field holding an explicit `null` EXISTS, so `exists` excludes only the absent case, which was never the problem. They put it in a spec and called it "strictly better" than the pair-of-bounds form they had actually tested.
   **Both halves of that are the same mechanism and worth naming separately.** Mine: I was pleased with a clean one-operator answer and did not notice I had stopped citing. Theirs, in their words: they had measured four behaviours precisely so as not to record a guarantee nobody had made, then took a fifth on trust because it was the answer they wanted - so **"thanks are a signal to re-read, not to proceed."** The practical rule for this file and for any reply to a consumer: **if a claim has no file, line or measurement behind it, say so in the same sentence.** An unqualified sentence sitting between two cited ones is the most dangerous shape a wrong claim can take.
+- **STATE THE RULE, NOT THE LIST - a list of names makes the blast radius something each consumer has to ask about.** I told consumers that the index-values route "now refuses `offset`, `page`, `cursor`, `sort`, `fields`, `after`, `skip`", and a consumer had to gate their deploy approval on asking whether it was a SHARED query-string validator, because they send `offset` and `sort` to the DOCUMENTS listing where both are load-bearing. The rule is **"refuse what you cannot honour"**: the documents route IMPLEMENTS both, so accepting them is correct, while the values route's underlying client call takes `(collection, field, limit, ascending)` and has no offset at all, so accepting them was the defect. Stated that way the scope is DERIVABLE; stated as seven names it reads like a generic set and invites exactly the question it got.
+  Worth pairing with the verification lesson, because answering it needed both: reading `opts.offset = parseUInt(...)` proves the parameter is CONSUMED, and disjoint page1/page2 proves it is HONOURED. Different claims, and this whole week turned on the gap between them.
 - **THE ONE QUESTION THAT CATCHES THIS WHOLE FAMILY: "WHAT ELSE WOULD PRODUCE THIS EXACT RESULT?"** It is one line, it costs nothing, and on 2026-10-12 three separate instances of the same defect appeared in a single afternoon - two of them mine - every one of which it would have stopped:
   - **A vector-encryption test** read rows written BEFORE the flag was flipped and concluded about writes after it. What else would produce three rows still searching at 1.0? Pre-flip vectors living in the vector sub-db rather than the body. Which is exactly what was happening, and the new-insert path was broken.
   - **A consumer's page probe** returned 200 at 5.4 MiB and they concluded the size limit was per DOCUMENT. What else would produce that? A per-RESPONSE limit anywhere above 5.4 MiB - which is what it is, 100 MB. A test that passes under both hypotheses cannot choose between them.

+ 1 - 1
api/llms.txt

@@ -138,7 +138,7 @@ An OPTIONAL per-collection JSON Schema, validated on every write. All four route
   **`mode` DEFAULTS BY WHETHER THE COLLECTION HOLDS DATA**, and the asymmetry is deliberate: `enforce` on an EMPTY collection (it cannot fail, and a live contract is what you want) and `audit` on a POPULATED one (enforce usually refuses on real data, and the counts are what you need first - defaulting to enforce there would make the common case look broken). `mode_defaulted` tells you which rule applied, so you never have to infer it.
   In `enforce` mode one non-conforming row refuses the whole change: **422 `schema_violation`** with `details.rows_checked`, `details.violating_rows` and up to ten `details.examples` of `{id, message, fields}`. A schema outside the supported subset is **422 `invalid_schema`** instead - a different slug on purpose, because one says fix your schema and the other says fix your data.
 - `DELETE /api/v1/projects/{project}/collections/{name}/schema` - Remove it; writes stop being validated. **Idempotent** - removing a schema that is not there reaches the requested end state, so it is 200, not 404.
-- `GET    /api/v1/projects/{project}/collections/{name}/schema/suggest?sample_limit=N` - A schema generated FROM the data as a starting point (project-manage; it scans). Answers `{schema, rows_scanned, complete, applied}`. **`applied` is always `false`: this NEVER applies what it suggests.** Lengths and ranges are only described rather than enforced, so arming it unseen would create something that looks stricter than what it checks - edit it, then PUT it. `complete: false` means it was built from a sample, so a field absent from the suggestion may still exist in the data; it is emitted unconditionally, so absence means only "older server".
+- `GET    /api/v1/projects/{project}/collections/{name}/schema/suggest?sample_limit=N` - A schema generated FROM the data as a starting point (project-manage; it scans). Answers `{schema, rows_scanned, complete, applied}`. **`applied` is always `false`: this NEVER applies what it suggests.** Lengths and ranges are only described rather than enforced, so arming it unseen would create something that looks stricter than what it checks - edit it, then PUT it. **AND READ A SUGGESTION AS EVIDENCE ABOUT WHAT IS THERE, NEVER AS A PROPOSAL FOR WHAT SHOULD BE: it encodes whatever is already WRONG as if it were intended.** If a `year` field holds a stringified number anywhere in the collection, `suggest` faithfully proposes `"type": "string"` - so applying a suggestion unedited blesses the drift you were trying to find. That makes **audit mode the more informative of the two**: `suggest` tells you what the data looks like, while setting a schema you CHOSE in `audit` mode tells you what it would have rejected. The second is usually the question, and on a populated collection it is also the safe order - audit first, enforce once the counts come back clean. `complete: false` means it was built from a sample, so a field absent from the suggestion may still exist in the data; it is emitted unconditionally, so absence means only "older server".
 
 **A WRITE refused by the schema is 422 `schema_violation` on the DOCUMENT routes** - insert, update, upsert, patch (judged on the MERGED result, so a small body can trip it), increment, batch and restoreVersion. **`error.details.fields` is ALWAYS AN ARRAY, even for a single path, and `field` is never present on this slug** - unlike `duplicate_values`, which singularises. That is deliberate: several violating paths is the ordinary case here, so `details.fields.forEach(...)` has to work for one path too. The paths are dotted and indexed (`addr.zip`, `tags[2]`). The values are deliberately NOT echoed back, so nothing sensitive is reflected; the message names the rule and the size.
 

+ 1 - 1
api/openapi.json

@@ -5065,7 +5065,7 @@
         "tags": [
           "documents"
         ],
-        "description": "Project-manage, because it scans the collection and exists to author a contract rather than satisfy one. It NEVER applies what it suggests - applied is always false. Lengths and ranges are only described rather than enforced, so arming it unseen would create something that looks stricter than what it checks: edit it, then PUT it. complete:false means it was built from a sample, so a field absent from the suggestion may still exist in the data; it is emitted unconditionally, so absence means only an older server.",
+        "description": "Project-manage, because it scans the collection and exists to author a contract rather than satisfy one. It NEVER applies what it suggests - applied is always false. Lengths and ranges are only described rather than enforced, so arming it unseen would create something that looks stricter than what it checks: edit it, then PUT it. complete:false means it was built from a sample, so a field absent from the suggestion may still exist in the data; it is emitted unconditionally, so absence means only an older server. AND read a suggestion as evidence about what IS in the data, never as a proposal for what should be: it encodes whatever is already wrong as if it were intended - a stringified number anywhere in a field makes it propose type string - so applying one unedited blesses the drift you were looking for. Setting a schema you CHOSE in audit mode is the more informative move: suggest says what the data looks like, audit says what your schema would have rejected.",
         "parameters": [
           {
             "name": "project",