From c32d0a318a444ea486ea9611d961dc7284ee83bf Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 07:22:39 -0600 Subject: [PATCH] docs(atlas-search): align Worker README and wrangler comment with the code Five survey findings from the Atlas book pass, each verified against pkgs/atlas-search/worker/src on main: - key material is KEY_SCHEMA 2: it also carries "v": 2 and the disclosure context (hosted-per-user); the README's fingerprint list predated the bump, so a key built from the README was wrong. - the D1 hot cache is not flag-activated: HotCacheStore has no caller in the request path (tests only), so the README now says the store is unwired rather than implying the flag turns it on. - wrangler.toml's GATE_TOKEN comment scoped the gate to /v1/*; the same gate covers POST /mcp. - the Worker itself verifies effective_ceiling on every search response and refuses (502) before caching; the README credited ceiling enforcement to the service only. - the module map credited index.ts with normalization and keying; both live in key.ts, search keying runs in search.ts, and index.ts calls queryKey directly only for inspect/purge. --- pkgs/atlas-search/worker/README.md | 28 ++++++++++++++++++-------- pkgs/atlas-search/worker/wrangler.toml | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pkgs/atlas-search/worker/README.md b/pkgs/atlas-search/worker/README.md index 8e8a412f65..65e87d8a65 100644 --- a/pkgs/atlas-search/worker/README.md +++ b/pkgs/atlas-search/worker/README.md @@ -9,7 +9,10 @@ and caches the result **indefinitely** (no TTL/eviction in v1). ## Shape -- `src/index.ts` — gate, normalization, keying, routing. +- `src/index.ts` — the inbound gate and routing. Normalization + and keying live in `src/key.ts`; index.ts calls `queryKey` + directly only for the inspect/purge routes (search keying runs + in `src/search.ts`). - `src/cache_do.ts` — the `QueryCache` DO: one per query key; check-and-fill runs inside the DO so a fan-out happens once. State machine: absent → embedded → complete; the embedding is @@ -18,13 +21,19 @@ and caches the result **indefinitely** (no TTL/eviction in v1). (`POST /v1/embed`, `POST /v1/search`) via the `atlas-search.security.cab` tunnel hostname + Cloudflare Access service token. The service enforces this client's - `personal` tier ceiling; the Worker holds no Turso credentials + `personal` tier ceiling, and the Worker enforces it too: every + search response's `effective_ceiling` is checked against the + pinned ceiling and a mismatch is refused (502) before anything + is cached. The Worker holds no Turso credentials and keeps no shard list (new `atlas-core-*` databases join the fan-out through the service's manifest discovery). -- `src/key.ts` — DO key = sha256 over the normalized query plus - the pinned config fingerprint (ceiling, model revision, vector - table, k). A cached entry is never served across ceilings or - embedding spaces. +- `src/key.ts` — query normalization and DO keying. The key is + sha256 over the canonical key material (KEY_SCHEMA 2): the + normalized query plus `"v": 2`, the pinned ceiling, the + disclosure context (`hosted-per-user`, #12622), model + revision, vector table, and k. A cached entry is never served + across ceilings, disclosure contexts, or embedding spaces; + entries keyed under schema v1 are orphaned, never served. ## Endpoints @@ -68,8 +77,11 @@ The `HOT_CACHE` D1 binding and the store module in design (`doc/2026-11-23T08-06-00Z_design_atlas_d1_tenant_hot_cache/`): the §5 `hot_cache` schema (migration `migrations/0001_hot_cache.sql`) plus get/put/touch/evict primitives. The tier is gated by -`HOT_CACHE_ENABLED` (default `"false"`); with the flag off nothing -reads or writes the cache and the read path is unchanged. Freshness +`HOT_CACHE_ENABLED` (default `"false"`), but the store is not yet +wired into the request path at all: nothing in the Worker calls +it outside tests, so the flag alone does not activate the cache — +with the flag on and the binding present, the Worker still never +touches D1 and the read path is unchanged. Freshness (#13101), admission/eviction (#13103), and read-path integration (#13105) are separate follow-ons. The committed `database_id` is a local placeholder: the real `atlas-hot-cache` database is created at diff --git a/pkgs/atlas-search/worker/wrangler.toml b/pkgs/atlas-search/worker/wrangler.toml index 9d845b986a..4a342fc32f 100644 --- a/pkgs/atlas-search/worker/wrangler.toml +++ b/pkgs/atlas-search/worker/wrangler.toml @@ -4,7 +4,7 @@ # The same gate covers the MCP endpoint (POST /mcp, #8625). # # Secrets (wrangler secret put; values never in this file): -# GATE_TOKEN inbound bearer gate for /v1/* +# GATE_TOKEN inbound bearer gate for /v1/* and POST /mcp # SERVICE_TOKEN the `cf-worker` client token of the fleet # search service (ceiling_cap: personal) # ACCESS_CLIENT_ID Cloudflare Access service token for