[Bugfix][Model] Allow Run:ai memory_limit sentinel values (#47337)

Signed-off-by: Ting Sun <suntcrick@gmail.com>
This commit is contained in:
Ting SUN
2026-07-05 00:08:34 +00:00
committed by GitHub
parent 4a6bf3c77f
commit 91b5647300
2 changed files with 24 additions and 16 deletions
@@ -119,6 +119,6 @@ def test_runai_invalid_extra_config_leaves_environ_untouched():
# os.environ (all values are validated before any global mutation). # os.environ (all values are validated before any global mutation).
with patch.dict(os.environ, {}, clear=False): with patch.dict(os.environ, {}, clear=False):
os.environ.pop("RUNAI_STREAMER_CONCURRENCY", None) os.environ.pop("RUNAI_STREAMER_CONCURRENCY", None)
with pytest.raises(ValueError, match="memory_limit must be a positive integer"): with pytest.raises(ValueError, match="memory_limit must be an integer >= -1"):
_runai_loader({"concurrency": 16, "memory_limit": -5}) _runai_loader({"concurrency": 16, "memory_limit": -5})
assert "RUNAI_STREAMER_CONCURRENCY" not in os.environ assert "RUNAI_STREAMER_CONCURRENCY" not in os.environ
@@ -47,21 +47,29 @@ class RunaiModelStreamerLoader(BaseModelLoader):
# Validate every value before mutating os.environ, so a later # Validate every value before mutating os.environ, so a later
# invalid key cannot leave an earlier one partially applied. # invalid key cannot leave an earlier one partially applied.
env_updates: dict[str, str] = {} env_updates: dict[str, str] = {}
for key, env_var in ( if "concurrency" in extra_config:
("concurrency", "RUNAI_STREAMER_CONCURRENCY"), concurrency = extra_config["concurrency"]
("memory_limit", "RUNAI_STREAMER_MEMORY_LIMIT"), if (
): isinstance(concurrency, bool)
if key in extra_config: or not isinstance(concurrency, int)
value = extra_config[key] or concurrency <= 0
if ( ):
isinstance(value, bool) raise ValueError(
or not isinstance(value, int) f"concurrency must be a positive integer, got {concurrency!r}"
or value <= 0 )
): env_updates["RUNAI_STREAMER_CONCURRENCY"] = str(concurrency)
raise ValueError(
f"{key} must be a positive integer, got {value!r}" if "memory_limit" in extra_config:
) memory_limit = extra_config["memory_limit"]
env_updates[env_var] = str(value) if (
isinstance(memory_limit, bool)
or not isinstance(memory_limit, int)
or memory_limit < -1
):
raise ValueError(
f"memory_limit must be an integer >= -1, got {memory_limit!r}"
)
env_updates["RUNAI_STREAMER_MEMORY_LIMIT"] = str(memory_limit)
os.environ.update(env_updates) os.environ.update(env_updates)
runai_streamer_s3_endpoint = os.getenv("RUNAI_STREAMER_S3_ENDPOINT") runai_streamer_s3_endpoint = os.getenv("RUNAI_STREAMER_S3_ENDPOINT")