hyf

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

commit 18359a016c6499e98679d2cf4ca597e4195a2b32
parent 249f73211c6c6e9965814f1abc7c05d80fbf2828
Author: triesap <tyson@radroots.org>
Date:   Sun, 12 Apr 2026 00:49:25 +0000

runtime: load bounded hyf config

Diffstat:
Mpixi.lock | 24++++++++++++++++++++++++
Mpixi.toml | 1+
Asrc/hyf_runtime/config.mojo | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/hyf_runtime/startup.mojo | 4++++
Msrc/hyf_runtime/status.mojo | 43+++++++++++++++++++++++++++++++++++++++++--
Msrc/hyf_stdio/control/status.mojo | 9+++++++--
Mtests/fixtures/v1/scenarios/status_ok.json | 2+-
Mtests/test_hyf.mojo | 18++++++++++++++++--
Mtests/test_repo_local_process_contract.mojo | 8++++++++
Mtests/test_stdio_contract.mojo | 188+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 420 insertions(+), 7 deletions(-)

diff --git a/pixi.lock b/pixi.lock @@ -62,6 +62,8 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.7-hb78ec9c_6.conda - conda: ../../../../vendor/mojo/mojson build: hb0f4dca_0 + - conda: ../../../../vendor/mojo/morph + build: hb0f4dca_0 osx-arm64: - conda: https://conda.anaconda.org/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_2.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-hd037594_9.conda @@ -110,6 +112,8 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/zstd-1.5.7-hbf9d68e_6.conda - conda: ../../../../vendor/mojo/mojson build: h60d57d3_0 + - conda: ../../../../vendor/mojo/morph + build: h60d57d3_0 packages: - conda: https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-20_gnu.conda build_number: 20 @@ -598,6 +602,26 @@ packages: - libstdcxx >=15 - libgcc >=15 license: Apache-2.0 +- conda: ../../../../vendor/mojo/morph + name: morph + version: 0.1.0 + build: h60d57d3_0 + subdir: osx-arm64 + variants: + target_platform: osx-arm64 + depends: + - mojo <1.0 + license: MIT +- conda: ../../../../vendor/mojo/morph + name: morph + version: 0.1.0 + build: hb0f4dca_0 + subdir: linux-64 + variants: + target_platform: linux-64 + depends: + - mojo <1.0 + license: MIT - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.1.0-pyha770c72_0.conda sha256: 6ed158e4e5dd8f6a10ad9e525631e35cee8557718f83de7a4e3966b1f772c4b1 md5: e9c622e0d00fa24a6292279af3ab6d06 diff --git a/pixi.toml b/pixi.toml @@ -14,6 +14,7 @@ preview = ["pixi-build"] [dependencies] mojo = "=0.26.3.0.dev2026040805" mojson = { path = "../../../../vendor/mojo/mojson" } +morph = { path = "../../../../vendor/mojo/morph" } [tasks] run = "mojo run src/main.mojo" diff --git a/src/hyf_runtime/config.mojo b/src/hyf_runtime/config.mojo @@ -0,0 +1,130 @@ +from std.os.path import exists +from std.pathlib import Path + +from morph.toml import from_toml + + +@fieldwise_init +struct HyfServiceRuntimeConfig(Defaultable, Copyable, Movable): + var transport: String + + def __init__(out self): + self.transport = "stdio" + + +@fieldwise_init +struct HyfExecutionRuntimeConfig(Defaultable, Copyable, Movable): + var default_execution_mode: String + var allow_assisted: Bool + + def __init__(out self): + self.default_execution_mode = "deterministic" + self.allow_assisted = False + + +@fieldwise_init +struct HyfAssistBridgeRuntimeConfig(Defaultable, Copyable, Movable): + var bridge_enabled: Bool + var transport: String + var endpoint: String + + def __init__(out self): + self.bridge_enabled = False + self.transport = "stdio" + self.endpoint = "" + + +@fieldwise_init +struct HyfRuntimeConfig(Defaultable, Copyable, Movable): + var service: HyfServiceRuntimeConfig + var runtime: HyfExecutionRuntimeConfig + var assist: HyfAssistBridgeRuntimeConfig + + def __init__(out self): + self.service = HyfServiceRuntimeConfig() + self.runtime = HyfExecutionRuntimeConfig() + self.assist = HyfAssistBridgeRuntimeConfig() + + +@fieldwise_init +struct HyfLoadedRuntimeConfig(Copyable, Movable): + var artifact_present: Bool + var loaded: Bool + var compiled_defaults_active: Bool + var load_state: String + var load_error: String + var effective: HyfRuntimeConfig + + +def default_runtime_config() -> HyfRuntimeConfig: + return HyfRuntimeConfig() + + +def default_loaded_runtime_config() -> HyfLoadedRuntimeConfig: + return HyfLoadedRuntimeConfig( + artifact_present=False, + loaded=False, + compiled_defaults_active=True, + load_state="not_found", + load_error="", + effective=default_runtime_config(), + ) + + +def assisted_execution_enabled(config: HyfLoadedRuntimeConfig) -> Bool: + return config.effective.runtime.allow_assisted + + +def assist_bridge_configured(config: HyfLoadedRuntimeConfig) -> Bool: + return ( + config.effective.assist.bridge_enabled + and not String(config.effective.assist.endpoint).strip() == "" + ) + + +def load_runtime_config(path: String) -> HyfLoadedRuntimeConfig: + var defaults = default_runtime_config() + if String(path).strip() == "" or not exists(path): + return default_loaded_runtime_config() + + try: + var config = from_toml[HyfRuntimeConfig](Path(path).read_text()) + _validate_runtime_config(config) + return HyfLoadedRuntimeConfig( + artifact_present=True, + loaded=True, + compiled_defaults_active=False, + load_state="loaded", + load_error="", + effective=config^, + ) + except e: + return HyfLoadedRuntimeConfig( + artifact_present=True, + loaded=False, + compiled_defaults_active=True, + load_state="invalid", + load_error=String(e), + effective=defaults^, + ) + + +def _validate_runtime_config(config: HyfRuntimeConfig) raises: + if config.service.transport != "stdio": + raise Error("service.transport must be 'stdio'") + + if config.runtime.default_execution_mode != "deterministic": + raise Error( + "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" + ) diff --git a/src/hyf_runtime/startup.mojo b/src/hyf_runtime/startup.mojo @@ -6,6 +6,7 @@ from hyf_runtime.env import ( configured_repo_local_root_from_env, configured_user_home_from_env, ) +from hyf_runtime.config import HyfLoadedRuntimeConfig, load_runtime_config from hyf_runtime.errors import raise_runtime_contract_error from hyf_runtime.paths import RuntimePaths, hyf_runtime_paths_for_unix_profile from hyf_runtime.profile import repo_local_profile @@ -18,6 +19,7 @@ struct RuntimeStartupContext(Copyable, Movable): var user_home: String var startup_config_path: String var startup_config_path_source: String + var config: HyfLoadedRuntimeConfig var paths: RuntimePaths @@ -138,6 +140,7 @@ def resolve_startup_context( startup_config_path_source = String("startup_flag") if profile != repo_local_profile(): repo_local_base_root = String("") + var config = load_runtime_config(startup_config_path) return RuntimeStartupContext( paths_profile=profile, @@ -145,6 +148,7 @@ def resolve_startup_context( user_home=String(input.user_home), startup_config_path=startup_config_path, startup_config_path_source=startup_config_path_source, + config=config^, paths=paths^, ) diff --git a/src/hyf_runtime/status.mojo b/src/hyf_runtime/status.mojo @@ -1,5 +1,6 @@ from mojson import Value, loads +from hyf_runtime.config import assist_bridge_configured from hyf_runtime.diagnostics import ( diagnostics_debug_override_dir_from_env, effective_diagnostics_dir_for_runtime_paths, @@ -50,8 +51,46 @@ def build_runtime_status_value(context: RuntimeStartupContext) raises -> Value: "artifact_path_source", Value(String(context.startup_config_path_source)), ) - config.set("loaded", Value(False)) - config.set("compiled_defaults_active", Value(True)) + config.set("artifact_present", Value(context.config.artifact_present)) + config.set("loaded", Value(context.config.loaded)) + config.set("load_state", Value(String(context.config.load_state))) + config.set( + "compiled_defaults_active", + Value(context.config.compiled_defaults_active), + ) + if context.config.load_error != "": + config.set("load_error", Value(String(context.config.load_error))) + + var effective = loads("{}") + effective.set( + "service_transport", + Value(String(context.config.effective.service.transport)), + ) + effective.set( + "default_execution_mode", + Value(String(context.config.effective.runtime.default_execution_mode)), + ) + effective.set( + "allow_assisted", + Value(context.config.effective.runtime.allow_assisted), + ) + effective.set( + "assist_bridge_enabled", + Value(context.config.effective.assist.bridge_enabled), + ) + effective.set( + "assist_bridge_configured", + Value(assist_bridge_configured(context.config)), + ) + effective.set( + "assist_transport", + Value(String(context.config.effective.assist.transport)), + ) + effective.set( + "assist_endpoint", + Value(String(context.config.effective.assist.endpoint)), + ) + config.set("effective", effective) status.set("config", config) status.set("diagnostics", _diagnostics_status_value(context)) diff --git a/src/hyf_stdio/control/status.mojo b/src/hyf_stdio/control/status.mojo @@ -10,6 +10,7 @@ from hyf_core.capabilities.registry import ( implemented_deterministic_capability_count, ) from hyf_core.metadata import current_build_identity +from hyf_runtime.config import assisted_execution_enabled from hyf_runtime.startup import ( RuntimeStartupContext, resolve_startup_context_from_process, @@ -62,6 +63,7 @@ def build_status_output_with_runtime_context( ) raises -> Value: var output = loads("{}") var build_identity = _build_identity_value() + var assisted_enabled = assisted_execution_enabled(runtime_context.config) output.set("build_identity", build_identity.copy()) output.set("daemon", build_identity["daemon_name"].clone()) output.set("transport", build_identity["transport"].clone()) @@ -77,13 +79,16 @@ def build_status_output_with_runtime_context( var execution_modes = loads("{}") execution_modes.set("deterministic", Value(True)) - execution_modes.set("assisted", Value(False)) + execution_modes.set("assisted", Value(assisted_enabled)) output.set("enabled_execution_modes", execution_modes) var execution_mode_request_behavior = loads("{}") execution_mode_request_behavior.set("deterministic", Value("execute")) execution_mode_request_behavior.set( - "assisted", Value("backend_unavailable") + "assisted", + Value("backend_unavailable") + if assisted_enabled + else Value("disabled_by_runtime_config"), ) output.set( "execution_mode_request_behavior", diff --git a/tests/fixtures/v1/scenarios/status_ok.json b/tests/fixtures/v1/scenarios/status_ok.json @@ -32,7 +32,7 @@ "output.enabled_execution_modes.deterministic": true, "output.enabled_execution_modes.assisted": false, "output.execution_mode_request_behavior.deterministic": "execute", - "output.execution_mode_request_behavior.assisted": "backend_unavailable", + "output.execution_mode_request_behavior.assisted": "disabled_by_runtime_config", "output.backend_reachability.deterministic_backend": "available", "output.backend_reachability.assisted_backend": "unavailable", "output.counts.canonical_business_capabilities": 8, diff --git a/tests/test_hyf.mojo b/tests/test_hyf.mojo @@ -37,8 +37,9 @@ from hyf_stdio.control.capabilities import build_capabilities_output from hyf_stdio.codec import decode_request, encode_error, encode_success from hyf_stdio.envelope import WireErrorResponse, WireSuccessResponse from hyf_stdio.errors import WireError +from hyf_runtime.startup import RuntimeStartupInput, resolve_startup_context from hyf_stdio.server import ( - handle_request_line, + handle_request_line_with_runtime_context, handle_request_line_with_control_builders, ) @@ -72,7 +73,20 @@ struct ScopedEnvVar: def _dispatch(line: String) raises -> Value: - return loads(handle_request_line(line)) + var result = Value(None) + with TemporaryDirectory() as temp_dir: + var runtime_context = resolve_startup_context( + RuntimeStartupInput( + env_paths_profile="repo_local", + env_repo_local_base_root=temp_dir, + user_home="/home/unused", + argv=List[String](), + ) + ) + result = loads( + handle_request_line_with_runtime_context(line, runtime_context) + ) + return result^ def _capability_output_entry_by_id( diff --git a/tests/test_repo_local_process_contract.mojo b/tests/test_repo_local_process_contract.mojo @@ -77,6 +77,14 @@ def test_src_main_consumes_repo_local_env_without_outer_wrapper() raises: runtime_status["config"]["artifact_path_source"].string_value(), "canonical_runtime_path", ) + assert_equal( + runtime_status["config"]["artifact_present"].bool_value(), + False, + ) + assert_equal( + runtime_status["config"]["load_state"].string_value(), + "not_found", + ) def main() raises: diff --git a/tests/test_stdio_contract.mojo b/tests/test_stdio_contract.mojo @@ -91,11 +91,35 @@ def test_status_reports_repo_local_runtime_truth() raises: ) assert_equal( response["output"]["runtime"]["config"][ + "artifact_present" + ].bool_value(), + False, + ) + assert_equal( + response["output"]["runtime"]["config"][ + "load_state" + ].string_value(), + "not_found", + ) + assert_equal( + response["output"]["runtime"]["config"][ "compiled_defaults_active" ].bool_value(), True, ) assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "default_execution_mode" + ].string_value(), + "deterministic", + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "allow_assisted" + ].bool_value(), + False, + ) + assert_equal( response["output"]["runtime"]["paths"][ "diagnostics_dir" ].string_value(), @@ -217,6 +241,170 @@ 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' + ) + 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"]["enabled_execution_modes"][ + "assisted" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["execution_mode_request_behavior"][ + "assisted" + ].string_value(), + "backend_unavailable", + ) + assert_equal( + response["output"]["runtime"]["config"][ + "artifact_present" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"][ + "loaded" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"][ + "load_state" + ].string_value(), + "loaded", + ) + assert_equal( + response["output"]["runtime"]["config"][ + "compiled_defaults_active" + ].bool_value(), + False, + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "service_transport" + ].string_value(), + "stdio", + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "default_execution_mode" + ].string_value(), + "deterministic", + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "allow_assisted" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "assist_bridge_enabled" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "assist_bridge_configured" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "assist_endpoint" + ].string_value(), + "hyf-assistd://local", + ) + assert_true( + not _has_key( + response["output"]["runtime"]["config"], + "load_error", + ) + ) + + +def test_status_reports_invalid_runtime_config_without_crashing() raises: + with TemporaryDirectory() as temp_dir: + var startup_config_path = Path(temp_dir) / "invalid-hyf-config.toml" + startup_config_path.write_text( + '[runtime]\ndefault_execution_mode = "assisted"\n' + ) + 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"]["enabled_execution_modes"][ + "assisted" + ].bool_value(), + False, + ) + assert_equal( + response["output"]["execution_mode_request_behavior"][ + "assisted" + ].string_value(), + "disabled_by_runtime_config", + ) + assert_equal( + response["output"]["runtime"]["config"][ + "artifact_present" + ].bool_value(), + True, + ) + assert_equal( + response["output"]["runtime"]["config"][ + "loaded" + ].bool_value(), + False, + ) + assert_equal( + response["output"]["runtime"]["config"][ + "load_state" + ].string_value(), + "invalid", + ) + assert_equal( + response["output"]["runtime"]["config"][ + "compiled_defaults_active" + ].bool_value(), + True, + ) + assert_true( + response["output"]["runtime"]["config"]["load_error"] + .string_value() + .find("default_execution_mode") + >= 0 + ) + assert_equal( + response["output"]["runtime"]["config"]["effective"][ + "allow_assisted" + ].bool_value(), + False, + ) + + def test_status_reports_configured_but_deferred_custody_truthfully() raises: with TemporaryDirectory() as temp_dir: var identity_dir = Path(temp_dir) / "secrets" / "services" / "hyf"