Skip to content

Commit 9f652a5

Browse files
authored
fix(turn): retain the selected Codex operation transport (#9965)
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 649a5e8 commit 9f652a5

2 files changed

Lines changed: 28 additions & 34 deletions

File tree

‎loopx/control_plane/turn_driver/codex_operation_host.py‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
FirstPartyHostGoalAdmission,
2626
FirstPartyHostRuntimeRejected,
2727
)
28-
from ...hosts.oar_client import oar_execution_engine_selected
2928
from . import managed_operation_host as operations
3029
from .codex_cli import (
3130
_checked_prompt_context,
32-
_codex_binary_supports_oar,
3331
collaboration_mcp_turn_environment,
3432
normalize_codex_stdio_mcp_server,
3533
prepare_codex_cli_input,
@@ -88,33 +86,8 @@ def run_codex_operation_host(
8886
resolved_bin = shutil.which(codex_bin)
8987
if not resolved_bin:
9088
raise ValueError("Codex executable is unavailable")
91-
if (
92-
worker is None
93-
and mcp_server is None
94-
and oar_execution_engine_selected()
95-
and _codex_binary_supports_oar(str(resolved_bin))
96-
):
97-
from .oar_operation_host import run_oar_operation_host
98-
99-
return run_oar_operation_host(
100-
request,
101-
host="codex-cli",
102-
runtime_id="codex",
103-
runtime_root=runtime_root,
104-
registry_path=registry_path,
105-
project=project,
106-
provider="openai",
107-
model=model,
108-
reasoning_effort=reasoning_effort,
109-
sandbox=sandbox,
110-
timeout_seconds=120.0 if timeout_seconds is None else timeout_seconds,
111-
runtime_bin=Path(resolved_bin),
112-
source_route=source_route,
113-
goal_admission=goal_admission,
114-
confirmed_operation_id=confirmed_operation_id,
115-
operation_request_file=operation_request_file,
116-
operation_request_sha256=operation_request_sha256,
117-
)
89+
# --codex-operation-tools selects the app-server transport. Its session
90+
# and approved operations retain that identity across ordinary engine changes.
11891
with Path(resolved_bin).open("rb") as stream:
11992
binary_digest = hashlib.file_digest(stream, "sha256").hexdigest()
12093
profile = {

‎tests/test_codex_operation_host.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,14 @@ def check_at_writeback(admission, *, operation):
284284
def _claimed_native_fixture(tmp_path: Path):
285285
from examples import operation_action_fixtures as fixtures
286286
from loopx.control_plane.turn_driver.managed_operation_host import operation_tool_handler
287+
from test_dsh_goal_mode import _signed_request
287288

288289
service, store = fixtures.service(tmp_path, goal_id="fixture-goal")
289290
executable = tmp_path / "fake-codex-operation"
290291
executable.write_text(FAKE_SERVER)
291292
executable.chmod(0o700)
292-
request = _request()
293-
request["turn_envelope"]["agent_id"] = "finance-fixture-agent"
294-
request["turn_envelope"]["action"]["selected_todo"]["todo_id"] = "todo-managed"
293+
request = _signed_request(goal_id="fixture-goal", agent_id="finance-fixture-agent", todo_id="todo-managed")
294+
request["session"]["action"] = "start_new"
295295
options = dict(runtime_root=store.root.parent.parent, registry_path=service.registry_path,
296296
project=service.registry_path.parent.parent, codex_bin=str(executable),
297297
model="test-model", reasoning_effort="xhigh", timeout_seconds=5)
@@ -319,10 +319,26 @@ def _claimed_native_fixture(tmp_path: Path):
319319
return store, claimed, request, options
320320

321321

322+
def _enable_default_oar_for_codex(monkeypatch, executable: Path) -> None:
323+
from loopx.control_plane.turn_driver import codex_cli
324+
325+
monkeypatch.delenv("LOOPX_EXECUTION_ENGINE", raising=False)
326+
# The fixture implements app-server locally. Represent an already
327+
# successful OAR binary probe without running a second model provider.
328+
executable = executable.resolve()
329+
monkeypatch.setitem(
330+
codex_cli._OAR_CODEX_BINARY_CACHE,
331+
(str(executable), executable.stat().st_mtime_ns),
332+
True,
333+
)
334+
335+
322336
def test_confirmed_operation_is_automatically_carried_into_accepted_native_turn(
323337
tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
324338
) -> None:
339+
monkeypatch.setenv("LOOPX_EXECUTION_ENGINE", "legacy")
325340
store, claimed, request, options = _claimed_native_fixture(tmp_path)
341+
_enable_default_oar_for_codex(monkeypatch, Path(options["codex_bin"]))
326342
prompt = tmp_path / "native-prompt.txt"
327343
monkeypatch.setenv("FAKE_OPERATION_PROMPT_FILE", str(prompt))
328344
result = run_codex_operation_host(request, **options)
@@ -787,15 +803,20 @@ def test_owned_app_server_process_authenticates_native_metadata_and_resumes_same
787803
)
788804

789805

806+
@pytest.mark.parametrize("provider", ["file", "sqlite"])
790807
def test_admitted_turn_cli_launches_owned_transport_without_plain_cli_fallback(
791-
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
808+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, provider: str,
792809
) -> None:
793810
from loopx.cli import main as cli_main
811+
from tests.control_plane.canonical_authority_fixture import isolate_sqlite_runtime
794812

795-
project, runtime, registry = _write_live_fixture(tmp_path)
813+
if provider == "sqlite":
814+
isolate_sqlite_runtime(tmp_path, monkeypatch)
815+
project, runtime, registry = _write_live_fixture(tmp_path, provider=provider)
796816
executable = tmp_path / "fake-codex-operation"
797817
executable.write_text(FAKE_SERVER)
798818
executable.chmod(0o700)
819+
_enable_default_oar_for_codex(monkeypatch, executable)
799820

800821
def forbidden_plain_cli(*args, **kwargs):
801822
pytest.fail("Operation opt-in must not downgrade to plain Codex exec")

0 commit comments

Comments
 (0)