Add CacheRoute strategy, KDN knowledge index and pass request context to strategy.select#1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fcb455e9e6
ℹ️ 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.
Isolate failing KDN snapshots during index refresh
This loop makes kdn_refresh_once depend on successful /knowledge/snapshot calls to every alive KDN: if one node times out or returns non-2xx, fetch_kdn_snapshot raises and the whole refresh aborts before the normal table-update path runs. In mixed-health clusters, one flaky KDN can block scheduler knowledge refresh globally and keep knowledge_table stale even when other KDNs are healthy.
Useful? React with 👍 / 👎.
| payload_for_build = dict(payload) | ||
| payload_for_build["_scheduler_kdn_knowledge_index"] = getattr(request.app.state, "kdn_knowledge_index", {}) |
There was a problem hiding this comment.
Stop injecting full KDN index into request payload
Adding _scheduler_kdn_knowledge_index to the per-request payload makes each request carry the full scheduler-side knowledge index object, and _handle_client logs payloads when SCHEDULER_VERBOSE_REQUEST_LOG is enabled (default is 1 in core/config.py). With non-trivial knowledge sets this can massively inflate per-request log volume and request-time overhead, turning routing metadata into a hot-path performance issue.
Useful? React with 👍 / 👎.
Motivation
request_ctxinto proxy/kdn selection strategies.Description
refresh_kdn_knowledge_indexinscheduler/knowledge/kdn_sync.pyto fetch per-KDN metadata (kid->length/kv_ready) and store it onapp.state.kdn_knowledge_index, and integrated its usage intokdn_refresh_once.scheduler/strategy/base.pyto accept an optionalrequest_ctxand updatedround_robinto keep the unified signature.CacheRouteStrategyinscheduler/strategy/cacheroute.pythat ranks KDNs by text coverage / KV cache coverage / overload status and selects proxies byinflight/qps/gpu_utilwith stable tie-breaking.scheduler/strategy/factory.pyand added a--cacherouteshortcut intest/demo_scheduler.py.scheduler/scheduler.pyto prepare and passrequest_ctx(includingkdn_knowledge_index,knowledge_list, and other lightweight fields) and to send richerproxies/kdnsmetadata into strategy selection; adaptedcore/request.pyto includerequest_ctxwhen callingstrategy.select.Testing
scheduler,CacheRouteStrategy, and callingselectwith simple/dummy inputs, which succeeded.demo_scheduler) with the--cacherouteshortcut to verify environment wiring and that the scheduler initializes without immediate exceptions.Codex Task