Skip to content

refactor(router): resolve KV transfer sources before worker selection ranks them - #125

Closed
ishandhanani wants to merge 1 commit into
idhanani/dyn-177-selection-config-slicefrom
idhanani/dyn-177-kv-hint-keys
Closed

ishandhanani wants to merge 1 commit into
idhanani/dyn-177-selection-config-slicefrom
idhanani/dyn-177-kv-hint-keys

Conversation

@ishandhanani

Copy link
Copy Markdown
Owner

Step 5d-2 (DYNO-177), stacked on #124. Third boundary change for dynamo-worker-selection; behavior-preserving. Plan: split-v2/inventory-worker-selection.md.

Summary

KvTransferSourceSummary::new(candidates, workers, scope) read each worker's config (WorkerConfigLike::kv_transfer_keys) and the indexer's ResidencyRoutingSnapshot (through KvTransferCandidates.routing_snapshot). The selection stage must see neither, so the step splits:

  • kv_hints::resolve_transfer_sources(candidates, workers, &scope) (router side) walks the candidates with the same skips the summary applied (prefix no longer than every target's local prefix or longer than the retained chain; worker ranks without a source endpoint; cache owners missing from the snapshot; an owner without topology inherits its attached worker's) and yields ResolvedTransferSource { source, prefix_blocks, worker_type, attachment, topology }.
  • KvTransferSourceSummary::new(sources, scope) ranks the resolved records exactly as before (by_type when any target takes any island, by_island for covered labels); source_for is unchanged. KvTransferScope gains min_local_prefix_blocks() and needs_islands() for the resolver.
  • WorkerKvTransferKeys keeps its data and target(), gains from_parts over already-hashed labels plus worker_type()/topology() accessors; WorkerKvTransferKeys::new(&impl WorkerConfigLike) becomes WorkerKvTransferKeysExt::of beside WorkerConfigLike in kv_hints.rs, and WorkerKvTransferKeysCache moves there (same path). WorkerConfigLike::kv_transfer_keys's default calls the extension.
  • KvTransferCandidateSource moves to dynamo_router_protocol::kv_hints (shared vocabulary: the indexer produces it, selection consumes it); dynamo_kv_indexer::kv_hints and dynamo_kv_router::kv_hints re-export it. label_key/topology_keys/CacheOwnerKvTransferKeys stay with the indexer, which builds the snapshot keys; the router calls them for worker keys.

Cost: the resolver copies each source's topology labels (a few pairs) into the record; the summary previously borrowed them. Everything else is the same single pass.

Validation

  • cargo check --all-targets on kv-router, builtin, mocker, ext-proc, bench, lib/llm: clean.
  • cargo test -p dynamo-router-protocol -p dynamo-kv-indexer --all-features: protocol 10 passed; kv-indexer 597 passed, 2 ignored.
  • cargo test -p dynamo-kv-router --features standalone-selection,standalone-slot-tracker,metrics,testing: 590 lib + 2 + 7 passed, 2 ignored.
  • cargo test -p dynamo-custom-policy-builtin: all targets pass (56 + 5 + 1 + 3 + 20 + 3 + 4).
  • clippy -D warnings: protocol, kv-indexer, kv-router, builtin (--all-features --all-targets); mocker, ext-proc, bench (--tests): clean.
  • scripts/router_layering_check.sh: 20 checks, 0 failures (protocol direct deps unchanged; the behavior grep accepts the plain-data enum).
  • scripts/router_move_diff.py 435715c223 WORKTREE over the seven touched files: 5,671 common / 88 new / 33 dropped: the ResolvedTransferSource record, the resolver, the summary's new signature and loop over records, from_parts and the three accessors, the extension trait and the cache's call, and the call-site spelling.

… ranks them

The transfer-source summary that credits a candidate worker for the KV
prefix it could fetch read two things the worker-selection stage must not
see: each worker's config (through WorkerConfigLike::kv_transfer_keys) and
the indexer's residency routing snapshot (through
KvTransferCandidates.routing_snapshot). Split the step in two.

The router resolves first: kv_hints::resolve_transfer_sources walks the
request's candidates with today's skips (sources no longer than every
target's local prefix or longer than the retained chain, worker ranks that
publish no source endpoint, cache owners missing from the snapshot, the
attached worker's topology for an owner that publishes none) and yields
ResolvedTransferSource records: who holds the prefix, how long it is, the
hashed hint worker type, the attached worker, and the topology labels.
KvTransferSourceSummary::new takes those records and the scope and ranks
them exactly as before; source_for is unchanged.

Worker keys move the same way. WorkerKvTransferKeys keeps its data,
target(), and a from_parts constructor over already-hashed labels, with
worker_type() and topology() accessors; deriving the keys from a config
becomes the WorkerKvTransferKeysExt extension trait beside
WorkerConfigLike, and WorkerKvTransferKeysCache moves next to it.
KvTransferCandidateSource moves to dynamo_router_protocol::kv_hints as
shared vocabulary; the indexer and kv-router re-export it at the old
paths. The label hashing (label_key, topology_keys) stays with the indexer,
which builds the snapshot keys; the router calls it for worker keys.

Step 5d-2 of the router split v2 plan (worker-selection boundary). DYNO-177.

Signed-off-by: Ishan Dhanani <ishandhanani@gmail.com>
@ishandhanani

Copy link
Copy Markdown
Owner Author

Landed upstream as ai-dynamo#18055 (squash commit 79692cf on main, 2026-11-11). Closing this fork review unit.

This branch had an error being deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant