Repository navigation
feat(planner): add runtime-configurable minimum endpoints #13038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
302cbcd
feat(planner): add runtime-configurable minimum endpoints
tedzhouhk e0b2a91
fix(planner): address runtime endpoint review feedback
tedzhouhk d9457ea
fix(planner): preserve zero legacy endpoint floor
tedzhouhk 9046732
docs(api): regenerate references from source stubs
tedzhouhk dae519c
fix(planner): keep control API internals private
tedzhouhk b594403
docs(planner): clarify minimum endpoint mode semantics
tedzhouhk a3e4e22
Merge remote-tracking branch 'origin/main' into hzhou-codex/dyn-3675-…
tedzhouhk e65cc66
docs(api): refresh planner source links
tedzhouhk 4b5cb68
docs(planner): clarify endpoint examples
tedzhouhk 2d5209e
docs(planner): document single-role endpoint defaults
tedzhouhk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Local runtime API for planner minimum endpoint configuration.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import logging | ||
| from typing import Any, Protocol | ||
|
|
||
| from aiohttp import web | ||
| from pydantic import BaseModel, ConfigDict, Field, ValidationError | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class _MinimumEndpointValidationError(ValueError): | ||
| """Raised when a well-formed runtime update is invalid for the planner.""" | ||
|
|
||
|
|
||
| class _MinimumEndpointUnavailableError(RuntimeError): | ||
| """Raised when a runtime update cannot safely run before its deadline.""" | ||
|
|
||
|
|
||
| class _MinimumEndpointController(Protocol): | ||
| async def get_min_endpoints(self) -> dict[str, Any]: | ||
| ... | ||
|
|
||
| async def patch_min_endpoints(self, updates: dict[str, int]) -> dict[str, Any]: | ||
| ... | ||
|
|
||
|
|
||
| class _MinimumEndpointsPatch(BaseModel): | ||
| model_config = ConfigDict(extra="forbid", strict=True) | ||
|
|
||
| min_endpoint: int | None = Field(default=None, ge=0) | ||
| prefill_min_endpoint: int | None = Field(default=None, ge=1) | ||
| decode_min_endpoint: int | None = Field(default=None, ge=1) | ||
|
|
||
|
|
||
| def _error(message: str, status: int) -> web.Response: | ||
| return web.json_response({"error": message}, status=status) | ||
|
|
||
|
|
||
| def _build_app(controller: _MinimumEndpointController) -> web.Application: | ||
| async def handle_get(_request: web.Request) -> web.Response: | ||
| try: | ||
| response = await controller.get_min_endpoints() | ||
| except _MinimumEndpointUnavailableError as exc: | ||
| return _error(str(exc), 503) | ||
| return web.json_response(response) | ||
|
|
||
| async def handle_patch(request: web.Request) -> web.Response: | ||
| try: | ||
| payload = await request.json() | ||
| except (json.JSONDecodeError, UnicodeDecodeError): | ||
| return _error("request body must be valid JSON", 400) | ||
| if not isinstance(payload, dict): | ||
| return _error("request body must be a JSON object", 400) | ||
|
|
||
| try: | ||
| patch = _MinimumEndpointsPatch.model_validate(payload) | ||
| except ValidationError as exc: | ||
| # Unknown fields make the patch structurally invalid (400). Type, | ||
| # range, and null errors on known fields are semantic validation | ||
| # failures (422). | ||
| status = ( | ||
| 400 | ||
| if any(error["type"] == "extra_forbidden" for error in exc.errors()) | ||
| else 422 | ||
| ) | ||
| return _error(str(exc), status) | ||
|
|
||
| fields = patch.model_fields_set | ||
| if not fields: | ||
| return _error("request body must include at least one endpoint field", 400) | ||
| if any(getattr(patch, field) is None for field in fields): | ||
| return _error("minimum endpoint fields cannot be null", 422) | ||
|
|
||
| updates = {field: int(getattr(patch, field)) for field in fields} | ||
| try: | ||
| response = await controller.patch_min_endpoints(updates) | ||
| except _MinimumEndpointUnavailableError as exc: | ||
| return _error(str(exc), 503) | ||
| except _MinimumEndpointValidationError as exc: | ||
| return _error(str(exc), 422) | ||
| return web.json_response(response) | ||
|
|
||
| app = web.Application() | ||
| app.router.add_get("/v1/min-endpoints", handle_get) | ||
| app.router.add_patch("/v1/min-endpoints", handle_patch) | ||
| return app | ||
|
|
||
|
|
||
| async def _start_control_api( | ||
| controller: _MinimumEndpointController, port: int | ||
| ) -> web.AppRunner: | ||
| """Start the localhost-only runtime configuration API.""" | ||
|
|
||
| runner = web.AppRunner(_build_app(controller)) | ||
| await runner.setup() | ||
| site = web.TCPSite(runner, "127.0.0.1", port) | ||
| try: | ||
| await site.start() | ||
| except Exception: | ||
| await runner.cleanup() | ||
| raise | ||
| logger.info( | ||
| "Planner runtime configuration API listening on " | ||
| "http://127.0.0.1:%s/v1/min-endpoints", | ||
| port, | ||
| ) | ||
| return runner |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.