Forráskód Böngészése

docs: what a consumer needs to move to the new hostname, measured not asserted

Asked by a consumer the day before their go-live, so all of it was
verified: both names proxy to the same backend and return byte-for-byte
identical bodies for the same path, CORS preflight is identical, and the
read timeout and body limit match because the new host takes them from
the shared snippet.

The base is the ROOT with no /rag, and the old value invites exactly the
wrong guess - /rag on the new host is a 404, measured. Keys and origin
allow-lists need no re-provisioning, because they live in the database
and the allow-list is checked against the Origin the BROWSER sends, which
is the consumer's page origin and does not change when the API host does.
That is the part a consumer will reasonably assume otherwise.

The one way the switch bites: outside /api/ the new host answers nginx's
branded 404 page, so a base string still containing /rag returns HTML and
a JSON parse failure rather than our error envelope. The failure does not
name its own cause and it lands at config time. Hence: test one real
write against the new base first, and never flip it the day before a
go-live.

Also labels the hang-versus-failure note as closed on the consumer's
side - told the 180s ceiling was ours, they added an 8s AbortSignal, so a
three-minute freeze became a fail-fast into their already-harmless path.
A latency budget split across two owners is invisible to both, which is
what made saying whose ceiling it was worth doing.
fszontagh 1 hónapja
szülő
commit
8a5df1879f
1 módosított fájl, 4 hozzáadás és 1 törlés
  1. 4 1
      CLAUDE.md

+ 4 - 1
CLAUDE.md

@@ -70,7 +70,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **A CHECK THAT CANNOT *TELL* IS A DIFFERENT FAILURE FROM A CHECK THAT CANNOT FAIL, and it is harder to see.** Most of the traps recorded here are checks that could not fail. This is the other kind: a check that fires reliably and answers a DIFFERENT question than the one asked of it. The specimen: a consumer proposed detecting whether a filtered search ran on the uncapped server path by reading `db_client` from `/api/v1/version`. That field would have been returned every time, correctly, and it reports the CLIENT library version - so a client at 2.14 against a server at 2.13, where the filtered call is refused and the capped emulation runs, reads 2.14.0 throughout. The answer was dependable and about something else. Their own documentation already carried the line "`db_client` is the RUNTIME library version", written by them, three paragraphs above the proposal. **The defence is to verify when asked to confirm**: they asked me to confirm the mapping was version-deterministic and it was checking rather than agreeing that found it.
 - **Tightening a contract only helps if the consumer's failure path is LOUDER than the behaviour it replaced.** A STRICTER ERROR IS ONLY LOUD IF THE CALLER DOES NOT SWALLOW IT. Tightening `/search` to refuse an unknown option was meant to turn a silently wrong answer into a visible failure. A consumer then checked and found their `recall_memory` catches EVERY search error and falls back to keyword matching - so the new 422 would have silently degraded their search instead, with nothing logged anywhere. The defect would have moved rather than been fixed: from our silence to theirs. They now rethrow `unknown_option` specifically, and a deliberately misspelled option fails four of their tests. So when tightening a contract, "would your tests notice if you started?" has to be paired with **"does your error handling swallow it?"** - a caller with a broad catch converts a loud contract violation into a quiet capability loss, which is strictly worse than the original bug because it looks like a working system. Note what the defect becomes rather than merely where it goes: a dropped filter stops being a dropped filter and becomes a silently different retrieval strategy - still 200, still wrong, and now one layer further from the cause. In a RAG path that is a wrong answer delivered confidently, which is the single failure a knowledge base cannot afford.
   **THE SIBLING QUESTION, AND IT INVERTS THE USUAL ASSUMPTION: ASK WHETHER A HANG IS WORSE THAN A FAILURE FOR THAT CALLER, BECAUSE SOMETIMES IT IS.** Measured on the only public WRITE path on prod, toloajto's offer submission, and stated by its owner 2026-10-15. Their `quotes` INSERT is best-effort - try/catch, no retry, **no fetch timeout** - so a FAILED insert is swallowed with a console warning and is genuinely harmless, because the MiniCRM/n8n push that actually DELIVERS the offer still runs. But that insert is `await`ed SEQUENTIALLY BEFORE the delivery push, so a HUNG insert blocks the delivery for the full stall with no timeout to cut it short: the button spins, and **if the customer closes the tab mid-hang the CRM push never runs and the offer is lost outright**. So for that caller our cheapest failure is an error and our most expensive one is latency - the opposite of the usual reading, where an error is the bad outcome and a slow success is tolerable.
