{"record":{"id":"cdd360f6bb0f1011","repo":"unslothai/unsloth","slug":"llama-server-does-not-accept-the-spaces-around-t","errorCode":null,"errorMessage":"llama-server does not accept the spaces around '{token[:64]}': write it as '{flag}'","messagePattern":"llama-server does not accept the spaces around '(.+?)': write it as '(.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/llama_server_args.py","lineNumber":300,"sourceCode":"            # model path: that is the one thing the -m / --model denial exists to\n            # prevent, and it would sidestep the native-path lease as well.\n            if pending_values <= 0:\n                raise ValueError(\n                    \"extra llama-server args cannot contain a bare value \"\n                    f\"('{token[:64]}'); every value must follow its flag\"\n                )\n            pending_values -= 1\n            if pending_two_value > 0:\n                pending_two_value -= 1\n        elif token != token.strip():\n            # _flag_name strips before it looks anything up, so a quoted \"--top-k \"\n            # passed the denylist and the arity walk as --top-k and then went to the\n            # child with the space still on it. llama.cpp looks the whole token up,\n            # so it answers \"error: invalid argument: --top-k\" (measured on b10342),\n            # naming a flag that looks correct in the log. Only flag-shaped tokens:\n            # a VALUE may legitimately end in whitespace, a chat template or a\n            # grammar being the obvious ones.\n            raise ValueError(\n                f\"llama-server does not accept the spaces around '{token[:64]}': \"\n                f\"write it as '{flag}'\"\n            )\n        elif \"=\" in token:\n            # llama.cpp looks the WHOLE token up in its option map, folding only the\n            # underscore spelling, so \"--top-k=20\" is not \"--top-k\" with a value: it\n            # is an argument it has never heard of. Measured on b10342 and b10360,\n            # where --top-k=20, --ctx-size=4096 and --flash-attn=on each exit with\n            # \"error: invalid argument\". Accepting the GNU spelling here meant the\n            # switch tore down the resident model and the child then refused to\n            # start, so it is refused while it is still a 400 with somewhere to go.\n            # Splitting it here would be a guess: for a switch the value is not one,\n            # and this module cannot know an ordinary flag's arity.\n            value = token.partition(\"=\")[2]\n            raise ValueError(\n                f\"llama-server does not read an attached value: write '{flag}' and \"\n                f\"'{value[:32]}' as two separate arguments, not '{token[:64]}'\"\n            )","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/llama_server_args.py#L282-L318","documentation":"ValueError from llama_server_args.py:300 — a flag token carries leading/trailing whitespace (token != token.strip()). _flag_name strips before lookup, so a quoted '--top-k ' passed the denylist and arity walk as --top-k but would reach the child with the space attached; llama.cpp looks up the WHOLE token and answers 'error: invalid argument: --top-k' (measured on b10342), naming a flag that looks correct in the log. Only flag-shaped tokens are checked — values (chat templates, grammars) may legitimately end in whitespace.","triggerScenarios":"Passing a quoted flag with an accidental trailing/leading space: '--top-k ' or ' --flash-attn', typically from template-built arg strings or copy-paste where the space before a closing quote survives.","commonSituations":"f-string / shell building like f\"--top-k {k} \" then splitting; copy-pasting from docs with stray spaces; JSON config values with trailing whitespace around flag names.","solutions":["Strip flag tokens before submitting: [t if not t.startswith('-') else t.strip() for t in args] — the error message itself tells you the correct spelling.","Fix the producer: don't pad flag strings when building argv; only values may carry whitespace.","Use shlex.split on a properly quoted command line so spaces inside quotes stay on values, not flags."],"exampleFix":"# before\nextra_args = [\"--top-k \", \"40\"]  # trailing space on the flag\n\n# after\nextra_args = [\"--top-k\", \"40\"]","handlingStrategy":"validation","validationCode":"extra_args = [t.strip() if t.startswith('-') and '=' not in t else t for t in extra_args]","typeGuard":"def flag_is_clean(token) -> bool:\n    return not token.startswith('-') or token == token.strip()","tryCatchPattern":"try:\n    validate_extra_args(args)\nexcept ValueError as e:\n    if \"spaces around\" in str(e):\n        args = [t if not t.startswith('-') else t.strip() for t in args]\n        validate_extra_args(args)\n    else:\n        raise","preventionTips":["Strip flag tokens (not value tokens) before submitting.","Do not pad flags when building command strings in f-strings or templates.","Prefer list-based argv construction over string concatenation + split."],"tags":["llama-server","validation","whitespace","argv","flag-parsing"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}