Skip to content

feat(kv-router): wire shared-cache hits and full session context into selection - #9

Closed
ishandhanani wants to merge 1 commit into
idhanani/p0-selection-scheduler-hooksfrom
idhanani/p0-selection-shared-cache-session
Closed

ishandhanani wants to merge 1 commit into
idhanani/p0-selection-scheduler-hooksfrom
idhanani/p0-selection-shared-cache-session

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Phase 0 (selection-core parity), item 2a. Stacked on #8.

Summary

Closes two of the ScheduleRequest gaps in SelectionCore::schedule_selection where the frontend KvRouter supplies a signal and the selection service hardcoded it away:

  • shared_cache_hits: None (core/mod.rs:786 on main). SelectionHostHooks gains shared_cache: Option<Arc<dyn SharedKvCache>>. prepare_selection_inputs runs the shared-cache lookup concurrently with the indexer lookup (same shape as lib/llm/src/kv_router/route_lookup.rs::join_indexer_and_shared_cache), only for prompts that carry raw token_ids, and a failed lookup is logged and ignored. potential_loads does not consult it.
  • SessionContext::new(session_id, None, None, None, None) (core/mod.rs:779-780). Both SelectRequest and SelectAndReserveRequest accept a structured session_context object (session_id, parent_session_id, session_final, kv_hints.evict_session, input_trigger) that maps 1:1 onto the frontend's to_worker_selection_session_context (lib/llm/src/kv_router.rs:259). The flat session_id stays as the legacy form; the object wins when both are present. The From impl destructures exhaustively so a new field fails to compile until mapped.

Documented in standalone-selection.md. Still open from item 2: LoRA narrowing (2b) and the router-hint chain (2c).

Validation

  • cargo test -p dynamo-kv-router --features standalone-selection --lib services::selection: 68 passed. New tests: shared_cache_hits_reach_worker_selection (recording SharedKvCache + capturing WorkerPicker asserts the call args, that shared_beyond_device_blocks == 1 reaches the policy, that potential_loads and hash-only prompts do not query it), session_context_reaches_worker_selection (all five fields observed by the picker, legacy session_id fallback), and two wire-deserialization tests in types.rs.
  • cargo clippy --features standalone-selection --all-targets: only the pre-existing registry.rs dead-code warning. cargo fmt clean.
  • python3 docs/fern/scripts/docs_lint.py clean.

… selection

Two frontend scheduler inputs the SelectionService hardcoded away:

- shared_cache_hits was always None. SelectionHostHooks gains an optional
  SharedKvCache; prepare_selection_inputs queries it concurrently with the
  indexer for prompts that carry raw token_ids and passes the hits into
  ScheduleRequest, so the built-in scorer's shared-beyond-device credit and
  custom policies see the same signal the frontend KvRouter provides. Load
  projection (potential_loads) does not consult it.

- session_context only carried session_id. Both select requests accept a
  structured session_context object (parent_session_id, session_final,
  kv_hints, input_trigger) mirroring the frontend's AgentContext mapping;
  the flat session_id remains as the legacy form and loses to the object.

Tests: a recording SharedKvCache plus a capturing picker prove the hits and
every session field reach worker selection; wire deserialization and legacy
fallback are covered in types.rs.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani

Copy link
Copy Markdown
Owner Author

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

This branch had an error being deployed

1 failed deployment
external_collaborator — 7f7eded9 Deployed Sep 3, 2026 by ishandhanani via ok-to-test #23
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