Add CacheRoute strategy and KDN knowledge indexing; propagate request_ctx to scheduler and strategies#2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f64e089b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| items = await fetch_kdn_snapshot( | ||
| base_url=base_url, | ||
| need_fields=["kid", "length", "kv_ready"], | ||
| ) |
There was a problem hiding this comment.
Skip unreachable KDNs while building knowledge index
refresh_kdn_knowledge_index calls fetch_kdn_snapshot for every alive KDN without handling per-node failures. Since fetch_kdn_snapshot raises on timeout/HTTP errors and kdn_refresh_once invokes this step before any fallback selection, one temporarily unreachable KDN can abort the whole refresh pass, leaving both knowledge_table and kdn_knowledge_index stale even when other KDNs are healthy. This should degrade gracefully by catching errors per KDN and continuing with remaining nodes.
Useful? React with 👍 / 👎.
Motivation
Description
scheduler/strategy/cacheroute.pyimplementingCacheRouteStrategywhich selects KDNs by text coverage / KV coverage / overload heuristics and selects proxies by low inflight / qps / gpu_util, and exposesget_debug_snapshotfor/debug/strategy.scheduler/strategy/base.pyto accept arequest_ctxoptional parameter in theProxySelectionStrategy.selectsignature to pass precomputed context into strategies.scheduler/strategy/round_robin.pyto accept the newrequest_ctxargument and retain compatibility.scheduler/strategy/factory.pyunder the namecacheroute.refresh_kdn_knowledge_indextoscheduler/knowledge/kdn_sync.pyto build a lightweight per-KDN knowledge metadata index (mapping KDN -> {kid -> {length, kv_ready}}) and integrated its use into the KDN refresh flow so the scheduler keepsapp.state.kdn_knowledge_indexupdated.core/request.pyto accept an extrakdn_knowledge_indexargument inRequest.build_requestand to pass a compactrequest_ctxwhen calling strategyselect(includesknowledge_list,knowledge_length,prompt_token_length,kdn_knowledge_index, etc.).scheduler/scheduler.pyto: provide richer proxy/KDN metadata to strategies, call_handle_clientwithkdn_knowledge_index, populatekdn_knowledge_indexin app state, and include strategy debug snapshot in/debug/strategyoutput if available.test/demo_scheduler.pyto add a--cacherouteshortcut flag that sets--strategy cacheroutewhen launching the demo scheduler.Testing
import scheduler,import scheduler.strategy.cacheroute) and validated no immediate import errors (success).--cacherouteto exercise the new strategy during integration testing.Codex Task