浏览代码

fix: this file said the /fn throttle was CLOSED, and prod has never had it

Measured from the public internet with no credential of any kind:

  POST https://qdrant-1.../rag/fn/novitax/aliz/kb-search  body {}  no auth
    -> 200 in 0.106s
  control: same shape, function id that does not exist      -> 404

So a tenant's live function runs anonymously, and the control proves it is a
real function rather than a catch-all. Prod cannot refuse it: read from the
source at the 0.13.0 revision, function_dispatch.cpp has ZERO references to
rateLimiter and no key gate. The throttle landed in 696b431, which is an
ancestor of the built 0.16.0 deb and is NOT in prod's 0.13.0.

This is the committed/released/deployed confusion this file already warns
about, committed by this file, about a security control - and 0.15.0 was never
published, so the ceiling has not existed in production on any day since the
gap was found. Three live functions sit behind a voice agent with the URL in a
VAPI config, ctx.mail and ctx.fetch are outside the policy, and the only thing
bounding abuse today is that nobody has tried. SV-19.

The repair that generalises: record the ARTEFACT a fix is in, never the
version it "shipped" in. The second is a claim about the world; the first is
checkable with git merge-base --is-ancestor.

Found while answering whether /fn can be added to the customer-facing host's
whitelist. It can, and the answer is after the deploy rather than before -
today it would duplicate an anonymous unthrottled surface onto the one
hostname we deliberately kept narrow.

Also recorded, from the same consumer: their 6000ms embed budget sits exactly
on our ~6s cold path, so the first call of a quiet period is a coin flip -
6.037s succeeded and 6.547s failed on the same query minutes apart. Their
lesson is the better one: two observations looked identical and the identity
was the thing to be suspicious of. Their degraded returns had at least two
causes (our hourly stall, their boundary) and they had written up a third that
morning, so when a consumer reports an intermittent fault the question is not
which cause it is but how many it has.
fszontagh 1 月之前
父节点
当前提交
02c55b8d9f
共有 1 个文件被更改,包括 6 次插入 和 1 次删除
  1. 6 1
      CLAUDE.md

+ 6 - 1
CLAUDE.md

@@ -120,7 +120,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **Routes:** functions are managed at `/api/v1/projects/{p}/functions*` (project-manage; **policy is admin-only**) and served to the world at **`/fn/{project}/*`**, which is **unauthenticated** - the project segment is therefore hostile input: charset-restricted (no `:`, the `qualify()` separator), confirmed against `listProjects()` before anything qualifies a collection, and a `..` segment is refused anywhere (httplib percent-decodes before the handler sees the path, and `..` can be captured by a `:name` param). Disabled and invalid functions are absent from the descriptor list, so they 404 rather than 403, and function error text never reaches the caller - it goes to the run log, with the `run_id` in the response.
 - **`/fn` IS UNAUTHENTICATED *AND* UNTHROTTLED, AND THE SECOND HALF SURPRISES PEOPLE WHO READ THE FIRST.** Verified in code 2026-10-13, prompted by a consumer asking how to send a verification e-mail: `function_dispatch.cpp` never touches `rateLimiter()`, and the policy's `rate_limit_per_min` is enforced only inside `requireCapabilityCore` - that is, on the function's DATA access through `ctx.collections`. **`ctx.mail` and `ctx.fetch` are outside the policy entirely** (a function with `rules: []` can still send mail, which is recorded above as a deliberate decision). So a published function that sends mail or makes an outbound call is reachable by anyone who learns the URL, with no per-function ceiling: an e-mail bomb aimed at any address, on the tenant's SMTP quota and sender reputation, or a paid API burned.
   The unauthenticated part is a design decision and still right - a published HTTP function is published. **The unthrottled part was not a decision, it was a gap**, and the field that looked like it covered it did not. I believed it did when I started answering.
