From 9a7a5edd6ebd2695d21a26811329f25968b9523a Mon Sep 17 00:00:00 2001 From: zhaoxi Date: Thu, 4 Jun 2026 01:55:40 +0000 Subject: [PATCH] =?UTF-8?q?refactor(standalone):=20=E6=94=B6=E6=95=9B=20?= =?UTF-8?q?=5FSTANDALONE=20=E5=88=A4=E6=96=AD=E5=88=B0=20standalone=5Fprox?= =?UTF-8?q?y=20=E5=8D=95=E4=B8=80=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 各模块不再各自读 os.environ,统一从 standalone_proxy._STANDALONE 导入, 环境变量只在一处决定模式,减少散落的重复逻辑。 Co-Authored-By: Claude Opus 4.7 --- kilostar/api/__init__.py | 3 ++- kilostar/core/global_state_machine/global_state_machine.py | 4 +--- kilostar/core/global_state_machine/gsm_snapshot.py | 4 ++-- kilostar/utils/ray_hook.py | 3 +-- kilostar/worker_cluster/worker_cluster.py | 4 +--- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/kilostar/api/__init__.py b/kilostar/api/__init__.py index cc9acef..07b1bad 100644 --- a/kilostar/api/__init__.py +++ b/kilostar/api/__init__.py @@ -20,7 +20,8 @@ from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse, JSONResponse from fastapi.staticfiles import StaticFiles -_STANDALONE = os.environ.get("KILOSTAR_MODE", "distributed") == "standalone" +from kilostar.utils.standalone_proxy import _STANDALONE + if not _STANDALONE: from ray import serve diff --git a/kilostar/core/global_state_machine/global_state_machine.py b/kilostar/core/global_state_machine/global_state_machine.py index 9410dc7..355a9a5 100644 --- a/kilostar/core/global_state_machine/global_state_machine.py +++ b/kilostar/core/global_state_machine/global_state_machine.py @@ -12,11 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os from typing import Any, Dict, List, Optional, Tuple -from kilostar.utils.standalone_proxy import actor_class +from kilostar.utils.standalone_proxy import actor_class, _STANDALONE -_STANDALONE = os.environ.get("KILOSTAR_MODE", "distributed") == "standalone" if not _STANDALONE: import ray diff --git a/kilostar/core/global_state_machine/gsm_snapshot.py b/kilostar/core/global_state_machine/gsm_snapshot.py index 2cd02ec..b683095 100644 --- a/kilostar/core/global_state_machine/gsm_snapshot.py +++ b/kilostar/core/global_state_machine/gsm_snapshot.py @@ -30,11 +30,11 @@ GSM 仍然是 source of truth + 写入串行化器,但读路径解耦: from __future__ import annotations import asyncio -import os from dataclasses import dataclass, field from typing import Any, Callable, Dict, List, Optional, Tuple -_STANDALONE = os.environ.get("KILOSTAR_MODE", "distributed") == "standalone" +from kilostar.utils.standalone_proxy import _STANDALONE + if not _STANDALONE: import ray diff --git a/kilostar/utils/ray_hook.py b/kilostar/utils/ray_hook.py index 3096ebd..31c2831 100644 --- a/kilostar/utils/ray_hook.py +++ b/kilostar/utils/ray_hook.py @@ -11,12 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os import time from functools import lru_cache from typing import Any, Dict -_STANDALONE = os.environ.get("KILOSTAR_MODE", "distributed") == "standalone" +from kilostar.utils.standalone_proxy import _STANDALONE if not _STANDALONE: import ray diff --git a/kilostar/worker_cluster/worker_cluster.py b/kilostar/worker_cluster/worker_cluster.py index 62db4fc..76e3cc0 100644 --- a/kilostar/worker_cluster/worker_cluster.py +++ b/kilostar/worker_cluster/worker_cluster.py @@ -12,14 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import time import asyncio from collections import OrderedDict -from kilostar.utils.standalone_proxy import actor_class +from kilostar.utils.standalone_proxy import actor_class, _STANDALONE from kilostar.utils.ray_hook import ray_actor_hook -_STANDALONE = os.environ.get("KILOSTAR_MODE", "distributed") == "standalone" if _STANDALONE: from asyncio import Queue else: