From 801e28d6bf3d7c85a8097c91bd65f01c3490d73c Mon Sep 17 00:00:00 2001 From: lishuoshuo-amd Date: Wed, 23 Sep 2026 15:00:19 +0800 Subject: [PATCH 1/2] test: keep the both-arms-dry walkthrough off real kernel subprocesses on either route KERNEL entry runs out of band and holds the phase until the hook returns. The previous fix only covered the GEAK route, but the route is read from KERNEL_OPT_BACKEND_ORDER, and an earlier test on the same xdist worker leaves it at "forge" (test_atom_kernel_backend_default deletes an unset key, which monkeypatch does not record, and the code under test then writes it). On the forge route the hook launched `kernelforge.cli kernel-rewrite-controller`, so reaching CLOSE within eleven ticks again depended on how fast a subprocess exited on the CI host. The test now sets the backend order itself and runs once per route, with both process boundaries replaced: the GEAK runner path is unresolvable and the Controller run returns no_opportunity. Each route pins the terminal result it reached, so a new subprocess step on either route fails the test instead of racing it. Co-authored-by: Cursor --- .../tests/test_optimize_loop_walkthrough.py | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py b/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py index 883bb6d861..0b3c383631 100644 --- a/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py +++ b/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py @@ -77,16 +77,36 @@ async def test_a_baseline_carries_the_run_into_the_optimisation_phase_with_work( @pytest.mark.asyncio -async def test_both_arms_dry_walks_the_rest_of_the_chain(session_dir: Path, monkeypatch: pytest.MonkeyPatch): - """With nothing left to try, the run reaches CLOSE through every phase.""" - from hyperloom.orchestrator.kernel import request_handlers +@pytest.mark.parametrize( + ("backend_order", "result_field", "result_key", "expected"), + [ + ("", "geak_result", "error_class", "runner_not_found"), + ("forge", "kernel_rewrite_controller_result", "status", "no_opportunity"), + ], + ids=["geak", "forge"], +) +async def test_both_arms_dry_walks_the_rest_of_the_chain( + session_dir: Path, + monkeypatch: pytest.MonkeyPatch, + backend_order: str, + result_field: str, + result_key: str, + expected: str, +): + """With nothing left to try, the run reaches CLOSE through every phase, on either kernel route.""" + from hyperloom.orchestrator.kernel import controller_submit, request_handlers from hyperloom.orchestrator.state.attempt_ledger import record_config_attempt def _no_geak_runner(tool_name: str) -> Path: raise FileNotFoundError(tool_name) - # KERNEL entry runs out of band; a real GEAK subprocess would decide how long the phase is held. + def _no_controller_run(**kwargs: Any) -> dict[str, Any]: + return {"status": "no_opportunity", "patch_count": 0, "task_count": 0, "output_dir": str(kwargs["output_dir"])} + + # KERNEL entry runs out of band and holds the phase; a real GEAK or Controller subprocess would set how long. + monkeypatch.setenv("KERNEL_OPT_BACKEND_ORDER", backend_order) monkeypatch.setattr(request_handlers, "_kernel_agent_tool_path", _no_geak_runner) + monkeypatch.setattr(controller_submit, "run_controller_subprocess", _no_controller_run) coord = _coordinator(session_dir) try: @@ -117,7 +137,7 @@ def _no_geak_runner(tool_name: str) -> Path: await coord.tick(tick) assert state.phase == ps.PHASE_CLOSE - assert state.geak_result["error_class"] == "runner_not_found" + assert getattr(state, result_field)[result_key] == expected visited = [to_phase for _, to_phase, _ in _chain(state)] assert visited[:2] == [ps.PHASE_PRELUDE, ps.PHASE_FRAMEWORK_AGENT] assert visited[-3:] == [ps.PHASE_KERNEL_AGENT, ps.PHASE_SWEEP, ps.PHASE_CLOSE] From 82e75a321ac85fa87ccc88eb9e437c03f37bf971 Mon Sep 17 00:00:00 2001 From: lishuoshuo-amd Date: Wed, 23 Sep 2026 15:13:33 +0800 Subject: [PATCH 2/2] test: stub both kernel subprocess boundaries in the fixture and wait on KERNEL entry Both process boundaries now live in the session_dir fixture, as #1623 does for the Controller, so no test in the file can reach a real GEAK runner or Controller process. Only geak_runner.py is refused; every other kernel-agent tool path still resolves. The walkthrough also waits on the out-of-band KERNEL entry hook after each tick. With the subprocesses stubbed the hook returns within a tick, so the wait is immediate; it removes the remaining dependency on the hook finishing inside the fixed tick count. Co-authored-by: Cursor --- .../tests/test_optimize_loop_walkthrough.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py b/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py index 0b3c383631..2202cbe66b 100644 --- a/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py +++ b/src/hyperloom/inference_optimizer/tests/test_optimize_loop_walkthrough.py @@ -40,9 +40,25 @@ def _coordinator(session_dir: Path): ) +def _no_controller_run(**kwargs: Any) -> dict[str, Any]: + return {"status": "no_opportunity", "patch_count": 0, "task_count": 0, "output_dir": str(kwargs["output_dir"])} + + @pytest.fixture def session_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: + from hyperloom.orchestrator.kernel import controller_submit, request_handlers + + real_tool_path = request_handlers._kernel_agent_tool_path + + def _tool_path_without_geak_runner(tool_name: str) -> Path: + if tool_name == "backends/geak_runner.py": + raise FileNotFoundError(tool_name) + return real_tool_path(tool_name) + monkeypatch.setenv("USER_DATA_PATH", str(tmp_path)) + # KERNEL entry would otherwise launch a real GEAK runner or Controller process on its route. + monkeypatch.setattr(request_handlers, "_kernel_agent_tool_path", _tool_path_without_geak_runner) + monkeypatch.setattr(controller_submit, "run_controller_subprocess", _no_controller_run) return make_session_dir() @@ -94,19 +110,9 @@ async def test_both_arms_dry_walks_the_rest_of_the_chain( expected: str, ): """With nothing left to try, the run reaches CLOSE through every phase, on either kernel route.""" - from hyperloom.orchestrator.kernel import controller_submit, request_handlers from hyperloom.orchestrator.state.attempt_ledger import record_config_attempt - def _no_geak_runner(tool_name: str) -> Path: - raise FileNotFoundError(tool_name) - - def _no_controller_run(**kwargs: Any) -> dict[str, Any]: - return {"status": "no_opportunity", "patch_count": 0, "task_count": 0, "output_dir": str(kwargs["output_dir"])} - - # KERNEL entry runs out of band and holds the phase; a real GEAK or Controller subprocess would set how long. monkeypatch.setenv("KERNEL_OPT_BACKEND_ORDER", backend_order) - monkeypatch.setattr(request_handlers, "_kernel_agent_tool_path", _no_geak_runner) - monkeypatch.setattr(controller_submit, "run_controller_subprocess", _no_controller_run) coord = _coordinator(session_dir) try: @@ -135,6 +141,8 @@ def _no_controller_run(**kwargs: Any) -> dict[str, Any]: for tick in range(1, 12): await coord.tick(tick) + # KERNEL entry runs out of band and holds the phase until it returns. + await coord._await_kernel_entry_task() assert state.phase == ps.PHASE_CLOSE assert getattr(state, result_field)[result_key] == expected