-  Two consequences worth carrying. When pricing ANY window or slow path, "what does your error handling do" is only half the question; the other half is **"what does your code do while waiting, and what is downstream of the await"**. And a caller with no client-side timeout does not experience a slow dependency as slowness - it experiences it as an abandoned transaction, which is silent, unlogged on both sides, and indistinguishable from a customer who simply changed their mind. Note our own `/rag/` mount sets `proxy_read_timeout 180s`, so the ceiling on that spin is ours, not theirs.
+  Two consequences worth carrying. When pricing ANY window or slow path, "what does your error handling do" is only half the question; the other half is **"what does your code do while waiting, and what is downstream of the await"**. And a caller with no client-side timeout does not experience a slow dependency as slowness - it experiences it as an abandoned transaction, which is silent, unlogged on both sides, and indistinguishable from a customer who simply changed their mind. Note our own `/rag/` mount sets `proxy_read_timeout 180s`, so the ceiling on that spin is ours, not theirs. **CLOSED ON THEIR SIDE THE SAME DAY, and the lesson is KEPT because the shape recurs rather than because the instance is open:** told that the 180 s ceiling was ours and not theirs, they added an 8 s `AbortSignal.timeout` to both offer-flow inserts and the copy-link insert, so a stall now lands in the harmless path a failure already had - the design still goes out through the CRM push, the quote simply is not persisted to rag, and the link falls back to a self-contained URL. A three-minute freeze became an 8 s fail-fast. Worth noting WHAT unlocked it: they had the timeout problem in their own code and could not see the number, because the ceiling lived in our nginx config. **A latency budget split across two owners is invisible to both of them**, so saying out loud which side holds the ceiling is cheap and is the thing that made the fix obvious.
 - **clangd, clang-format and clang-tidy are configured** (`.clangd`, `.clang-format`) and read `build-host/compile_commands.json`, so they cover `src/`, `tests/` and `runner/` including `runner/src/main.cpp`. The tidy set is narrow on purpose (`bugprone`/`cert`/`clang-analyzer`/`misc`/`performance`): the broad `modernize`/`readability` families bury real findings under thousands of style notes. `.clang-format` **describes the style the code already uses** rather than imposing one, so it is close to a no-op; `LambdaBodyIndentation: OuterScope` is the setting that matters, since every route handler is a lambda whose body is indented from the statement. Even so the codebase is hand-laid-out and not formatter-clean, so format **new or changed code only** (`git clang-format`), never whole files.
 - TS: no `any`, no TS `enum`, no constructor parameter-property shorthand (tsconfig `erasableSyntaxOnly`). Iterating parsed JSON: bind to a named var first (range-for over `nlohmann::json::parse(...)[...]` dangles).
 - Commits: conventional prefixes (`feat`/`fix`/`build`/`docs`/`test`). Branch for feature work; `main` is pushed to `ssh://git.smartbotics.ai:10022/fszontagh/smartbotic-vectorapi.git`.
@@ -215,6 +215,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **AN ERROR PAGE'S RELATIVE URL RESOLVES AGAINST THE REQUESTED PATH, NOT AGAINST THE ERROR PAGE'S OWN PATH, AND EVERY TEXT-BASED CHECK PASSES WHILE IT IS BROKEN.** The pages first carried `src="logo.png"`, which is correct relative to `/_brand/404.html` and is never what the browser resolves: nginx's internal redirect leaves the URL as the REQUEST, so the logo was fetched from `/logo.png`, or `/some/deep/logo.png`, and 404'd every time. curl said `status=404 type=text/html` and the body contained the brand name twice, so it looked finished. **It was a screenshot that found it** - the broken-image icon - which is the one check that could. A local preview had also passed, because the file happened to sit beside the HTML there, so the preview was testing a layout the server can never reproduce. Absolute `/_brand/logo.png` fixes it, and the test that proves it is a DEEP path, not the one the page was first opened at.
   **EVERY nginx-RAISED ERROR ON THE BOX IS BRANDED NOW, AND THE CATCH-ALL IS OURS RATHER THAN DEBIAN'S.** The snippet is included by all four server blocks: both hostnames, the port-80 redirect and the catch-all. The bare IP and any unknown hostname answer a branded page carrying the landing text, with status **404** rather than 200, because nothing is published there and a 200 would tell every monitor and crawler otherwise. Verified afterwards that qdrant still answers its own JSON on `:6334` and the whole `/rag/` surface is untouched, which is the part that mattered: that hostname fronts a service that is not ours.
   **NEVER EDIT A dpkg CONFFILE TO DO IT. `/etc/nginx/sites-available/default` belongs to nginx-common**, and a modified conffile makes every later nginx upgrade stop and ask about a three-way merge - a cosmetic change turning into an interactive prompt in the middle of an unattended upgrade. I edited it, the owner caught it, and it was restored byte-for-byte (`dpkg --verify nginx-common` prints nothing, which is the check). The catch-all now lives in `/etc/nginx/sites-available/smartbotics-catchall`, which no package owns, and the packaged `default` is left as shipped and simply not symlinked into `sites-enabled`; `/var/www/html/index.nginx-debian.html` is the same story, still on disk and never served. **`dpkg -S <file>` before touching anything under `/etc`** - and note the failure is invisible at the time, since the edit works perfectly until an upgrade months later.
