Skip to content

Commit a9fdf78

Browse files
authored
Report invalid DSH native module options before dispatch (#9966)
* fix(turn): expose DSH native module option conflicts in planning Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> * fix(turn): honor the final DSH option after an empty value Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> * Keep empty host selections invalid across repeated arguments Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --------- Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 510b775 commit a9fdf78

5 files changed

Lines changed: 110 additions & 20 deletions

File tree

‎loopx/cli_commands/turn_selection.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ def managed_executor_cli_binding(
126126
else None
127127
),
128128
codex_operation_tools=bool(getattr(args, "codex_operation_tools", False)),
129-
dsh_operation_module_configured=bool(getattr(args, "dsh_operation_module", None)),
129+
dsh_operation_module_path=getattr(args, "dsh_operation_module", None),
130130
codex_sandbox=getattr(args, "codex_sandbox", "read-only"),
131131
)

‎loopx/control_plane/collaboration/operation_wake.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def dispatch_confirmed_operation_wake(
208208
proposal, action="wake",
209209
binding_current=managed_operation_binding_current(runtime_root, parameters),
210210
launch_context={"host": host,
211-
"operation_tools": bool(turn_host_arg_option(argv, "--dsh-operation-module")) if dsh else "--codex-operation-tools" in argv,
211+
"operation_tools": bool(turn_host_arg_option(argv, "--dsh-operation-module", strip=False)) if dsh else "--codex-operation-tools" in argv,
212212
"iteration_context": turn_host_arg_option(argv, "--iteration-context")},
213213
executor_route={"goal_id": service.goal_id, "agent_id": binding["agent_id"],
214214
"todo_id": binding["todo_id"], "host_surface": "loopx-managed-dsh" if dsh else "loopx-managed-codex",

‎loopx/control_plane/turn_driver/host_binding.py‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import importlib.util
3434
from collections.abc import Mapping, Sequence
35+
from pathlib import Path
3536
from typing import Any, Callable
3637

3738
from ..operator_credential import (
@@ -185,16 +186,27 @@ def _with_operation_transport(
185186
sandbox: str,
186187
model: str | None,
187188
reasoning_effort: str | None,
188-
dsh_operation_module_configured: bool = False,
189+
dsh_operation_module_configured: bool,
190+
dsh_operation_module_path: str | None,
191+
dsh_runner_configured: bool,
189192
) -> dict[str, Any]:
190-
if codex_operation_tools or dsh_operation_module_configured:
193+
if codex_operation_tools or dsh_operation_module_configured or dsh_operation_module_path:
191194
from ..effect_runtime import effect_runtime_result
192195

193196
observed = effect_runtime_result(
194197
"operation.managed_transport.project",
195-
{"host": host, "sandbox": sandbox, "codex_operation_tools": codex_operation_tools,
196-
"dsh_operation_module_configured": dsh_operation_module_configured,
197-
"model": model, "reasoning_effort": reasoning_effort},
198+
{
199+
"host": host,
200+
"sandbox": sandbox,
201+
"codex_operation_tools": codex_operation_tools,
202+
"dsh_operation_module_configured": dsh_operation_module_configured or bool(dsh_operation_module_path),
203+
"dsh_operation_module_absolute": (
204+
Path(dsh_operation_module_path).is_absolute() if dsh_operation_module_path else None
205+
),
206+
"dsh_runner_configured": dsh_runner_configured,
207+
"model": model,
208+
"reasoning_effort": reasoning_effort,
209+
},
198210
)
199211
binding["operation_transport"] = observed["transport"]
200212
if observed["reason"]:
@@ -216,6 +228,7 @@ def managed_executor_binding(
216228
max_tokens: int | None = None,
217229
codex_operation_tools: bool = False,
218230
dsh_operation_module_configured: bool = False,
231+
dsh_operation_module_path: str | None = None,
219232
codex_sandbox: str = "read-only",
220233
) -> dict[str, Any]:
221234
"""Project the executor one planned Turn would run on.
@@ -286,6 +299,7 @@ def managed_executor_binding(
286299
binding, codex_operation_tools=codex_operation_tools, host=host,
287300
sandbox=codex_sandbox, model=profile["model"], reasoning_effort=profile["reasoning_effort"],
288301
dsh_operation_module_configured=dsh_operation_module_configured,
302+
dsh_operation_module_path=dsh_operation_module_path, dsh_runner_configured=dsh_runner_configured,
289303
)
290304
individual_profile: str | None = None
291305
if host == INDIVIDUAL_TURN_HOST and (model or reasoning_effort):
@@ -315,28 +329,27 @@ def managed_executor_binding(
315329
binding, codex_operation_tools=codex_operation_tools, host=host,
316330
sandbox=codex_sandbox, model=model, reasoning_effort=reasoning_effort,
317331
dsh_operation_module_configured=dsh_operation_module_configured,
332+
dsh_operation_module_path=dsh_operation_module_path, dsh_runner_configured=dsh_runner_configured,
318333
)
319334

320335

321-
def turn_host_arg_option(host_args: Sequence[str], name: str) -> str | None:
336+
def turn_host_arg_option(host_args: Sequence[str], name: str, *, strip: bool = True) -> str | None:
322337
"""Return the value the Turn CLI will use for one repeatable argv option."""
323338
args = [str(value) for value in host_args]
324339
selected: str | None = None
325340
for index, value in enumerate(args):
326-
if value.startswith(f"{name}="):
327-
candidate = value.partition("=")[2].strip()
328-
if not candidate:
329-
return None
330-
selected = candidate
331341
if value == name:
332342
if index + 1 >= len(args):
333343
return None
334-
candidate = args[index + 1].strip()
335-
# argparse treats another option token as a missing value for this
336-
# option. Keep the read model fail-closed in the same case.
337-
if not candidate or candidate.startswith("--"):
338-
return None
339-
selected = candidate
344+
raw = args[index + 1]
345+
elif value.startswith(f"{name}="):
346+
raw = value.partition("=")[2]
347+
else:
348+
continue
349+
candidate = raw.strip() if strip else raw
350+
if (strip and not candidate) or (value == name and candidate.startswith("--")):
351+
return None
352+
selected = candidate or None
340353
return selected
341354

342355

@@ -355,6 +368,7 @@ def managed_executor_binding_from_host_args(
355368
"""
356369

357370
host = turn_host_arg_option(host_args, "--host") or "unknown"
371+
module_path = turn_host_arg_option(host_args, "--dsh-operation-module", strip=False)
358372
return managed_executor_binding(
359373
host,
360374
environ=environ,
@@ -379,7 +393,10 @@ def managed_executor_binding_from_host_args(
379393
else None
380394
),
381395
codex_operation_tools="--codex-operation-tools" in host_args,
382-
dsh_operation_module_configured=bool(turn_host_arg_option(host_args, "--dsh-operation-module")),
396+
dsh_operation_module_path=module_path,
397+
# A custom runner conflicts with the native module. Leave ordinary
398+
# delegation readiness on its existing probe and credential checks.
399+
dsh_runner_configured=bool(module_path and turn_host_arg_option(host_args, "--dsh-runner", strip=False)),
383400
codex_sandbox=turn_host_arg_option(host_args, "--codex-sandbox") or "read-only",
384401
)
385402

‎loopx/control_plane/work_items/operation_agent_handoff.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,16 @@ export function projectManagedOperationTransport(input: JsonObject): JsonObject
7272
const supportedHosts = conflictingFlags ? [] : [dshTransport ? "dsh" : "codex-cli"];
7373
const supportedSandboxes = dshTransport ? [] : ["read-only", "workspace-write"];
7474
const reason = typeof input.host !== "string" || !supportedHosts.includes(input.host) ? "operation_transport_host_unsupported"
75+
: dshTransport && input.dsh_runner_configured === true ? "operation_transport_runner_conflict"
76+
: dshTransport && input.dsh_operation_module_absolute === false ? "operation_transport_module_path_relative"
7577
: !dshTransport && (typeof input.sandbox !== "string" || !supportedSandboxes.includes(input.sandbox)) ? "operation_transport_sandbox_unsupported"
7678
: typeof input.model !== "string" || !ID.test(input.model)
7779
|| typeof input.reasoning_effort !== "string"
7880
|| !["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"].includes(input.reasoning_effort)
7981
? "operation_transport_profile_required" : null;
8082
const remediation = conflictingFlags ? ["correct_execution_profile"]
83+
: reason === "operation_transport_runner_conflict" ? ["remove_dsh_runner"]
84+
: reason === "operation_transport_module_path_relative" ? ["use_absolute_dsh_operation_module"]
8185
: reason === "operation_transport_host_unsupported" ? ["select_supported_operation_host"]
8286
: reason === "operation_transport_sandbox_unsupported" ? ["select_supported_operation_sandbox"]
8387
: reason === "operation_transport_profile_required" ? ["correct_execution_profile"] : [];

‎tests/control_plane/test_operation_transport_readback.py‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,72 @@ def test_planning_and_cli_inspection_agree_on_operation_host_flags(
151151
assert projected["configuration_valid"] is supported
152152
assert projected["runtime_qualified"] is False
153153
assert not (root / "host-started").exists()
154+
155+
156+
@pytest.mark.parametrize(("options", "remedy", "cli_error"), [
157+
(["--dsh-operation-module", "relative.js"], "use_absolute_dsh_operation_module", "absolute"),
158+
(["--dsh-runner=", "--dsh-operation-module", "{module}", "--dsh-runner=custom"],
159+
"remove_dsh_runner", "without --dsh-runner"),
160+
(["--dsh-operation-module= {module}"], "use_absolute_dsh_operation_module", "absolute"),
161+
(["--dsh-operation-module", "{module}", "--dsh-runner=custom"],
162+
"remove_dsh_runner", "without --dsh-runner"),
163+
])
164+
def test_planning_rejects_dsh_module_options_refused_by_cli(service, options, remedy, cli_error):
165+
from loopx.control_plane.turn_driver.host_binding import managed_executor_binding_from_host_args
166+
167+
root, runner = service
168+
options = [option.format(module=root / "module.js") for option in options]
169+
argv = ["--host", "dsh", "--dsh-model", "test-model", "--dsh-reasoning-effort", "high", *options]
170+
config = json.loads(runner.config.read_text())
171+
config["bindings"][0]["host_args"] = argv
172+
runner.config.write_text(json.dumps(config))
173+
before = runner.config.read_bytes(), runner.registry.read_bytes()
174+
175+
status, inspected = cli(runner, "inspect", "--binding-id", "analysis")
176+
assert status == 1 and cli_error in inspected["error"]
177+
binding = managed_executor_binding_from_host_args(argv, environ={})
178+
assert binding["operation_transport"]["configuration_valid"] is False
179+
assert binding["operation_transport"]["runtime_qualified"] is False
180+
assert binding["available"] is False
181+
assert binding["unavailable_remediation"] == [remedy]
182+
assert (runner.config.read_bytes(), runner.registry.read_bytes()) == before
183+
assert not (root / "host-started").exists()
184+
185+
186+
@pytest.mark.parametrize("options", [
187+
["--dsh-operation-module=", "--dsh-operation-module", "{module}"],
188+
["--dsh-runner=custom", "--dsh-runner=", "--dsh-operation-module={module}"],
189+
["--dsh-operation-module={module}", "--dsh-operation-module="],
190+
])
191+
def test_repeated_dsh_options_use_the_final_cli_value(service, options):
192+
from loopx.control_plane.turn_driver.host_binding import managed_executor_binding_from_host_args
193+
194+
root, runner = service
195+
argv = ["--host", "dsh", "--dsh-model", "test-model", "--dsh-reasoning-effort", "high",
196+
*(option.format(module=root / "module.js") for option in options)]
197+
config = json.loads(runner.config.read_text())
198+
config["bindings"][0]["host_args"] = argv
199+
runner.config.write_text(json.dumps(config))
200+
201+
status, inspected = cli(runner, "inspect", "--binding-id", "analysis")
202+
assert status == 0, inspected
203+
projected = managed_executor_binding_from_host_args(argv, environ={})
204+
assert projected.get("operation_transport") == inspected["executor"].get("operation_transport")
205+
assert not (root / "host-started").exists()
206+
207+
208+
def test_empty_host_before_valid_host_cannot_select_operation_transport(service):
209+
from loopx.control_plane.turn_driver.host_binding import managed_executor_binding_from_host_args
210+
211+
root, runner = service
212+
argv = ["--host=", "--host=dsh", "--dsh-operation-module", str(root / "module.js")]
213+
config = json.loads(runner.config.read_text())
214+
config["bindings"][0]["host_args"] = argv
215+
runner.config.write_text(json.dumps(config))
216+
217+
status, inspected = cli(runner, "inspect", "--binding-id", "analysis")
218+
assert status == 1 and inspected["error"] == "invalid delegation Turn arguments"
219+
projected = managed_executor_binding_from_host_args(argv, environ={})
220+
assert projected["executor"] == "unknown"
221+
assert projected["available"] is False
222+
assert projected["operation_transport"]["configuration_valid"] is False

0 commit comments

Comments
 (0)