Răsfoiți Sursa

docs: the static fallback swallows a missing FILE, and a function cannot return binary refs SV-50

fszontagh 5 zile în urmă
părinte
comite
3c2f1e6b19
2 a modificat fișierele cu 19 adăugiri și 0 ștergeri
  1. 3 0
      CLAUDE.md
  2. 16 0
      api/llms.txt

+ 3 - 0
CLAUDE.md

@@ -741,3 +741,6 @@ Publishing uploads to the live apt repo - only with explicit confirmation. The d
 - **I INFERRED A CONSUMER'S ERROR-TAGGING ORDER FROM ITS SYMPTOM AND WAS WRONG - THE THIRD TIME IN A FORTNIGHT OF READING SOMEONE ELSE'S CODE OFF OUR OWN LOGS.** Told that a database failure had been bucketed as an upstream 5xx, I proposed the mechanism: a `status >= 500` arm running ahead of the `e.code` check. `code` was the first arm and always had been; the slug never arrived as `code` at all. The question was answerable by asking, and the previous two instances (`kitchen_presets`, a consumer's call sites) were already written in this file when I did it again. **Equally: the stripped-read defect above is real and does NOT explain what they measured** - the generic arm yields `internal` / 500 and they saw a 503 with no code - so accepting their diagnosis wholesale would have closed the question on a cause that does not fit. A tidy explanation that fits is more expensive than none, and one that does not even fit should be said out loud rather than absorbed.
 
 - **A HARNESS THAT DIFFERENCES TWO MEASUREMENTS MUST ASSERT THE PRESENCE OF THE FIELD IT IS READING, NOT MERELY A 200 - MINE SUBTRACTED TWO 404s AND REPORTED A PROVIDER TIME OF MINUS 0.066 SECONDS.** Timing an embedding provider by differencing a `query_text` search against a `query_vector` control on the same collection, I had the route path wrong (`/api/v1/projects/{p}/...`, not `/api/v1/{p}/...`), both arms answered 404 with an EMPTY BODY, and the script cheerfully produced a negative duration from two failures. The sign is what gave it away, which is luck: had the control been the slower 404 the number would have been small, positive and plausible. It now asserts HTTP 200 **and** the presence of the `results` KEY on every arm before recording anything, because an absent key and an empty list must never render the same in a number you intend to subtract - the same trap as a baseline probe that recorded an error envelope as a legitimate empty ranking.
+
+- **THE PROJECT STATIC MOUNT'S SPA FALLBACK SWALLOWS A MISSING *FILE* AS WELL AS A MISSING ROUTE, SO ABSENCE IS NOT AVAILABLE AS A SIGNAL TO A TENANT.** `serveProjectStatic` (`src/handlers/static_files.cpp:69-75`) does one `infoByPath` lookup and, on ANY miss under the mount, serves `index` - no extension rule, no content-type rule. So an image that was never uploaded answers **200 `text/html`** with the SPA shell, exactly as `/settings` does. Both consequences are real and pull opposite ways: an unpublished file **leaks nothing**, because it is indistinguishable from a route, and a client **cannot branch on a 404** for a missing asset while a fallback is configured - an `<img>` renders broken and reports nothing. There is no way to have both; `index: ""` buys the 404 and costs the SPA. Found by novitax 2026-11-21 by CHECKING rather than assuming, because it could have made their own report moot - which is the habit worth copying: the check that would retire your finding is the one to run first. `api/llms.txt` was silent on the file-versus-route distinction while documenting `""` precisely, which is this file's standing rule about a silence propagating as confidently as a wrong sentence.
+- **A FUNCTION CANNOT RETURN BINARY, AND THE ASYMMETRY IS THE PART A READER GETS WRONG: `bodyBase64` EXISTS ON `ctx.fetch`'s REQUEST SIDE AND NOWHERE ELSE.** `kEnvelopeKeys[]` is exactly `{status, headers, body}` (`runner/src/run_service.cpp:52`), so `bodyBase64` in a return envelope is not an ignored option - it is a fourth key, which FAILS THE RUN as a mixed envelope. The consequence a tenant meets is that **no gate can be put in front of a binary asset**: the function that can check a session cannot emit the bytes, and the mount that can emit them is unauthenticated by design. `ctx.files.get()` returning base64 makes this maximally confusing, since the function can READ the file perfectly well. SV-50; documented in `api/llms.txt` beside the envelope, because the gap was discoverable only by trying it.

+ 16 - 0
api/llms.txt

@@ -112,6 +112,20 @@ meaning "no fallback - an unmatched path answers a plain 404", not an absent
 key.** An absent key leaves the stored value alone; a present empty string is
 stored.
 
+**THE FALLBACK DOES NOT DISTINGUISH A MISSING ROUTE FROM A MISSING FILE, so
+with an `index` set a missing image answers 200 and `text/html`.** The lookup
+is one path lookup against the stored `path` metadata, and ANY miss under the
+mount takes the fallback - there is no extension rule and no content-type rule,
+so `/img/avatar.webp` that was never uploaded returns your SPA shell with a 200
+exactly as `/settings` does. Two consequences, pulling in opposite directions.
+A caller cannot use **absence as a signal**: a 404 is not available for a
+missing asset while a fallback is configured, so a client that branches on one
+will branch on the HTML instead, and an `<img>` will render broken rather than
+report anything. Conversely **an unpublished file leaks nothing** - it is
+indistinguishable from a route, which is the same answer a stranger gets for
+any path at all. There is currently no way to have both an SPA fallback and a
+404 on a missing asset; `index: ""` buys the 404 and costs the SPA.
+
 ### The path a file is served at comes from its METADATA, not its name
 
 File names are a single path segment, so `assets/index-a1b2.js` cannot be a
@@ -585,6 +599,8 @@ export default async function (ctx) {
 
 **The return value shapes the response.** An object whose keys are a non-empty subset of `{status, headers, body}` is a response envelope; any other object is sent as a `200` body; an object MIXING envelope keys with other keys **fails the run** rather than being guessed at. Host calls are synchronous, so `await` is optional - it works because awaiting a non-promise is a no-op.
 
+**A FUNCTION CANNOT RETURN BINARY, AND THE ASYMMETRY WITH `ctx.fetch` IS EASY TO READ THE WRONG WAY ROUND.** `body` is a string or a JSON value, so a string is sent as-is and anything else is `dump()`ed as JSON. There is **no `bodyBase64` and no `bodyBytes` on the RETURN side** - those exist on `ctx.fetch`'s REQUEST side only, and `bodyBase64` in an envelope is not a binary escape hatch but an unknown key, which fails the run as a mixed envelope. A byte outside a valid UTF-8 sequence cannot survive a JSON string, which is the same constraint that makes `responseType: 'base64'` necessary inbound; outbound there is nothing to opt into. So `ctx.files.get()` handing you base64 means a function can READ a stored file and cannot EMIT it. **The practical consequence is that a function cannot gate a binary asset:** a session check in front of an image needs the function to serve the bytes, and the static mount that can serve them is unauthenticated by design. Today the only shapes available are publishing the file on the mount (public to anyone who learns the path - note the path is not guessable from the listing, which is authenticated) or returning a **302** to a URL you control. Tracked as SV-50; say so if you need it.
+
 **The id lives in the source, not in the URL.** A script exports `export const on = { id: 'kb-search', type: 'http', route: '/kb/:topic', method: 'GET' }`, and that `id` is the registry row's identity. `path` records where the author keeps the file and carries no meaning, so moving `kb-search.js` to `lib/search.js` keeps the same row - and the policy an admin granted travels with it.
 
 **Every write is compiled on a runner before it is stored.** The engine that validates is the engine that will execute. A compile failure is **422** `compile_failed` with the error; an `on` block with no id is **422** `missing_function_id`; no healthy runner is **503** `no_runner` and nothing is stored. Code is never stored unvalidated.