Răsfoiți Sursa

docs: /invoke silently discards a bare payload and answers 200

Reported by a consumer and confirmed in code rather than taken on
report: manualTrigger() reads exactly method, path, params, query,
headers and body, and every other key is ignored, leaving ctx.body null.
So POST /invoke with {"day":"2026-10-12"} runs the function with an
empty body and returns 200. {json:...} and a bare JSON string do the
same.

The cost is a false pass rather than a failure. Their re-run looked like
it had processed the day they asked for; the function had processed its
default day, and it surfaced only because a second request for a
different day returned the same day in its result. Only a control with a
differing input could tell.

Another sibling of the unknown_option class, and this one is a JSON body
so the blanket rule applies safely - the query-string caveat about
incidental parameters does not reach a posted body. Filed as #82 to run
the existing unknownKeys() over the envelope.

Also records the second face of the TTL trap, which bit the same
consumer within the hour: an at-most-once marker with a TTL is a guard
for the SCHEDULE, never evidence of what happened. Their daily-report
guard was correct for a cron and wrong the moment a human could re-run an
older day, because after two days no record remained that the mail had
been sent. If a person can re-run it later, the fact has to live
somewhere permanent. It is the mirror of the restore bug one layer up:
once relying on a row that quietly expired, once resurrecting one that
should have.
fszontagh 1 lună în urmă
părinte
comite
accd508f50
1 a modificat fișierele cu 3 adăugiri și 0 ștergeri
  1. 3 0
      CLAUDE.md

+ 3 - 0
CLAUDE.md

@@ -104,6 +104,8 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 
   **But the query string CANNOT take the body's blanket treatment, and that is why this needs design rather than a copy-paste.** Every key in a JSON body is deliberate, so refusing all unknowns is safe. A query string legitimately collects things nobody meant as options - a cache-buster, a proxy's addition, a UI's `_=<timestamp>` - so a blanket 422 would break callers for params that were never asking for behaviour. The defensible line is to refuse the params a caller plausibly sends EXPECTING AN EFFECT and that we do not implement (`offset`, `page`, `cursor`, `sort`, `fields`), and to keep ignoring genuinely incidental ones. Refusing `offset` is the point; refusing `_=1760000000` is a regression.
 - **An unknown key on a vector `/search` body is REFUSED (422 `unknown_option`), not ignored** (`functions/known_keys.hpp`, pure). It was ignored until 0.10.3, and measured on prod that produced silently wrong answers rather than errors: `topK: 3` returned the DEFAULT five rows, `minScore: 0.99` returned rows where the correct spelling returns none, and **`filter:` in the singular returned the rows the caller meant to EXCLUDE** - a dropped filter is frequently a tenancy boundary in the caller's mind, which is what makes this a defect and not an ergonomic wish. Every unrecognised key is named at once, and the accepted set is listed, because the usual cause is a plausible spelling of a real option. Matching is exact and case-sensitive on purpose: accepting `Top_K` would give the service two spellings for one option, which is how the next drift starts. `ctx.fetch`, `ctx.mail` and `ctx.jobs` already behaved this way; this brought the HTTP surface in line.
+- **`POST /functions/{id}/invoke` TAKES AN ENVELOPE, AND A BARE PAYLOAD IS SILENTLY DISCARDED WITH A 200 - ANOTHER SIBLING OF THE `unknown_option` CLASS, STILL UNFIXED.** Reported by a consumer 2026-10-15 and confirmed in code: `manualTrigger()` (`handlers/functions.cpp:146`) reads exactly `method`, `path`, `params`, `query`, `headers` and `body`, and **every other key is ignored**, leaving `t["body"]` null. So `POST .../invoke` with `{"day":"2026-10-12"}` runs the function with an EMPTY `ctx.body` and answers **200**. `{json: ...}` and a JSON string do the same. The correct envelope is `{"body": {...}}`.
+  **The cost is a false pass, which is worse than a failure.** Their re-run "looked like it had processed the day I asked for", and the function had quietly processed its DEFAULT day; it surfaced only because a second request for a DIFFERENT day returned the same day in its result. A control that returns 200 for an input it discarded cannot be distinguished from one that worked, which is exactly the shape `unknownKeys()` exists to prevent on the vector `/search` body. **This is a JSON BODY, so the blanket rule applies and is safe** - the query-string caveat about incidental parameters does not reach here, since every key in a posted body is deliberate. Fix is to run the existing `unknownKeys()` over the invoke envelope and 422 with the accepted set named, which is the same idiom and the same error shape. Their suggestion is worth taking too: echo which input the run actually used, so the answer carries its own evidence.
 - **`embedTimeoutMs` on `.search()`/`.store()` is validated, not coerced.** A non-integer or non-positive value is 422, and exceeding it is **504** `embedding_timeout` (distinct from the run simply running out of budget, because the remedies differ). It went unnoticed for a release while being silently accepted and ignored, which is exactly why an unsupported option must be refused rather than dropped.
 - **Wall time has TWO ceilings** (`functions/wall_budget.hpp`): an HTTP one (~2 s, which `RunnerPool::readTimeoutSec` must exceed) and a JOB one, which is exempt because a queue-claimed run holds no socket. `RunService::run` takes the kind as a PARAMETER, never inferred from the descriptor, and defaults to Http - the narrow budget - so a caller that forgets is slow rather than dangerous. Precedence: `min(descriptor timeoutMs or default, project max or kind ceiling, hard ceiling)`, resolved by the pure `resolveWallBudget()`. **The project cap is per kind** (`{http, job}` on `PUT /projects/{p}/settings/functions`): one number could not express "10 s for routes, 60 s for jobs", so capping a project's routes also cut its cron work and the only safe setting was no cap. `FunctionView` carries BOTH and `RunService::run` selects, because `lookup()` does not know how a run was triggered. The engine's `JsLimits::wall_time_ms` is raised to the highest ceiling at construction, or the clamp inside `JsRuntime::run` would kill every job at the HTTP value.
 - **Job runs draw from their OWN pool lane.** A lease is held for a run's whole duration, every `ctx.fetch` included, so without a lane N slow jobs leave one runtime for every interactive route and the second overlapping HTTP run blocks until the read timeout fires - a 503 from a healthy runner. Worst-case memory is `(pool + job_pool) x memory_limit_bytes`, so the two lanes ADD.