-  **CLOSED IN 0.15.0, both halves, and the lesson is kept because the shape recurs.** `rate_limit_per_min` is now charged on `/fn` as well as on data access, and a function can require a key with `auth: 'key'` in its `on` block. Five decisions in that fix are load-bearing:
+  **CLOSED IN 0.15.0 IN THE ARTEFACT AND STILL OPEN IN PRODUCTION AS OF 2026-10-22 - THIS ENTRY SAID "CLOSED" AND PROD RUNS 0.13.0.** Measured from the public internet with no credential: `POST https://qdrant-1.../rag/fn/novitax/aliz/kb-search` with body `{}` and no `Authorization` answered **200 in 0.106 s**, with the control - the same shape against a function id that does not exist - answering **404**, so it is a real function running rather than a catch-all. Read from the source at the 0.13.0 revision rather than from these notes, `src/handlers/function_dispatch.cpp` there contains **zero** references to `rateLimiter` and no key gate; the throttle landed in `696b431`. By the two-command instrument: `696b431` IS an ancestor of the built 0.16.0 deb and is NOT in prod's 0.13.0.
+  **So this is the committed/released/deployed confusion this file warns about, committed BY this file, about a security control.** "Closed in 0.15.0" reads as the third and was only ever the first - and 0.15.0 was never published, so the control has not existed in production on any day since the gap was found. Three live functions behind a voice agent are reachable at a URL in a VAPI config, with `ctx.mail` and `ctx.fetch` outside the policy, and the only thing bounding abuse today is that nobody has tried. Tracked as SV-19, which also carries the separate question of adding `/fn/` to the customer-facing host's whitelist - correctly answered "after the deploy, not before", since adding it today would duplicate an anonymous unthrottled surface onto the one hostname we kept narrow.
+  **The generalisable repair is to write the ARTEFACT the fix is in, never the version it "shipped" in**, because the second is a claim about the world and the first is checkable with `git merge-base --is-ancestor`. The lesson below is kept because the shape recurs.** `rate_limit_per_min` is now charged on `/fn` as well as on data access, and a function can require a key with `auth: 'key'` in its `on` block. Five decisions in that fix are load-bearing:
   - **AUTHENTICATE FIRST, THROTTLE SECOND.** The reverse lets an anonymous flood spend a function's whole minute budget and lock out the one caller holding a key - a denial of service achieved by being refused. Ordering it this way rejects that flood without charging the bucket the legitimate caller shares.
   - **The two ceilings are counted in SEPARATE buckets against the same number.** One shared bucket would make the limit mean something nobody intends: a function doing three reads per request would spend four tokens per call, so a limit of 60 would admit 15 requests and **adding a read to a script would silently lower its own request ceiling**. That is the same mistake as charging a listing one token per collection examined, which this file already records fixing once.
   - **`auth` defaults to `public` and an unrecognised VALUE is REFUSED**, while an unknown KEY in the `on` block stays ignored. Both are deliberate and they pull in opposite directions: an unknown key is a script written for a newer server and must still load, whereas `auth: 'kye'` falling back to public would publish a function whose author believed it was gated. A typo must never widen access. Note the honest limitation: **an older server ignores the key entirely, so a gated function deployed backwards is silently public** - the one place forward-compatibility cuts against safety.
@@ -453,6 +455,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 
 - **`Client::get` returns nullopt for BOTH "absent" and "transport failed"** - it throws only for PERMISSION_DENIED - so a registry lookup cannot tell them apart from the return value. Unhandled, that reaches a caller as 404 "no such collection" for a collection that exists, and a 404 is unretryable BY DESIGN for a careful client, because adding it to a retry set would retry every genuine absence. A consumer lost a 6-minute ingest of an 8 GB mailbox to exactly this. `CollectionRegistry::get` therefore **retries once** (a transient failure usually succeeds, and logs a warning saying so) and then asks `healthCheck()` before reporting absence, throwing **503** when the database is unreachable. Reported upstream too: the client should distinguish, the way it already does for a permission denial.
 - **A REPRODUCIBLE vector-search baseline needs an explicit `query_vector`. Pinning `query_text` is NOT enough.** `query_text` is embedded server-side through the external provider on *every* call - there is no query-embedding cache (`emb.embed(cfg.model, text)` in `handlers/vectors.cpp`), so the same text can yield a different vector on a different day and every score and row count moves with it. Measured by a consumer across one deploy over a byte-identical collection (12447 rows unchanged): an unfiltered top score went 0.7221 to 0.7175 and a filtered count 424 to 426, while five consecutive calls agreed to six decimals - so it is drift in text→vector, not per-call noise. The isolating test: a fixed explicit `query_vector` returned bit-identical results three times, which proves the RANKING is deterministic given a vector. **So nothing in a release has to change for such a baseline to move, and it is therefore not evidence about the release either way.** Corollary worth stating because it bit us: `scan_capped` is query-dependent too and so is also a measurement, not a property of the collection - it is set only when the walk hit the cap *while still short of `top_k`*, so a query that fills `top_k` reports false where a query that falls short reports true. Read all three of the useful assertions (`scan_capped`/`scanned`/the nested error envelope) as "this query, this filter", never as facts about the data.
