odysseus-dev/odysseus · error · HTTPException

Invalid cmd — could not parse

Error message

Invalid cmd — could not parse

What it means

HTTP 400 from _check_serve_binary() in routes/cookbook_helpers.py when shlex.split() raises ValueError while tokenizing a command segment — the cmd string has unbalanced quotes or an unterminated escape. The validator must tokenize the command to find its first real token; malformed quoting makes that impossible.

Source

Thrown at routes/cookbook_helpers.py:723

    def repl(match: re.Match[str]) -> str:
        value = match.group("value")
        mapped = _LLAMA_CPP_PYTHON_GGML_TYPES.get(value.lower())
        if not mapped:
            return match.group(0)
        quote = match.group("quote")
        return f"{match.group('flag')}{match.group('sep')}{quote}{mapped}{quote}"

    return _LLAMA_CPP_PYTHON_TYPE_FLAG_RE.sub(repl, cmd)


def _check_serve_binary(seg: str) -> None:
    """Validate that a single command segment starts with an allowlisted binary
    (after skipping leading env-var assignments like `CUDA_VISIBLE_DEVICES=0`)."""
    try:
        tokens = shlex.split(seg) if seg.strip() else []
    except ValueError:
        raise HTTPException(400, "Invalid cmd — could not parse")
    if not tokens:
        return
    env_re = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
    first = next((t for t in tokens if not env_re.match(t)), "")
    base = os.path.basename(first)
    if base not in _SERVE_CMD_ALLOWLIST:
        raise HTTPException(
            400,
            f"cmd binary '{base or '(empty)'}' is not allowed. Must start with one of: "
            f"{', '.join(sorted(_SERVE_CMD_ALLOWLIST))}",
        )


def _is_safe_serve_subshell(subshell: str) -> bool:
    return bool(
        _SAFE_PRINTF_SUBSHELL_RE.fullmatch(subshell)
        or _SAFE_FIND_MMPROJ_SUBSHELL_RE.fullmatch(subshell)
    )

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Balance all quotes in the cmd string — every opening ' or \" needs a close
  2. Remove trailing lone backslashes; use backslash-newline continuations only at end of line
  3. Validate with python -c "import shlex; shlex.split(cmd)" before submitting
  4. If the command came from the UI builder, regenerate it rather than hand-patching

Example fix

# before
cmd = "vllm serve 'mistralai/Mistral-7B-Instruct-v0.2 --port 8000"
# after
cmd = "vllm serve mistralai/Mistral-7B-Instruct-v0.2 --port 8000"
Defensive patterns

Strategy: validation

Validate before calling

import shlex

def cmd_parses(cmd: str) -> bool:
    try:
        shlex.split(cmd)
        return True
    except ValueError:
        return False

assert cmd_parses(cmd), "unbalanced quotes in cmd"

Prevention

When it happens

Trigger: cmd="vllm serve 'mistralai/Mistral-7B --port 8000" (missing closing quote), a cmd ending in a lone backslash, or a stray unmatched quote inside a token.

Common situations: Hand-editing a serve command and deleting a closing quote; multi-line vLLM commands pasted with a broken line-continuation; JSON escaping bugs that turn an escaped quote into a dangling one.

Related errors


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/d7083b41696d90ff. Report an issue: GitHub.