@@ -308,6 +310,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **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.
   **IF ONLY ONE SENTENCE OF THIS IS EVER DOCUMENTED, MAKE IT THIS: THE DIFF IS WHAT HIDES IT.** The consumer's framing, and it is better than mine. The operator at risk is not the one who reads the docs - it is the one whose restore LOOKS perfect. Every id back, every count matching, the verifier green, and a set of permanent markers quietly suppressing the work they were meant to guard for 48 hours. Their own run reported `1341 already present` and would have said nothing at all about the single row that mattered. So every reassuring signal a careful operator would check is intact while the damage is done, which is the same shape as a digest that matched while the ordering was wrong.
+  **AND THE SAME TRAP HAS A SECOND FACE, WHICH BIT THE SAME CONSUMER AGAIN WITHIN THE HOUR: AN AT-MOST-ONCE MARKER WITH A TTL IS A GUARD FOR THE SCHEDULE, NEVER EVIDENCE OF WHAT HAPPENED.** Their daily report used a 48-hour marker for "have we already sent today's mail", which is correct for a cron and wrong the moment a HUMAN can re-run an older day: after two days there is no record the mail ever went out, so a manual re-run sends it again - in their case to a list that had since grown beyond the original recipients. Four days were stored and mailed and only the two most recent still had a marker. **If a person can re-run the thing later, the fact has to live somewhere permanent**; the marker only answers "is the schedule allowed to fire now". Note it is the mirror of the restore bug one layer up: once relying on a row that has quietly expired, once resurrecting one that should have.
 - **VERIFYING A RESTORE: a row count and an id set cannot see the failure that matters.** They prove something was stored under the right names. A vector can be byte-perfect in the file, stored under the wrong field or in the wrong form, read back flawlessly and rank nowhere. A consumer's restore test is the model: every restored row must be **its own nearest neighbour at score 1.000000**, and the same `query_vector` must score a row **identically** in the restored and original collections (they measured a delta of 0.00e+00). Only retrieval BY SIMILARITY exercises what a vector is for - which is the same lesson as a digest that matched while the ordering was wrong.
 - **Document write bodies accept two shapes, via one reader.** `documentBody()` in `handlers/documents.cpp` is used by POST, PUT and PATCH: it unwraps `{"data":{...}}`, strips `id` (the document's identity, from the body on POST and from the URL on PUT/PATCH), and rejects `data` alongside any other top-level key with **422** `ambiguous_body`. Before 0.3.3 only POST unwrapped, so a `{"data":...}` PUT stored the wrapper as a literal field and a `data`-plus-siblings POST dropped the siblings silently. A literal top-level `data` field is still writable as `{"data":{"data":...}}`.
 - **QuickJS is pinned to an exact quickjs-ng tag** (`SVAPI_QUICKJS_TAG`, `runner/CMakeLists.txt`). QuickJS bytecode carries **no version stamp**, so a silent upgrade makes a cached blob *misread* rather than fail. quickjs-ng, not Bellard's tree: the module/promise/stack entry points the core needs (`JS_GetModuleNamespace`, `JS_PromiseState`, `JS_SetMaxStackSize`, `JS_IsJobPending`) are public API there. `JsBytecode` is an in-process cache only - never persist it without a QuickJS build fingerprint.