+- **A CONSUMER'S TIMEOUT CAN SIT EXACTLY ON THE BOUNDARY OF OUR COLD EMBED PATH, AND THEN THE FIRST CALL OF A QUIET PERIOD IS A COIN FLIP THAT LOOKS LIKE AN INTERMITTENT FAULT IN OUR SERVICE.** Measured by novitax 2026-10-22 on their live voice agent: their first embed attempt has a **6000 ms** budget and our cold path costs **about six seconds**, so two samples they had already collected sat at **6.037 s (succeeded) and 6.547 s (failed, 0 candidates)** - the same query, minutes apart, decided by a few hundred milliseconds. Their own words are the lesson: both observations looked identical, and the thing to be suspicious of was that identity rather than to explain it.
+  **It corroborates the long tail recorded above from the other side.** A cold `query_text` is 0.5-1.0 s at the median and the tail reaches at least 8.17 s, so a 6 s client timeout is not generously set - it is set INSIDE our distribution, and nothing on either side of the call says so. **This is the split-latency-budget trap again** (their timeout is their number, our tail is ours, and neither side can see the other), with the sharper form that **two different faults produced one symptom**: the hourly snapshot stall and this boundary, plus a third explanation they had written up that morning. When a consumer reports an intermittent degradation, the question is not which cause it is but **how many causes it has**.
+  The fix is the one already recommended here on independent grounds - embed ONCE and pass an explicit `query_vector` to every collection - which halves the draws from the tail, moves the cold call off the boundary, and is separately the only reproducible baseline.
 - **A CACHE WOULD MAKE SEARCH LATENCY BIMODAL, so do not derive a timeout from a post-cache p50.** If query embeddings are ever cached, the same endpoint answers in ~3 s or ~12-15 s depending on state nothing outside can see, and a timeout or retry budget tuned against the hit path will fire on every miss. Same family as the startup loop that was bounded by an attempt COUNT: a budget encoding a duration as a count carries a hidden assumption about per-item cost. Note also that **caching would NOT make a search reproducible** - per-process plus a TTL means a restart or the TTL boundary clears it, so results would be stable across an afternoon and silently not across a deploy, which is stable long enough to be trusted and not long enough to be true. An explicit `query_vector` stays the only reproducible baseline.
 - **MEASURED ON PROD, 2026-10-09, small collections (126 and 49 rows, dim 4096), server-side end to end.** The filtered similarity search costs **~25 ms** and the filter costs nothing measurable at that size - filtered and unfiltered are identical within noise. A cold `query_text` is **0.49-0.95 s**, essentially all of it the provider round trip; the SAME text repeated is 0.022 s, because the provider caches it. **That cache is useless to a workload of unique queries** such as a voice assistant, which is therefore permanently on the 0.5-1.0 s path. Eight samples in one window is a MEDIAN, not a tail: a 12-15 s text search was observed earlier the same day and did not reproduce, so the bad tail is real and unexplained rather than bounded at 0.95 s. Quote these as medians and say so.
   **RE-MEASURED 2026-10-19 BY A CONSUMER AND BY US, AND THE DISTRIBUTION IS WHAT MATTERS RATHER THAN EITHER FIGURE: THE MEDIAN IMPROVED BY AN ORDER OF MAGNITUDE AND THE TAIL DID NOT GO AWAY.** Twelve never-before-seen strings against `novitax:kb_facts`: **min 0.48 s, median 0.75 s, max 4.46 s, with 1 of 12 over 2 s**. In the same hour a cold `query_text` of ours took **8.17 s**, so the tail reaches at least that. Both observations are correct and neither alone describes the endpoint.