+  **MOVING A CONSUMER TO THE NEW NAME: THE BASE IS THE ROOT, AND THE OLD VALUE INVITES THE ONE WRONG GUESS.** `https://global-api-01.smartbotics.ai` with NO `/rag` and no trailing slash; `https://global-api-01.smartbotics.ai/rag/...` is a 404, measured. Everything else carries over and was verified rather than asserted when a consumer asked before their go-live: both names proxy to the same `127.0.0.1:8080`, and `GET /api/v1/projects/toloajto/collections` returns 200 on both with **byte-for-byte identical bodies**. CORS preflight is identical (204, same `Access-Control-Allow-*`). `proxy_read_timeout 180s` and `client_max_body_size 10m` match, the new host taking them from the shared snippet so the two cannot drift.
+  **Keys and origin allow-lists need NO re-provisioning, and the reason is the part worth stating:** a key and its allow-list live in the DATABASE, not in the hostname, and the allow-list is checked against the **Origin header the BROWSER sends**, which is the consumer's PAGE origin and does not change when they point at a different API host. A consumer will reasonably assume otherwise and ask whether their keys must be re-issued.
+  **The one way this switch bites: a wrong base returns HTML, not JSON.** Outside `/api/` the new host answers nginx's own branded 404 page, so a base string that still contains `/rag` gives the caller `text/html` and a JSON parse failure rather than our `{"error":{...}}` envelope. On the old host everything under `/rag/` reaches vectorapi, so a bad path there still returns JSON. The failure therefore does not name its own cause, and it lands at CONFIG time - which is why the advice to a consumer is to test one real write against the new base before flipping prod, and never to flip it the day before a go-live.
   **Two traps met while doing it.** The half-written config was a BYTE COPY of the qdrant one with a single `server_name` changed, so it still carried full duplicate `qdrant-1` blocks on 443 and 80 and pointed at qdrant's port 6333 and qdrant's certificate - enabling that would have put conflicting server blocks on the live site and served a cert that covers neither name. And **the first request after `systemctl reload nginx` hit the old worker set and answered 404**, which read exactly like a broken location block; every path passed on a retry seconds later. Do not diagnose an nginx location from a request issued in the same breath as the reload.
 - **Prod's database binds `localhost`, not `0.0.0.0`** (`storage.bind_address`), which is why it is only reachable from vectorapi on the same box - correct, and worth knowing before wondering why a port-mapped copy refuses connections.
 - **`policy-rc.d` DOES NOT HOLD THE DATABASE PACKAGE. It blocks `invoke-rc.d`, and that postinst calls `systemctl` DIRECTLY.** Measured the hard way on 2026-10-12: a `policy-rc.d` returning 101 was in place, the pinned install ran at 18:21:12, and the service restarted anyway - the 2.17.2 first-boot migration ran to completion before the install command had even returned. **A hold point three consumers had been promised simply did not exist**, and that cost TWO separate things, not one. One consumer lost the chance to say "wait, a call is live" that they had explicitly been offered. **And because the install itself triggered the migration, the outage happened at 18:21 rather than in the 18:30 slot all three had approved** - it ran NINE MINUTES EARLY, outside the approved window, which is a governance failure distinct from the missing check. A consumer put that second point in the record; my own account had blurred it into the first, which understated it.