Add CacheRoute strategy: per-KDN index, topology-aware proxy selection, and demo flags#3
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31c2292c86
ℹ️ 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 KDN snapshot errors during index refresh
refresh_kdn_knowledge_index now performs a blocking snapshot call for every alive KDN, but a single fetch_kdn_snapshot failure aborts the whole function and propagates out of kdn_refresh_once. In practice, one stale/unreachable KDN in the alive set causes all refresh cycles to fail, so knowledge_table and kdn_knowledge_index stop updating for healthy nodes as well. This should degrade gracefully per KDN (skip/log failed node) instead of failing the full refresh pass.
Useful? React with 👍 / 👎.
| bw_tier = int(item.get("bandwidth_tier", 0) or 0) | ||
| lat_tier = int(item.get("latency_tier", 999) or 999) |
There was a problem hiding this comment.
Validate topology tier values before int conversion
The strategy casts bandwidth_tier/latency_tier directly with int(...) from proxy-provided meta.kdn_links. If one proxy advertises a non-numeric value (e.g., from misconfigured PROXY_KDN_LINKS_JSON), this raises ValueError inside routing, which bubbles out of strategy selection and leaves the request without a selected route (ultimately returning a routing failure). Tier parsing should be defensive and fall back to defaults for invalid values.
Useful? React with 👍 / 👎.
Motivation
Description
scheduler/strategy/cacheroute.pyimplementing lexicographic, non-weighted decision rules for KDN selection (text_full -> not_overloaded -> kv_cover_len -> load/tie-break) and a topology-aware proxy selection flow (best topology group -> load-safe filter -> affinity -> tie-break rotation), with environment-configurable thresholds and affinity decay/top-k retention.scheduler/strategy/base.pyto accept an optional lightweightrequest_ctx(containsknowledge_list,kdn_knowledge_index, etc.) and updatedround_robinto keep compatibility with the new signature.scheduler/knowledge/kdn_sync.py(methodrefresh_kdn_knowledge_index) and integrated it with the existing KDN refresh flow so strategies can compute per-KDN coverage without re-running retrieval/embedding.core/request.pynow builds a compactrequest_ctxandscheduler/scheduler.pypasseskdn_knowledge_indexinto_handle_client-> strategy select call;/debug/strategyexposes the last decision snapshot when available.meta.kdn_linksduring proxy registration; proxy side readsPROXY_KDN_LINKS_JSON(or demo--kdn-links-json) inproxy/proxy.pyandtest/demo_proxy.pyto populate that field without changing wire schemas.test/demo_scheduler.pyaccepts--cacheroute(shortcut for--strategy cacheroute) andtest/demo_proxy.pyaccepts--kdn-links-jsonfor quick experiments.Testing
python3 -m py_compile scheduler/strategy/cacheroute.py proxy/proxy.py test/demo_proxy.py(succeeded).cacheroutemodule via file import (avoiding full package imports) and ran selection scenarios validating: topology-first proxy group selection, deterministic tie rotation, and affinity updates (succeeded).uvicornmissing) when importing top-levelscheduler(this is an environment issue, not strategy logic); as a workaround we used direct module loading for strategy tests (documented and succeeded).Codex Task