Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(cli): preserve environment cache settings

svonavae7f0c296cf84
diff --git a/packages/sie_server/src/sie_server/cli.py b/packages/sie_server/src/sie_server/cli.py
index 275036412..21b441519 100644
--- a/packages/sie_server/src/sie_server/cli.py
+++ b/packages/sie_server/src/sie_server/cli.py
@@ -41,6 +41,7 @@ from sie_sdk.bundle_utils import (
match_bundle_model_adapters,
match_bundle_models,
)
+from sie_sdk.cache import get_cache_config
import sie_server
from sie_server.api.decisions import router as decisions_router
@@ -513,11 +514,10 @@ def serve(
"--cluster-cache",
help="Cluster cache URL (s3://, gs://, abfs(s)://, or oss://)",
),
- hf_fallback: bool = typer.Option(
- True,
+ hf_fallback: bool | None = typer.Option(
+ None,
"--hf-fallback/--no-hf-fallback",
- envvar="SIE_HF_FALLBACK",
- help="Enable HuggingFace Hub fallback",
+ help="Override HuggingFace Hub fallback (default: SIE_HF_FALLBACK or enabled)",
),
reload: bool = typer.Option(default=False, help="Enable auto-reload for development"),
tracing: bool = typer.Option(default=False, help="Enable OpenTelemetry tracing (exports to localhost:4317)"),
@@ -776,15 +776,16 @@ def serve(
# Pass cache config via environment variables
if local_cache:
os.environ["SIE_LOCAL_CACHE"] = str(Path(local_cache).resolve())
- elif "SIE_LOCAL_CACHE" in os.environ:
+ elif local_cache is not None and "SIE_LOCAL_CACHE" in os.environ:
del os.environ["SIE_LOCAL_CACHE"]
if cluster_cache:
os.environ["SIE_CLUSTER_CACHE"] = cluster_cache
- elif "SIE_CLUSTER_CACHE" in os.environ:
+ elif cluster_cache is not None and "SIE_CLUSTER_CACHE" in os.environ:
del os.environ["SIE_CLUSTER_CACHE"]
- os.environ["SIE_HF_FALLBACK"] = "true" if hf_fallback else "false"
+ if hf_fallback is not None:
+ os.environ["SIE_HF_FALLBACK"] = "true" if hf_fallback else "false"
# Configure tracing via environment variables
if tracing:
@@ -819,9 +820,10 @@ def serve(
f" → OpenAI base http://localhost:{port}/v1 (embeddings · rerank; chat/completions with -b sglang)"
)
typer.echo("")
- if cluster_cache:
- typer.echo(f"Cluster cache: {cluster_cache}")
- if not hf_fallback:
+ cache_config = get_cache_config()
+ if cache_config.cluster_cache:
+ typer.echo(f"Cluster cache: {cache_config.cluster_cache}")
+ if not cache_config.hf_fallback:
typer.echo("HuggingFace Hub fallback: disabled")
# Handle preload models (CLI flag takes precedence, then env var from Helm configmap)
diff --git a/packages/sie_server/tests/test_cli_cache.py b/packages/sie_server/tests/test_cli_cache.py
index e2bf0f1f8..e9471f4ce 100644
--- a/packages/sie_server/tests/test_cli_cache.py
+++ b/packages/sie_server/tests/test_cli_cache.py
@@ -23,13 +23,17 @@ def isolated_environment(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Ite
os.environ.update(saved)
[email protected]("environment", [None, "true", "false", "1", "0", "yes", "no"])
+ "environment",
+ [None, "true", "false", "1", "0", "yes", "no", "TRUE", "FALSE", "on", "off", "", "invalid", " true "],
+)
@pytest.mark.parametrize("flag", [None, "--hf-fallback", "--no-hf-fallback"])
def test_cli_cache_policy_precedence(
monkeypatch: pytest.MonkeyPatch, environment: str | None, flag: str | None
) -> None:
if environment is not None:
monkeypatch.setenv("SIE_HF_FALLBACK", environment)
+ environment_policy = get_cache_config().hf_fallback
observed = []
run_server = Mock(side_effect=lambda **_kwargs: observed.append(get_cache_config().hf_fallback))
monkeypatch.setattr(cli, "run_server", run_server)
@@ -40,9 +44,57 @@ def test_cli_cache_policy_precedence(
result = CliRunner().invoke(cli.app, args)
assert result.exit_code == 0, result.output
- expected = (
- flag == "--hf-fallback" if flag is not None else environment is None or environment in {"true", "1", "yes"}
- )
+ expected = flag == "--hf-fallback" if flag is not None else environment_policy
assert observed == [expected]
- assert os.environ["SIE_HF_FALLBACK"] == str(expected).lower()
+ assert os.environ.get("SIE_HF_FALLBACK") == (environment if flag is None else str(expected).lower())
+ assert ("HuggingFace Hub fallback: disabled" in result.output) is (not expected)
run_server.assert_called_once()
+
+
+ ("option", "environment_name", "field"),
+ [
+ ("--local-cache", "SIE_LOCAL_CACHE", "local_cache"),
+ ("--cluster-cache", "SIE_CLUSTER_CACHE", "cluster_cache"),
+ ],
+)
[email protected]("has_environment", [False, True])
[email protected]("flag_value", [None, "override", ""])
+def test_cli_cache_directory_precedence(
+ monkeypatch: pytest.MonkeyPatch,
+ tmp_path: Path,
+ option: str,
+ environment_name: str,
+ field: str,
+ has_environment: bool,
+ flag_value: str | None,
+) -> None:
+ default_value = getattr(get_cache_config(), field)
+ environment_value = str(tmp_path / "environment-cache") if has_environment else None
+ if environment_value is not None:
+ monkeypatch.setenv(environment_name, environment_value)
+ monkeypatch.setenv("SIE_HF_FALLBACK", "false")
+ initial_value = getattr(get_cache_config(), field)
+ observed = []
+ monkeypatch.setattr(cli, "run_server", Mock(side_effect=lambda **_kwargs: observed.append(get_cache_config())))
+ args = ["serve", "--host", "127.0.0.1"]
+ if flag_value is not None:
+ args.extend([option, flag_value])
+
+ result = CliRunner().invoke(cli.app, args)
+
+ assert result.exit_code == 0, result.output
+ if flag_value is None:
+ expected_value = initial_value
+ expected_environment = environment_value
+ elif flag_value:
+ expected_value = Path(flag_value).resolve() if field == "local_cache" else flag_value
+ expected_environment = str(expected_value)
+ else:
+ expected_value = default_value
+ expected_environment = None
+ assert len(observed) == 1
+ assert getattr(observed[0], field) == expected_value
+ assert observed[0].hf_fallback is False
+ assert os.environ.get(environment_name) == expected_environment
+ assert ("Cluster cache:" in result.output) is bool(observed[0].cluster_cache)