Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions loopx/cli_commands/turn_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ..control_plane.effect_runtime import EffectRuntimeRemoteError
from ..control_plane.quota.effective_action import EffectiveAction
from ..control_plane.runtime.effect_client_errors import node_probe_diagnostic_fields
from ..control_plane.turn_driver import (
LOOPX_TURN_EXECUTION_SCHEMA_VERSION,
TurnRecoveryBlockedError,
Expand Down Expand Up @@ -122,6 +123,7 @@ def build_turn_error_payload(
return {
**({"error_code": error_code, **(error_payload if isinstance(error_payload, Mapping) else {})}
if isinstance(error_code, str) else {}),
**node_probe_diagnostic_fields(exc),
"ok": False,
"schema_version": (
LOOPX_TURN_EXECUTION_SCHEMA_VERSION if run_once else "loopx_turn_plan_v0"
Expand Down
17 changes: 17 additions & 0 deletions tests/test_loopx_turn_error_readback.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ def test_runtime_conflict_preserves_machine_diagnostic_without_parsing_message(c
assert result["resume_turn_key"] == "sha256:" + "b" * 64


@pytest.mark.parametrize("command", ["plan", "run-once"])
def test_missing_node_preserves_probe_diagnostic_before_execution(command):
from loopx.control_plane.runtime.effect_client_errors import EffectRuntimeNodeProbeError

refusal = EffectRuntimeNodeProbeError("Runtime prerequisite unavailable", diagnostic_code="node_unavailable")
result = build_turn_error_payload({}, refusal, turn_command=command)

assert result["ok"] is False
assert result["error"] == "Runtime prerequisite unavailable"
assert result["diagnostic_code"] == "node_unavailable"
assert "loopx doctor --deep" in result["recommended_action"]
assert result["effects"] == {
"host_invoked": False, "state_written": False,
"scheduler_acknowledged": False, "quota_spent": False,
}


def test_generic_error_does_not_invent_a_machine_diagnostic():
result = build_turn_error_payload({}, ValueError("goal_stopped"), turn_command="run-once")
assert "error_code" not in result
Expand Down