Repository navigation
refactor(core): the core answers whether a request embeds, one embedding gate - #1764
Merged
Merged
Conversation
…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.
🔍 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(QueryorDraft(&str)), returned bySkillRemoteArgs::embed_need(op),DocSimilarQuery::embed_need()andEmbedNeed::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).Uteke(Uteke::embed_gate());uteke-serveclones it intoReqCtx.remote_embeds, MCP takes its slots from the same type.skill_remoteanddoc_similarity_querytake no slot themselves (they still check the draft cap).admit_remote_embed);remote_embed_input(the mirror of handler rules) andUteke::remote_embed_permit/remote_draft_permitare deleted. The slot is still taken before the store lock; an oversized draft is still a 400 before the slot.POST /doc/searchtakes a slot inhybrid/semanticmode (429 when two embedding requests run,ftsnever does).Classification found in
api_registry.rs:/doc/search,/doc/similar,/skill/search,/skill/similarareTier::Lab, so they are gated./recall,/search,/room/recalland/rememberareTier::Coreand get no new 429 (CORE contract)./contextis 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-
Utekegate 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
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.embed_need_is_true_exactly_when_the_operation_embeds_a_client_string(recording embedder againstskill_remote), plus gate unit tests (clone shares slots, draft cap before the gate).the_gated_routes_are_lab_and_the_memory_recall_routes_are_core;/doc/searchadded to the 429 test.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.embedding_requests_are_refused_when_every_slot_is_taken(core) andonly_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.jsonunchanged;docs/api-reference.mdcarries the new/doc/searchdescription).Closes #1753