ソースを参照

docs: a check that cannot TELL, and when tightening a contract helps

fszontagh 1 ヶ月 前
親
コミット
6d4356d7f4
1 ファイル変更、2 行追加、1 行削除
  1. 2 1
      CLAUDE.md

+ 2 - 1
CLAUDE.md

@@ -49,7 +49,8 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **Embedding config precedence:** collection `embedding_model` pin → project override → global default; endpoint + API key are the project override when set, else global. Resolved by the pure `resolveEmbedding()` (`project_settings.hpp`) - unit-test precedence there, not through the handlers.
 - **Every outbound request to an external provider goes through `applyOutboundDefaults()`** (`outbound_http.hpp`): `User-Agent: smartbotic-vectorapi/<version>` and nothing else, TLS verification on, redirects off. Never let cpp-httplib's default UA reach a provider.
 - **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"**.
-- **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.
+- **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.
 - **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`.