{"record":{"id":"a9b6f457a8d2172e","repo":"sgl-project/sglang","slug":"action-output-dimensions-must-be-non-zero-got-tu","errorCode":null,"errorMessage":"action output dimensions must be non-zero, got {tuple(action_array.shape)}","messagePattern":"action output dimensions must be non-zero, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":500,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py","lineNumber":437,"sourceCode":"    req = prepare_request(server_args, sp)\n    response = await async_scheduler_client.forward(req)\n    if getattr(response, \"error\", None):\n        raise RuntimeError(response.error)\n    if response.output is None:\n        raise RuntimeError(\"action policy returned no output\")\n    return response.output[0]\n\n\ndef action_generation_response(\n    output: dict[str, Any],\n    server_args: ServerArgs,\n    *,\n    preserve_numpy: bool = False,\n) -> dict[str, Any]:\n    actions = output[\"actions\"]\n    action_array = np.asarray(actions)\n    if any(size == 0 for size in action_array.shape):\n        raise ValueError(\n            \"action output dimensions must be non-zero, got \"\n            f\"{tuple(action_array.shape)}\"\n        )\n    if action_array.ndim == 2:\n        action_array = action_array[None]\n    elif action_array.ndim != 3:\n        raise ValueError(\n            \"action output must have shape [H, D] or [B, H, D], got \"\n            f\"{tuple(action_array.shape)}\"\n        )\n\n    data = []\n    for input_index, action_values in enumerate(action_array):\n        action_shape = list(action_values.shape)\n        if not preserve_numpy:\n            action_values = action_values.tolist()\n        action = {\n            \"type\": \"continuous\",","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py#L419-L455","documentation":"Raised by action_generation_response while validating the `actions` field of the model output: after np.asarray(actions), any dimension of the array is zero (e.g. shape (0,), (H, 0), (0, H, D)). The response builder refuses to serialize an empty action tensor because it would emit zero data items.","triggerScenarios":"Calling create_action_generation, action_realtime_ws, or action_generation_response directly with output['actions'] containing an empty list or an array with a zero dimension — e.g. the policy returned [] or an array of shape (0, D).","commonSituations":"Policy model returns an empty action list for degenerate input, horizon dimension collapses to 0 due to misconfigured sampling params, mocking/stubbing outputs in tests with empty arrays.","solutions":["Ensure the action policy actually produces non-empty output (check input observations and horizon settings)","Fix sampling params so the generated horizon/action dimensions are > 0","If writing tests, use realistic non-empty action arrays when mocking output"],"exampleFix":"# before\noutput = {\"actions\": np.zeros((0, 8))}\naction_generation_response(output, server_args)  # ValueError\n\n# after\noutput = {\"actions\": np.zeros((1, 8))}\naction_generation_response(output, server_args)  # OK","handlingStrategy":"validation","validationCode":"import numpy as np\narr = np.asarray(output[\"actions\"])\nif arr.size == 0 or any(s == 0 for s in arr.shape):\n    raise ValueError(\"rejecting empty actions before response build\")","typeGuard":"def has_nonzero_shape(actions) -> bool:\n    a = np.asarray(actions)\n    return a.ndim >= 1 and all(s > 0 for s in a.shape)","tryCatchPattern":null,"preventionTips":["Validate the actions array shape before calling action_generation_response","Sanity-check policy horizon/action-dim config is > 0","In tests, mock with realistic non-empty arrays"],"tags":["action-inference","shape-validation","numpy"],"backgroundTag":"tensor-shape-validation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}