浏览代码

docs: _expires_at is readable from client 2.19.0 and works against our 2.17.2 server

The server had always sent Document.expires_at; the client was dropping
it. So the TTL export/restore gap needs only a DB_CLIENT_VERSION move,
not a database upgrade, and the ABI move is additions-only.

Records the restore rule that closes the immortal-marker defect: absent
means no TTL, a past value means SKIP the row, otherwise compute
ttlSeconds from the delta. Also that the value can legitimately be in the
past - lazy sweep, a restrict relation holding a row, or a copy taken
while the server was stopped - which is the consumer's 121-hour row.

And one thing to fix independently of the pin: _expires_at is reserved
from 2.19.0 but is not in dbMetadataFields(), so a caller posting it
today has it stored as an ordinary user field. That is the shadow-copy
trap the list exists to prevent, and adding it costs a caller nothing
because they could never read their own value back.
fszontagh 1 月之前
父节点
当前提交
da675cb95a
共有 1 个文件被更改,包括 6 次插入 和 0 次删除
  1. 6 0
      CLAUDE.md

+ 6 - 0
CLAUDE.md

@@ -307,6 +307,12 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **A VECTOR COLLECTION'S INSERT GUARD USED TO COMMIT THE EXACT BUG IT EXISTS TO PREVENT.** `vector_missing` accepted a body carrying either `_vector` OR `vector`, while the documents route stores the body verbatim and a search reads `_vector`. So a row written with `vector` got a 201 and was then findable by NO search - the unsearchable junk row the guard was written for, admitted by the guard. Measured with two rows inserted under the two spellings from the same vector: only the underscored one came back. Now refused, with a message that also says to REWRITE any row already stored that way, because a caller who hit this has unfindable rows behind them and silently fixing only their next write would leave those while looking solved. Found by a consumer asking which field a RESTORE should write - the question exposed it, not a test.
 - **AN ERROR'S WORST READING IS THE ONE IT WILL GET UNDER PRESSURE.** Feeding an export's `vector_b64` back into the documents route used to answer "a document must carry `_vector`" - accurate, and read by someone restoring a 294 MB file at 3am as **"my backup has no vectors"**, which is indistinguishable from real data loss and will be believed. A consumer named that misreading after doing the restore. The message now names the export's own field, states that the backup is FINE, and says to expand the base64 - and a test asserts the ORDINARY missing-vector case does NOT mention a backup, so the reassurance cannot be given where it would be a lie. The general rule: when an error can be read as "your data is gone", say explicitly that it is not.
 - **The export writes base64 and no insert route reads it.** `vector_format=base64` emits `vector_b64`; `POST .../documents` wants `_vector` as a number array and `POST .../vectors` wants `vector` as a number array. So the one path a backup exists for does not round-trip without expanding the base64 first, and the 422 a caller gets names what is MISSING rather than the good vector sitting in the field the exporter wrote. Documented in `api/llms.txt`; whether to accept a base64 write form is open.
+- **`_expires_at` IS READABLE FROM CLIENT 2.19.0, AND IT IS A *CLIENT* FEATURE - IT WORKS AGAINST OUR 2.17.2 SERVER.** The server had always sent `Document.expires_at` (absolute ms since epoch); the CLIENT was dropping it. So the fix to the TTL gap below needs only a `DB_CLIENT_VERSION` move, not a database upgrade, and the ABI move is additions-only (one constant, soname 2, symbols file unchanged).
+  - `get`, `find` and `exportCollection` attach `_expires_at` when a document HAS an expiry, and omit it otherwise. **Absent means "no expiry", never zero.**
+  - **It can legitimately be in the PAST**, which is the whole point: the sweep runs every second, a `restrict` relation can hold a row past its TTL, and a copy taken while the server is stopped keeps expired rows until a server opens it. That is exactly the "121 hours past its deadline" row a consumer met.
+  - **The restore rule, which closes the immortal-marker defect:** absent → insert with no TTL; in the PAST → **skip the row**; otherwise `ttlSeconds = ceil((_expires_at - now)/1000)`.
+  - Filtering on it (`lt`, `exists`) needs a 2.19.0 **SERVER** (capability `document_expires_at`), so it is NOT available on prod today - reading it is, filtering is not. A row with no expiry is ABSENT for those filters rather than 0, so an upper bound cannot sweep up permanent rows.
+  - **IT IS RESERVED AND OUR STRIP LIST DOES NOT KNOW IT YET.** `dbMetadataFields()` (`documents_util.hpp:36`) lists six names and `_expires_at` is not among them, so on our current client a caller posting `{"_expires_at": ...}` to `POST .../documents` has it stored as an ordinary user field - precisely the shadow-copy trap that list exists to prevent, where every read overwrites the stored value and no filter can reach it. A 2.19.0 client strips it on write on both sides, but **add it to `dbMetadataFields()` regardless and independently of the pin move**: it is reserved from 2.19.0 onward, the cost to a caller is nil (they could never read their own value back), and doing it early means no row is ever written carrying one.
 - **TTL EXPIRY IS LAZY, SO A BACKUP LEGITIMATELY HOLDS ROWS THE LIVE PROJECT NO LONGER HAS - AND ANY BACKUP-VERSUS-LIVE COMPARISON READS THAT AS DATA LOSS.** Found by a consumer verifying their own backup right after a platform window, which is the worst possible moment to meet it: their tool reported `reminders_sent: 1 NOT in the live project`, which reads exactly like we lost a row during the maintenance. We had not. The row was an idempotency marker with a 48-hour TTL that expired 2026-10-10, was **still physically present in a backup taken 121 hours past its deadline**, and had been reaped by the time they verified an hour later. So the same row is present or absent depending on when the reaper happened to run, not on whether anything was lost.
   **There is NO supported way to read a document's REMAINING TTL** - audited in `client.hpp`: `ttlSeconds` appears on insert/upsert, `patchWithTtl` and `setFileTtl`, all WRITE paths, and `CollectionInfo::defaultTtlSeconds` is the COLLECTION's default rather than a row's expiry. So inferring from row age against a table of known TTLs is currently the only method, which is sound but needs the caller to know every TTL they ever set. Requested upstream.
   **THE SHARP EDGE IS ON RESTORE, AND IT IS OURS TOO: A RESTORED ROW CARRIES NO TTL, SO PUTTING AN EXPIRED ROW BACK MAKES IT IMMORTAL.** For their idempotency markers that meant a restore would permanently suppress the work the marker guards. Our own export has the same shape - nothing in it carries a TTL, because nothing can read one - so **a restore through `POST .../documents` resurrects expired rows as permanent ones**, and the more faithful the restore looks (every id back in place) the more complete the damage. Their fix is the right pattern for anyone restoring from our export: leave expired rows OUT, and say so in the output (`0 row(s) put back, 1341 already present, 1 expired left out`) rather than silently.