Skip to content

feat(kv-router): approximate and predict-on-route indexing in the selection service - #14

Closed
ishandhanani wants to merge 1 commit into
idhanani/p0-selection-advisory-busyfrom
idhanani/p0-selection-approx-indexer
Closed

ishandhanani wants to merge 1 commit into
idhanani/p0-selection-advisory-busyfrom
idhanani/p0-selection-approx-indexer

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Phase 0 (selection-core parity), item 4a. Stacked on #12. Item 4b (the Remote indexer 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-route SideIndexer (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 with use_kv_events=false therefore had an indexer nothing ever wrote to, i.e. no cache awareness.

  • IndexerPolicy::from_router_config (services/indexer/backend.rs) mirrors resolve_approximate_primary_policy + Indexer::new shape rules, including the two bail!s. router_approximate_cache_policy=lru falls back to TTL with a warning: LRU needs per-request acquire/release fencing (ApproximateRequestLease) the service does not have yet.
  • Indexer::{Single, Concurrent} gain approx: Option<SideIndexer> and primary_records_routing_decisions. find_tiered_matches seeds lower tiers from primary-only matches and merges side scores by per-worker max afterwards (same lockstep caveat as the frontend's merge_overlap_scores). find_matches merges too. remove_worker* also clear the side indexer. dump_events stays primary + lower tiers (side state is local and never replayed). records_routing_decisions() and supports_router_hint_chain_retention() exposed for 2c.
  • WorkerRegistry::set_indexer_policy applies to every partition indexer it creates; SelectionCore::new_inner sets it (policy resolved in try_new_local and SelectionServiceBuilder::build, so invalid configs fail at construction).
  • SelectionCore records a booking's public block hashes (RoutingDecisionHashes::from_local_hashes) for select_and_reserve, the cached POST /reservations replay (PendingSelection.routing_hashes, retained only when the indexer records; counted in the cache byte budget), and explicit reservations that carry token_ids/block_hashes. Query-only select records nothing (matches the frontend, which records on admission). Failures are logged: the booking already landed.
  • Documented as a "KV Indexing Modes" table in standalone-selection.md.

Behavior change: only for use_kv_events=false or router_predicted_ttl_secs deployments of the standalone service, which now get the frontend's cache credit semantics. cached_booking_honors_prefill_tracking re-booked the identical prompt and asserted potential_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_worker clears 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-existing registry.rs dead-code warning. cargo fmt and docs_lint.py clean.
  • No code outside lib/kv-router matches the services Indexer variants (lib/llm has its own enum); Python bindings use SelectionServiceBuilder only.

@github-actions github-actions Bot added feat documentation Improvements or additions to documentation labels Sep 3, 2026
…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

Copy link
Copy Markdown
Owner Author

Superseded by the upstream-shaped staging stack: continued as #46 (rebased onto ai-dynamo/main, see #33).

This branch had an error being deployed

1 failed deployment
external_collaborator — a428fdfd Deployed Sep 3, 2026 by ishandhanani via ok-to-test #28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant