Repository navigation
feat(kv-router): approximate and predict-on-route indexing in the selection service - #14
Closed
ishandhanani wants to merge 1 commit into
Closed
ishandhanani wants to merge 1 commit into
ishandhanani wants to merge 1 commit into
Conversation
ishandhanani
had a problem deploying
to
external_collaborator
September 3, 2026 06:43 — with
GitHub Actions
Failure
…ection service
Port the frontend Indexer's approximate modes into the runtime-free
services/indexer backend so a selection service built from the same
KvRouterConfig indexes the same way the frontend KvRouter does:
- IndexerPolicy::from_router_config resolves the frontend's shape rules:
event-driven primary; event-driven primary plus a short-TTL predict-on-route
SideIndexer when router_predicted_ttl_secs is set; approximate TTL primary
when use_kv_events=false. The same invalid combinations are rejected.
Capacity-bounded LRU retention falls back to TTL with a warning until the
service has per-request lease fencing.
- Indexer::{Single, Concurrent} gain approx and primary_records_routing_decisions.
Lookups seed lower tiers from confirmed primary matches only and merge side
scores by per-worker max afterwards. Side state is never dumped or replayed.
- WorkerRegistry carries the policy for every partition indexer it creates.
- SelectionCore records a booked routing decision (select_and_reserve, cached
replay, and explicit reservations that carry token_ids or block_hashes) into
the approximate indexer. Query-only selects record nothing. Recording
failures are logged, not returned: the booking already landed.
Previously a selection service with use_kv_events=false had an empty,
never-written indexer and therefore no cache awareness at all.
Tests: backend policy matrix, approximate primary and side-indexer merge for
1 and 2 threads, and core bookings credited through all three booking paths.
cached_booking_honors_prefill_tracking now books a distinct second prompt so
it measures prefill tracking rather than the new (correct) cache credit.
Signed-off-by: Ishan Dhanani <[email protected]>
ishandhanani
force-pushed
the
idhanani/p0-selection-approx-indexer
branch
from
September 3, 2026 06:52
273f2df to
a428fdf
Compare
ishandhanani
had a problem deploying
to
external_collaborator
September 3, 2026 06:52 — with
GitHub Actions
Failure
This was referenced Sep 3, 2026
Closed
Owner
Author
This branch had an error being deployed
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.
Phase 0 (selection-core parity), item 4a. Stacked on #12. Item 4b (the
Remoteindexer variant over the standalone indexer's HTTP/query_by_hash) follows separately.Summary
The frontend
Indexer(lib/llm/src/kv_router/indexer/mod.rs) has two approximate modes the services backend lacked: a predict-on-routeSideIndexer(router_predicted_ttl_secs, layered over an event-driven primary) and an approximate primary (use_kv_events=false, routing decisions written directly, TTL expiry). A selection service configured withuse_kv_events=falsetherefore had an indexer nothing ever wrote to, i.e. no cache awareness.IndexerPolicy::from_router_config(services/indexer/backend.rs) mirrorsresolve_approximate_primary_policy+Indexer::newshape rules, including the twobail!s.router_approximate_cache_policy=lrufalls back to TTL with a warning: LRU needs per-request acquire/release fencing (ApproximateRequestLease) the service does not have yet.Indexer::{Single, Concurrent}gainapprox: Option<SideIndexer>andprimary_records_routing_decisions.find_tiered_matchesseeds lower tiers from primary-only matches and merges side scores by per-worker max afterwards (same lockstep caveat as the frontend'smerge_overlap_scores).find_matchesmerges too.remove_worker*also clear the side indexer.dump_eventsstays primary + lower tiers (side state is local and never replayed).records_routing_decisions()andsupports_router_hint_chain_retention()exposed for 2c.WorkerRegistry::set_indexer_policyapplies to every partition indexer it creates;SelectionCore::new_innersets it (policy resolved intry_new_localandSelectionServiceBuilder::build, so invalid configs fail at construction).SelectionCorerecords a booking's public block hashes (RoutingDecisionHashes::from_local_hashes) forselect_and_reserve, the cachedPOST /reservationsreplay (PendingSelection.routing_hashes, retained only when the indexer records; counted in the cache byte budget), and explicit reservations that carrytoken_ids/block_hashes. Query-onlyselectrecords nothing (matches the frontend, which records on admission). Failures are logged: the booking already landed.standalone-selection.md.Behavior change: only for
use_kv_events=falseorrouter_predicted_ttl_secsdeployments of the standalone service, which now get the frontend's cache credit semantics.cached_booking_honors_prefill_trackingre-booked the identical prompt and assertedpotential_prefill_tokens == 4; with an approximate primary that prompt is now cached (0 effective prefill), so the test books a distinct prompt to keep measuring prefill tracking.Validation
cargo test -p dynamo-kv-router --features standalone-selection --lib: 1063 passed. New:indexer_policy_mirrors_frontend_resolution,event_driven_policy_ignores_routing_decisions,approximate_primary_records_routing_decisions(1 and 2 threads, also asserts dump carries it),side_indexer_merges_predicted_scores_by_worker_max(primary wins on longer prefix, side never seeds lower tiers or dumps,remove_workerclears it),bookings_populate_the_approximate_primary_without_kv_events(all three booking paths credited),event_driven_indexer_does_not_record_bookings.cargo clippy --features standalone-selection --all-targets: only the pre-existingregistry.rsdead-code warning.cargo fmtanddocs_lint.pyclean.lib/kv-routermatches the servicesIndexervariants (lib/llmhas its own enum); Python bindings useSelectionServiceBuilderonly.