Skip to content

refactor(core): the core answers whether a request embeds, one embedding gate - #1764

Merged
ajianaz merged 2 commits into
developfrom
refactor/1753-embedding-gate
Nov 13, 2026
Merged

ajianaz merged 2 commits into
developfrom
refactor/1753-embedding-gate

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

The core now answers "does this request embed a client string?" from the rules that decide the request, and there is one gate for HTTP and MCP.

  • uteke_core::remote_guard::EmbedNeed (Query or Draft(&str)), returned by SkillRemoteArgs::embed_need(op), DocSimilarQuery::embed_need() and EmbedNeed::for_search_mode(mode).
  • EmbedGate::admit(need) checks the draft cap (400) and then takes the slot (429, busy: 2 embedding requests are already running; retry in a moment).
  • One gate per Uteke (Uteke::embed_gate()); uteke-serve clones it into ReqCtx.remote_embeds, MCP takes its slots from the same type. skill_remote and doc_similarity_query take no slot themselves (they still check the draft cap).
  • The router reads the body once, decodes it into the typed request of the route and asks the core (admit_remote_embed); remote_embed_input (the mirror of handler rules) and Uteke::remote_embed_permit / remote_draft_permit are deleted. The slot is still taken before the store lock; an oversized draft is still a 400 before the slot.
  • POST /doc/search takes a slot in hybrid/semantic mode (429 when two embedding requests run, fts never does).

Classification found in api_registry.rs: /doc/search, /doc/similar, /skill/search, /skill/similar are Tier::Lab, so they are gated. /recall, /search, /room/recall and /remember are Tier::Core and get no new 429 (CORE contract). /context is LAB but is outside this issue and is left as it was. Not done, by decision in #1748: embedding outside the store lock.

Why

The embedding-cost bound was split between the router (a copy of the handlers' rules, which fails silently when a handler changes) and a per-Uteke gate that could never trip under the server lock. The rule belongs with the validation that already knows it (#1753, finding 1 of #1748); the slot-before-lock ordering from #1518/#1731/#1747 is kept.

Testing

  • New every_route_that_embeds_a_client_string_holds_a_slot_while_it_embeds: a probe embedder records how many gate slots are held at the moment a handler embeds; the table covers every LAB route and body shape (doc/skill similar, doc/skill search in every mode, list, show) and fails when a handler embeds without a slot, or a slot is taken without embedding.
  • New core test embed_need_is_true_exactly_when_the_operation_embeds_a_client_string (recording embedder against skill_remote), plus gate unit tests (clone shares slots, draft cap before the gate).
  • New the_gated_routes_are_lab_and_the_memory_recall_routes_are_core; /doc/search added to the 429 test.
  • Kept: the_embedding_gate_refuses_before_the_store_lock_is_taken (store lock held, third request 429, oversized 400, slots released; it runs the real router with the in-process server and threads), the MCP slot tests.
  • Replaced (same intent, new API): embedding_requests_are_refused_when_every_slot_is_taken (core) and only_requests_that_embed_a_client_string_take_a_slot (server).
  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p uteke-core -p uteke-mcp -p uteke-server -p uteke-cli, cargo run -p docgen (docs/core-contract.json unchanged; docs/api-reference.md carries the new /doc/search description).

Closes #1753

…ing gate

EmbedNeed comes from the validation that decides the request (SkillRemoteArgs, DocSimilarQuery, search mode); the router asks it once and takes the slot before the store lock, MCP uses the same gate type. POST /doc/search (LAB) takes a slot too.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

The three MCP tools and POST /doc/similar keep the shared gate; their errors go through the single class mapping.
@ajianaz
ajianaz merged commit 3efc1eb into develop Nov 13, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(server): the core answers "does this request embed?", one embedding gate

1 participant