hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

commit d1b66559f0fb9f51993ae88cf15bbf63a628b747
parent ae14a4bc218727c37cef34953bed21c98626a13d
Author: triesap <tyson@radroots.org>
Date:   Sun, 14 Jun 2026 15:50:10 -0700

runtime: add strict max provider config

- replace bridge-shaped config with assisted max_local provider structs
- validate provider id, URLs, model, route, timeout, and runtime gate before enabling
- expose effective provider config through runtime status
- add stdio tests for valid and invalid max_local TOML

Diffstat:
Msrc/hyf_runtime/config.mojo | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Msrc/hyf_runtime/status.mojo | 22+++++++++++++++++-----
Msrc/hyf_stdio/control/assisted_runtime.mojo | 6+-----
Mtests/test_hyf.mojo | 2+-
Mtests/test_stdio_contract.mojo | 182++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
5 files changed, 257 insertions(+), 51 deletions(-)

diff --git a/src/hyf_runtime/config.mojo b/src/hyf_runtime/config.mojo @@ -23,27 +23,43 @@ struct HyfExecutionRuntimeConfig(Defaultable, Copyable, Movable): @fieldwise_init -struct HyfAssistBridgeRuntimeConfig(Defaultable, Copyable, Movable): - var bridge_enabled: Bool - var transport: String - var endpoint: String +struct HyfMaxLocalProviderRuntimeConfig(Defaultable, Copyable, Movable): + var enabled: Bool + var base_url: String + var health_url: String + var model: String + var route: String + var request_timeout_ms: Int def __init__(out self): - self.bridge_enabled = False - self.transport = "stdio" - self.endpoint = "" + self.enabled = False + self.base_url = "" + self.health_url = "" + self.model = "" + self.route = "" + self.request_timeout_ms = 0 + + +@fieldwise_init +struct HyfAssistedRuntimeConfig(Defaultable, Copyable, Movable): + var provider: String + var max_local: HyfMaxLocalProviderRuntimeConfig + + def __init__(out self): + self.provider = "" + self.max_local = HyfMaxLocalProviderRuntimeConfig() @fieldwise_init struct HyfRuntimeConfig(Defaultable, Copyable, Movable): var service: HyfServiceRuntimeConfig var runtime: HyfExecutionRuntimeConfig - var assist: HyfAssistBridgeRuntimeConfig + var assisted: HyfAssistedRuntimeConfig def __init__(out self): self.service = HyfServiceRuntimeConfig() self.runtime = HyfExecutionRuntimeConfig() - self.assist = HyfAssistBridgeRuntimeConfig() + self.assisted = HyfAssistedRuntimeConfig() @fieldwise_init @@ -77,11 +93,16 @@ def assisted_execution_enabled(config: HyfLoadedRuntimeConfig) -> Bool: def assisted_runtime_configured(config: HyfLoadedRuntimeConfig) -> Bool: return ( - config.effective.assist.bridge_enabled - and not String(config.effective.assist.endpoint).strip() == "" + config.effective.runtime.allow_assisted + and config.effective.assisted.provider == "max_local" + and config.effective.assisted.max_local.enabled ) +def max_local_provider_configured(config: HyfLoadedRuntimeConfig) -> Bool: + return assisted_runtime_configured(config) + + def load_runtime_config(path: String) -> HyfLoadedRuntimeConfig: var defaults = default_runtime_config() if String(path).strip() == "" or not exists(path): @@ -118,13 +139,46 @@ def _validate_runtime_config(config: HyfRuntimeConfig) raises: "runtime.default_execution_mode must be 'deterministic' in the foundation wave" ) - if config.assist.transport != "stdio": - raise Error("assist.transport must be 'stdio'") - - if ( - config.assist.bridge_enabled - and String(config.assist.endpoint).strip() == "" - ): - raise Error( - "assist.endpoint must be configured when assist.bridge_enabled is true" - ) + if config.runtime.allow_assisted: + if config.assisted.provider != "max_local": + raise Error( + "assisted.provider must be 'max_local' when runtime.allow_assisted is true" + ) + + if config.assisted.provider != "" and config.assisted.provider != "max_local": + raise Error("assisted.provider must be 'max_local'") + + if config.assisted.max_local.enabled: + if not config.runtime.allow_assisted: + raise Error( + "runtime.allow_assisted must be true when assisted.max_local.enabled is true" + ) + if config.assisted.provider != "max_local": + raise Error( + "assisted.provider must be 'max_local' when assisted.max_local.enabled is true" + ) + _validate_max_local_provider_config(config.assisted.max_local) + + +def _require_non_empty(value: String, context: String) raises: + if String(value).strip() == "": + raise Error(context + " must not be empty") + + +def _require_http_url(value: String, context: String) raises: + var trimmed = String(value).strip() + if not (trimmed.startswith("http://") or trimmed.startswith("https://")): + raise Error(context + " must use http or https") + + +def _validate_max_local_provider_config( + config: HyfMaxLocalProviderRuntimeConfig +) raises: + _require_non_empty(config.base_url, "assisted.max_local.base_url") + _require_http_url(config.base_url, "assisted.max_local.base_url") + _require_non_empty(config.health_url, "assisted.max_local.health_url") + _require_http_url(config.health_url, "assisted.max_local.health_url") + _require_non_empty(config.model, "assisted.max_local.model") + _require_non_empty(config.route, "assisted.max_local.route") + if config.request_timeout_ms <= 0: + raise Error("assisted.max_local.request_timeout_ms must be greater than zero") diff --git a/src/hyf_runtime/status.mojo b/src/hyf_runtime/status.mojo @@ -76,19 +76,31 @@ def build_runtime_status_value(context: RuntimeStartupContext) raises -> Value: ) effective.set( "assisted_runtime_enabled", - Value(context.config.effective.assist.bridge_enabled), + Value(context.config.effective.runtime.allow_assisted), ) effective.set( "assisted_runtime_configured", Value(assisted_runtime_configured(context.config)), ) effective.set( - "assist_transport", - Value(String(context.config.effective.assist.transport)), + "assisted_provider", + Value(String(context.config.effective.assisted.provider)), + ) + effective.set( + "max_local_enabled", + Value(context.config.effective.assisted.max_local.enabled), + ) + effective.set( + "max_local_model", + Value(String(context.config.effective.assisted.max_local.model)), + ) + effective.set( + "max_local_route", + Value(String(context.config.effective.assisted.max_local.route)), ) effective.set( - "assist_endpoint", - Value(String(context.config.effective.assist.endpoint)), + "max_local_request_timeout_ms", + Value(context.config.effective.assisted.max_local.request_timeout_ms), ) config.set("effective", effective) status.set("config", config) diff --git a/src/hyf_stdio/control/assisted_runtime.mojo b/src/hyf_stdio/control/assisted_runtime.mojo @@ -23,16 +23,12 @@ def resolve_assisted_runtime_status( if assisted_execution_enabled(config): state = "unavailable" if configured else "unconfigured" - var endpoint = String("") - if configured: - endpoint = String(config.effective.assist.endpoint) - return AssistedRuntimeStatus( id=provider_runtime_id(), kind="provider_runtime", contract_version=assisted_runtime_contract_version(), transport="deferred", - endpoint=endpoint, + endpoint="", backend_kind="deferred", provider="", route="", diff --git a/tests/test_hyf.mojo b/tests/test_hyf.mojo @@ -856,7 +856,7 @@ def test_missing_input_returns_invalid_request() raises: ) -def test_assisted_request_falls_back_deterministically_when_bridge_is_unavailable() raises: +def test_assisted_request_falls_back_deterministically_when_provider_is_unavailable() raises: var result = _dispatch( load_scenario_request_json( "scenarios/assisted_backend_unavailable.json" diff --git a/tests/test_stdio_contract.mojo b/tests/test_stdio_contract.mojo @@ -39,6 +39,54 @@ def _array_contains_string(value: Value, expected: String) raises -> Bool: return False +def _max_local_runtime_config_toml() -> String: + return ( + '[service]\ntransport = "stdio"\n\n' + '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' + '[assisted]\nprovider = "max_local"\n\n' + '[assisted.max_local]\nenabled = true\n' + 'base_url = "http://127.0.0.1:8000/v1"\n' + 'health_url = "http://127.0.0.1:8000/health"\n' + 'model = "max-local-query-rewrite"\n' + 'route = "provider_runtime.query_rewrite.max_local"\n' + 'request_timeout_ms = 15000\n' + ) + + +def _assert_invalid_runtime_config_load_error( + config_text: String, expected_error_fragment: String +) raises: + with TemporaryDirectory() as temp_dir: + var startup_config_path = Path(temp_dir) / "invalid-hyf-config.toml" + startup_config_path.write_text(config_text) + with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): + with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): + var response = run_stdio_entrypoint( + "src/main.mojo", + load_scenario_request_json("scenarios/status_ok.json"), + "--config", + startup_config_path.__fspath__(), + ) + + assert_true(response["ok"].bool_value()) + assert_equal( + response["output"]["runtime"]["config"]["loaded"] + .bool_value(), + False, + ) + assert_equal( + response["output"]["runtime"]["config"]["load_state"] + .string_value(), + "invalid", + ) + assert_true( + response["output"]["runtime"]["config"]["load_error"] + .string_value() + .find(expected_error_fragment) + >= 0 + ) + + def test_status_success() raises: var response = run_hyf_stdio( load_scenario_request_json("scenarios/status_ok.json") @@ -262,11 +310,7 @@ def test_status_reports_repo_local_runtime_truth() raises: def test_status_loads_valid_runtime_config_truthfully() raises: with TemporaryDirectory() as temp_dir: var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" - startup_config_path.write_text( - '[service]\ntransport = "stdio"\n\n' - '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' - '[assist]\nbridge_enabled = true\ntransport = "stdio"\nendpoint = "hyf-assistd://local"\n' - ) + startup_config_path.write_text(_max_local_runtime_config_toml()) with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): var response = run_stdio_entrypoint( @@ -371,9 +415,35 @@ def test_status_loads_valid_runtime_config_truthfully() raises: ) assert_equal( response["output"]["runtime"]["config"]["effective"][ - "assist_endpoint" + "assisted_provider" ].string_value(), - "hyf-assistd://local", + "max_local", + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "max_local_enabled" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "max_local_model" + ].string_value(), + "max-local-query-rewrite", + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "max_local_route" + ].string_value(), + "provider_runtime.query_rewrite.max_local", + ) + assert_equal( + Int( + response["output"]["runtime"]["config"]["effective"][ + "max_local_request_timeout_ms" + ].int_value() + ), + 15000, ) assert_true( not _has_key( @@ -454,14 +524,92 @@ def test_status_reports_invalid_runtime_config_without_crashing() raises: ) -def test_capabilities_reports_configured_assist_runtime_deferred_truthfully() raises: +def test_status_rejects_invalid_max_local_runtime_config() raises: + var prefix = ( + '[service]\ntransport = "stdio"\n\n' + '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' + ) + var disabled_prefix = ( + '[service]\ntransport = "stdio"\n\n' + '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = false\n\n' + ) + var provider = '[assisted]\nprovider = "max_local"\n\n' + var max_local_header = '[assisted.max_local]\nenabled = true\n' + _assert_invalid_runtime_config_load_error( + prefix + '[assisted]\nprovider = "unsupported"\n', + "assisted.provider", + ) + _assert_invalid_runtime_config_load_error( + disabled_prefix + + provider + + max_local_header + + 'base_url = "http://127.0.0.1:8000/v1"\n' + + 'health_url = "http://127.0.0.1:8000/health"\n' + + 'model = "max-local-query-rewrite"\n' + + 'route = "provider_runtime.query_rewrite.max_local"\n' + + 'request_timeout_ms = 15000\n', + "runtime.allow_assisted", + ) + _assert_invalid_runtime_config_load_error( + prefix + + provider + + max_local_header + + 'health_url = "http://127.0.0.1:8000/health"\n' + + 'model = "max-local-query-rewrite"\n' + + 'route = "provider_runtime.query_rewrite.max_local"\n' + + 'request_timeout_ms = 15000\n', + "assisted.max_local.base_url", + ) + _assert_invalid_runtime_config_load_error( + prefix + + provider + + max_local_header + + 'base_url = "file:///tmp/max"\n' + + 'health_url = "http://127.0.0.1:8000/health"\n' + + 'model = "max-local-query-rewrite"\n' + + 'route = "provider_runtime.query_rewrite.max_local"\n' + + 'request_timeout_ms = 15000\n', + "assisted.max_local.base_url", + ) + _assert_invalid_runtime_config_load_error( + prefix + + provider + + max_local_header + + 'base_url = "http://127.0.0.1:8000/v1"\n' + + 'health_url = "http://127.0.0.1:8000/health"\n' + + 'model = ""\n' + + 'route = "provider_runtime.query_rewrite.max_local"\n' + + 'request_timeout_ms = 15000\n', + "assisted.max_local.model", + ) + _assert_invalid_runtime_config_load_error( + prefix + + provider + + max_local_header + + 'base_url = "http://127.0.0.1:8000/v1"\n' + + 'health_url = "http://127.0.0.1:8000/health"\n' + + 'model = "max-local-query-rewrite"\n' + + 'route = ""\n' + + 'request_timeout_ms = 15000\n', + "assisted.max_local.route", + ) + _assert_invalid_runtime_config_load_error( + prefix + + provider + + max_local_header + + 'base_url = "http://127.0.0.1:8000/v1"\n' + + 'health_url = "http://127.0.0.1:8000/health"\n' + + 'model = "max-local-query-rewrite"\n' + + 'route = "provider_runtime.query_rewrite.max_local"\n' + + 'request_timeout_ms = 0\n', + "assisted.max_local.request_timeout_ms", + ) + + +def test_capabilities_reports_configured_provider_runtime_truthfully() raises: with TemporaryDirectory() as temp_dir: var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" - startup_config_path.write_text( - '[service]\ntransport = "stdio"\n\n' - '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' - '[assist]\nbridge_enabled = true\ntransport = "stdio"\nendpoint = "hyf-assistd://local"\n' - ) + startup_config_path.write_text(_max_local_runtime_config_toml()) with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): var response = run_stdio_entrypoint( @@ -504,14 +652,10 @@ def test_capabilities_reports_configured_assist_runtime_deferred_truthfully() ra ) -def test_query_rewrite_falls_back_deterministically_when_bridge_is_unavailable() raises: +def test_query_rewrite_falls_back_deterministically_when_provider_is_unavailable() raises: with TemporaryDirectory() as temp_dir: var startup_config_path = Path(temp_dir) / "explicit-hyf-config.toml" - startup_config_path.write_text( - '[service]\ntransport = "stdio"\n\n' - '[runtime]\ndefault_execution_mode = "deterministic"\nallow_assisted = true\n\n' - '[assist]\nbridge_enabled = true\ntransport = "stdio"\nendpoint = "hyf-assistd://local"\n' - ) + startup_config_path.write_text(_max_local_runtime_config_toml()) with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"): with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, temp_dir): var response = run_stdio_entrypoint(