Skip to content

atlas search worker: Cloudflare Worker + per-query Durable Object embedding/result cache over the shard fan-out (successor surface for #5755) #6788

Closed

Description

@dezren39

What Drew ordered (2026-11-06 22:48 CST, verbatim substance)

Build the cross-database search surface as a Cloudflare Worker that pulls all databases for search; for each search query it stores a Durable Object, automatically inserts the query as an embedding, and caches the result — for now, indefinitely (no TTL/expiry).

This is the successor surface for the Atlas shard consumer wiring in #5755 (slice 1 merged in #6661; rehomed as fleet serve search in #6674). It supersedes the 2026-11-05 "Ask-the-ledger" direction (Cloudflare AI Search / AutoRAG over R2 snapshots + a query/miss ledger DB): Drew replaced the managed-AI-Search design with this explicit Worker + Durable Object + embedding cache design. The AI Search proposal is not being built; this issue is the record of what replaced it.

Architecture (v1)

Components

  1. Cloudflare Worker (pkgs/atlas-search/worker/) — the only public edge. Inbound gate: a shared bearer secret checked in the Worker (constant-time compare); not public-open. (Cloudflare Access in front of the Worker hostname is a follow-up hardening note below.)
  2. Durable Object class QueryCache — one DO per distinct query. DO name = sha256(normalized_query || config_fingerprint) where the fingerprint pins {ceiling: "personal", model_rev, vec_table, trunc: 0, k} so a cache entry can never be served across different effective ceilings or embedding spaces (the same rule the search service applies to job dedupe).
  3. The fleet search service (fleet serve search / atlas-search serve, laptop loopback :18760) remains the fan-out engine: it discovers the shard set from the Turso Platform API (only atlas-core-* databases), reads each candidate's atlas_manifest self-description (tier, topic, part, expected chunks), enforces per-client tier ceilings, embeds the query with the one shared resident embedder, runs the parallel cosine scan + merge/rerank. The Worker keeps no shard list of its own — new databases join the fan-out by existing in the Turso org with the atlas-core- prefix and a manifest; the Worker inherits the set through the service.
  4. Reachability: the service is exposed to the Worker through the existing amd-6-pm-stack Cloudflare Tunnel as atlas-search.security.cab → localhost:18760, fronted by a Cloudflare Access application whose only policy is a service token the Worker presents (CF-Access-Client-Id/CF-Access-Client-Secret). The tunnel hostname without the service token is rejected by Access before it reaches the laptop.

Miss path (first time a query is seen)

  1. Worker normalizes the query, computes the DO key, asks the DO for its entry → miss.
  2. Worker calls the service's new POST /v1/embed (added by this work to both server.rs copies, parity-guarded): the service's shared embedder returns the production query vector. The Worker stores {query, normalized_query, embedding, model, model_rev, dims, created_at} in the DO first — the DO is born holding the query's embedding, per Drew's spec, even if the search below then fails.
  3. Worker calls POST /v1/search (sync one-shot) with the dedicated cf-worker service client (see boundary below) → merged, reranked results.
  4. Worker stores {result, searched_at, fanout_ms, embed_ms} in the DO and returns the result with cache: "miss" and the timings.

Hit path

  • The DO returns the stored result verbatim; the fleet service is never contacted. Response carries cache: "hit", the original searched_at, and a hit_count the DO increments. This is the proof surface: a hit must be byte-identical to the miss response's result and must not move any counter on the service side.

Retention

  • Indefinite. No TTL, no eviction in v1 — Drew's "for now". DO storage is the ledger of every query ever asked through this surface. A future eviction policy (size/LRU) is a deliberate follow-up (filed separately), not a v1 behavior.

Embedding source — decision and why

The fleet embedder (the service's resident ONNX session): model Snowflake/snowflake-arctic-embed-m-v2.0 pinned at rev 95c2741480856aa9666782eb4afe11959938017f, query prompt "query: ", production vector table vec_snowflake_m_v2_768_f32 — 768 dimensions, full width (trunc = 0).

Workers AI is rejected: its 384-dim @cf/baai/bge-small-en-v1.5 lives in a different embedding space (and a different width). Cosine similarity across embedding spaces is meaningless; a Worker-side embedding that cannot be compared against the corpus vectors would silently corrupt every ranking. Any edge embedding must reproduce the corpus's exact space, and the only artifact that does that today is the pinned Snowflake session in the fleet service.

Correction to older notes: several records describe the corpus as "384-dim Snowflake". Production is 768-dim (vec_snowflake_m_v2_768_f32 in the live service config; 384 was a Matryoshka truncation option from the Python era, never the production width).

Secret-tier boundary

  • The Worker authenticates to the search service as a dedicated client, cf-worker, with ceiling_cap: "personal" — the service mechanically caps it to the Public + Internal tiers. The Secret tier is unreachable through this client no matter what the Worker asks for.
  • The Worker holds no Turso credentials and never receives secret-tier shard data, so nothing secret can enter a Durable Object — neither chunk content nor embeddings of secret chunks.
  • The drew-cli client (secret-bearing cap) stays laptop-local and is not used by anything in this build. Secret-tier search remains a laptop-side-only operation, exactly as today.

What v1 deliberately leaves out

Open questions (recorded, proceeded on defaults)

  • Worker hostname: default atlas-search on the account's workers.dev subdomain; a custom domain can be bound later without changing the design.
  • Whether the DO should also store the FTS match expression / branch pools for debugging: default no — result + embedding + provenance only.

Proof required (acceptance)

  • Deployed Worker + DO; a real query run twice: first response cache: "miss" with fan-out executed (service-side evidence), DO created holding a 768-dim embedding; second response cache: "hit", byte-identical result, served from the DO with no service contact; timings for both; DO state read back through the Worker's gated inspect endpoint.

Activity

  1. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  2. added a commit that references this issue on Nov 7, 2026
  3. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    Shipped — v1 live and proven (2026-11-06 night)

    PR: #6800, merged as f3cdeca52af2bf1d961d9447ecf278240545df66 (merge verified by readback; the user-token bucket was rate-limited, so the merge went through the GitHub App route).

    What shipped

    • Worker at pkgs/atlas-search/worker/, deployed: https://atlas-search.developing-today.workers.dev (version b8682c0b-2215-4ade-950f-86ec3bba4047). Routes: GET /health (open), POST /v1/search and GET /v1/cache/inspect (gate-token bearer, constant-time compare).
    • Durable Object per query (QueryCache, SQLite-backed): key = sha256(normalized query ‖ ceiling ‖ model rev ‖ vector table ‖ k). Miss path runs entirely inside the DO: the query is embedded and the embedding persisted before the fan-out runs (state machine absent → embedded → complete; a failed search retries the search only), then the result is cached indefinitely. Hits never contact the service.
    • Service: POST /v1/embed added to both server.rs copies under the fleet step 5: search domain joins fleet — gated on #5350 step 6 cutover #5433 parity guard (parity script green). Embed jobs are memory-only — they never enter the jobs ledger.
    • Fan-out unchanged and service-owned: shard discovery (Turso Platform API → atlas-core-* → atlas_manifest), embeddings, and merge/rerank all stay in fleet serve search. The Worker holds no Turso credentials and no shard list — new databases join by existing with the prefix + manifest.
    • Secret boundary, enforced twice: the Worker authenticates to the service as the cf-worker client (ceiling_cap: personal ⇒ Public+Internal tiers only), and refuses to cache any response whose reported effective_ceiling isn't personal. Secret-tier data cannot enter a DO.
    • Path in: tunnel ingress atlas-search.security.cab → localhost:18760 on the existing amd-6-pm-stack tunnel, DNS CNAME created, Cloudflare Access app with a service-token-only policy (public hits get 403 — verified). Secrets vaulted by name in BWS + 1Password Dev: atlas.search-cf-worker-token, atlas.search-worker-gate-token, cloudflare.access-atlas-search-client-id, cloudflare.access-atlas-search-client-secret.

    Tests (oracles named)

    • cargo: atlas-proto 4 (incl. embed_wire_roundtrip), atlas-search 27 (incl. embed route serving the shared embedder's vector), fleet-search --features serve 33 lib + 11 contract (incl. embed route). fmt clean.
    • Worker: 12/12 (vitest + pool-workers) + typecheck clean — hand-built canonical-digest key oracle; space-validator reject matrix (foreign model / truncated width / NaN); miss→hit identity against upstream call counters (repeat query with different whitespace must not increment them; result deep-equal); wrong-space refusal caches nothing; gate 401 with zero upstream contact.

    Live proof (2026-11-07T05:20Z, query "how does the fleet queue claim a task", k=3)

    • Miss: 9.52 s wall (embed 358 ms + fan-out 8,881 ms), 3 fanned-out results, DO created 05:20:34.839Z.
    • Hit (identical query): 0.135 s, cache: "hit", result byte-identical (verified programmatically), same key.
    • Hit (whitespace-variant query): cache: "hit" — normalization works in production.
    • DO readback via GET /v1/cache/inspect: has_embedding: true, embedding_dims: 768, embedding_valid: true, has_result: true, result_bytes: 16985, hit_count: 2, model Snowflake/snowflake-arctic-embed-m-v2.0.
    • Gates: wrong gate token → 401; hostname without Access headers → 403; service /v1/embed without bearer → 401.

    Deployment caveat (honest state)

    The service binary currently serving the laptop's atlas-search.service is the release build of the PR branch, wired via a reversible systemd drop-in (~/.config/systemd/user/atlas-search.service.d/6788-embed-endpoint.conf, with ATLAS_ORT_LIB pointed at the nix-closure ONNX Runtime). The code is on main now, so the durable deploy is the normal nix package rebuild — after that lands, the drop-in should be removed. Until then, if the unit is restarted from the stock nix binary, /v1/embed disappears: cache hits keep working, misses return 502 and cache nothing. The cf-worker client was added to ~/.local/state/atlas-search/service.json (backup at service.json.bak-6788).

    Deliberately out of v1

    Open questions recorded in the issue body stand (snapshot distribution, restricted-network shape) — neither blocks v1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions