Skip to content

Add CacheRoute strategy, KDN knowledge index and pass request context to strategy.select#1

Merged
zhy1658858023 merged 1 commit into
mainfrom
codex/understand-project-structure-for-scheduler-development
Mar 24, 2026
Merged

Add CacheRoute strategy, KDN knowledge index and pass request context to strategy.select#1
zhy1658858023 merged 1 commit into
mainfrom
codex/understand-project-structure-for-scheduler-development

Conversation

@zhy1658858023

Copy link
Copy Markdown
Collaborator

Motivation

  • Provide a scheduler-side lightweight per-KDN knowledge metadata index so strategies can reason about which KDN can satisfy knowledge/RAG requests without re-fetching embeddings.
  • Enable richer routing decisions by passing a normalized request_ctx into proxy/kdn selection strategies.
  • Implement a first-phase CacheRoute strategy to pick KDNs that best cover requested knowledge and choose less-loaded proxies accordingly.

Description

  • Added refresh_kdn_knowledge_index in scheduler/knowledge/kdn_sync.py to fetch per-KDN metadata (kid -> length/kv_ready) and store it on app.state.kdn_knowledge_index, and integrated its usage into kdn_refresh_once.
  • Extended the strategy API in scheduler/strategy/base.py to accept an optional request_ctx and updated round_robin to keep the unified signature.
  • Implemented CacheRouteStrategy in scheduler/strategy/cacheroute.py that ranks KDNs by text coverage / KV cache coverage / overload status and selects proxies by inflight/qps/gpu_util with stable tie-breaking.
  • Registered the new strategy in scheduler/strategy/factory.py and added a --cacheroute shortcut in test/demo_scheduler.py.
  • Enriched scheduler internals in scheduler/scheduler.py to prepare and pass request_ctx (including kdn_knowledge_index, knowledge_list, and other lightweight fields) and to send richer proxies/kdns metadata into strategy selection; adapted core/request.py to include request_ctx when calling strategy.select.

Testing

  • Performed smoke import and instantiation checks by importing scheduler, CacheRouteStrategy, and calling select with simple/dummy inputs, which succeeded.
  • Launched the demo startup path (demo_scheduler) with the --cacheroute shortcut to verify environment wiring and that the scheduler initializes without immediate exceptions.
  • No new automated unit tests were added in this change.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +62 to +65
items = await fetch_kdn_snapshot(
base_url=base_url,
need_fields=["kid", "length", "kv_ready"],
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread scheduler/scheduler.py
Comment on lines +472 to +473
payload_for_build = dict(payload)
payload_for_build["_scheduler_kdn_knowledge_index"] = getattr(request.app.state, "kdn_knowledge_index", {})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@zhy1658858023 zhy1658858023 merged commit 27b86f8 into main Mar 24, 2026
@zhy1658858023 zhy1658858023 deleted the codex/understand-project-structure-for-scheduler-development branch March 24, 2026 07:25
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