Skip to content

Commit ad3ca3c

Browse files
committed
fix: name the error code when the runtime server's start fails
A failed start, invoke or stop returned only a fixed message, such as "Fabric could not establish an active runtime", and the server didn't log the cause, so a consumer like NemoClaw couldn't tell a slow OpenClaw Gateway from any other failure. The message now ends with the SDK or adapter error code, for example "Cause: openclaw_gateway_start_timeout.". Only a lowercase identifier of at most 64 characters is included; the error's message and any values stay out of the response. Signed-off-by: Carlos Villela <[email protected]>
1 parent 624e687 commit ad3ca3c

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎sdk/python/nemo-fabric-runtime/src/nemo_fabric/runtime_server/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Ordinary SDK stop does not establish that all harness descendants exited. A succ
7070

7171
Completed commands except serve write exactly one newline-terminated JSON response to stdout. Logs use stderr. A completed SDK call exits 0; command or transport failure or unsupported behavior exits 1. A completed invoke can return a failed `RunResult` with partial or null output and artifacts, just as the SDK does. Inspect `result.status` and `result.error` for the invocation outcome; command diagnostics remain in the envelope's separate `error` field. Requests are bounded to 512 KiB and responses to 4 MiB, including framing. Lifecycle and invocation calls have a 320-second transport deadline; checks default to three seconds, and incomplete input has a ten-second deadline. The caller also bounds OpenShell execution and startup polling.
7272

73-
A timeout or missing, malformed, truncated, or oversized response leaves dispatched effects unknown. Errors use fixed diagnostics with `effects: none`, `applied`, or `unknown`. Routine errors exclude prompts, configuration values, and raw exceptions. Invocation results preserve normalized SDK results, including failed results with null output, and may contain user data. Calls are never replayed after an uncertain outcome.
73+
A timeout or missing, malformed, truncated, or oversized response leaves dispatched effects unknown. Errors use fixed diagnostics with `effects: none`, `applied`, or `unknown`. Routine errors exclude prompts, configuration values, and raw exceptions. When a start, invoke, or stop fails with an SDK or adapter error code, such as `openclaw_gateway_start_timeout`, the message ends with `Cause: <code>.`; only a lowercase identifier of at most 64 characters is included, never the error's message. Invocation results preserve normalized SDK results, including failed results with null output, and may contain user data. Calls are never replayed after an uncertain outcome.
7474

7575
`--config -`, `--request -`, and `--input -` explicitly select stdin. Otherwise commands read staged regular files containing exactly one bounded UTF-8 JSON value. Configuration and complete requests must be objects matching `FabricConfig` and `RunRequest`; convenience input follows the SDK's JSON input semantics. Unknown or duplicate flags, duplicate JSON keys, and oversized input are rejected.
7676

‎sdk/python/nemo-fabric-runtime/src/nemo_fabric/runtime_server/protocol.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Versioned local requests and safe command responses."""
55

66
import json
7+
import re
78
import sys
89
from typing import Any
910

@@ -18,6 +19,8 @@
1819
SHUTDOWN_SECONDS = 4.0
1920
SOCKET_PATH = "/sandbox/fabric.sock"
2021
OPERATIONS = ("start", "invoke", "stop", "serve", "check")
22+
# A cause is an SDK or adapter error code, never its message or other values.
23+
CAUSE = re.compile(r"[a-z][a-z0-9_]{0,63}")
2124
CONFIG_OPERATIONS = ("start",)
2225
LIFECYCLE_OPERATIONS = ("start", "stop")
2326

@@ -70,11 +73,15 @@ def __init__(
7073
stage: str = "request",
7174
*,
7275
unsupported: bool = False,
76+
cause: str | None = None,
7377
):
7478
self.code = code
7579
self.stage = stage
7680
self.unsupported = unsupported
77-
super().__init__(MESSAGES[code])
81+
message = MESSAGES[code]
82+
if isinstance(cause, str) and CAUSE.fullmatch(cause):
83+
message = f"{message} Cause: {cause}."
84+
super().__init__(message)
7885

7986

8087
def envelope(

‎sdk/python/nemo-fabric-runtime/src/nemo_fabric/runtime_server/state.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ async def handle(self, request: Any) -> dict[str, Any]:
210210
)
211211
error = ProtocolError(code, "validation")
212212
else:
213-
error = ProtocolError(f"{stage}_failed", stage)
213+
error = ProtocolError(
214+
f"{stage}_failed", stage, cause=getattr(error, "code", None)
215+
)
214216
return envelope(
215217
operation, result, changed=changed, error=error, effects=effects
216218
)

‎tests/python/runtime_server/test_state.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
from nemo_fabric import FabricConfigError, RunRequest, RuntimeStatus
10+
from nemo_fabric.errors import FabricRuntimeError
1011
from nemo_fabric.runtime_server.protocol import ProtocolError
1112

1213

@@ -175,6 +176,36 @@ async def test_sdk_preflight_rejection_does_not_consume_lifecycle(
175176
assert "PRIVATE" not in str(response)
176177

177178

179+
async def test_failed_start_names_the_runtime_error_code_without_its_message(
180+
host, host_request, mock_fabric
181+
):
182+
mock_fabric.start_runtime.side_effect = FabricRuntimeError(
183+
"adapter lifecycle start failed: PRIVATE",
184+
stage="start",
185+
code="openclaw_gateway_start_timeout",
186+
)
187+
response = await host.handle(host_request("start"))
188+
assert response["error"]["code"] == "start_failed"
189+
assert response["error"]["message"] == (
190+
"Fabric could not establish an active runtime. "
191+
"Cause: openclaw_gateway_start_timeout."
192+
)
193+
assert "PRIVATE" not in str(response)
194+
195+
196+
@pytest.mark.parametrize("code", ["PRIVATE value", "private/value", "x" * 65])
197+
async def test_failed_start_omits_a_cause_that_is_not_an_identifier(
198+
host, host_request, mock_fabric, code
199+
):
200+
mock_fabric.start_runtime.side_effect = FabricRuntimeError(
201+
"failed", stage="start", code=code
202+
)
203+
response = await host.handle(host_request("start"))
204+
assert response["error"]["message"] == (
205+
"Fabric could not establish an active runtime."
206+
)
207+
208+
178209
async def test_uncertain_start_consumes_lifecycle_without_replay(
179210
host, host_request, mock_fabric
180211
):

0 commit comments

Comments
 (0)