{"record":{"id":"2dfc8f07d7604fde","repo":"mudler/LocalAI","slug":"ds4-worker-invalid-value-for-s-s","errorCode":null,"errorMessage":"ds4-worker: invalid value for %s: %s\n","messagePattern":"ds4-worker: invalid value for (.+?): (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/cpp/ds4/worker_main.c","lineNumber":35,"sourceCode":"#include <signal.h>\n#include <limits.h>\n\n#include \"ds4.h\"\n#include \"ds4_distributed.h\"\n\nstatic const char *need_arg(int *i, int argc, char **argv, const char *flag) {\n    if (*i + 1 >= argc) {\n        fprintf(stderr, \"ds4-worker: missing value for %s\\n\", flag);\n        exit(2);\n    }\n    return argv[++(*i)];\n}\n\nstatic int parse_int_arg(const char *s, const char *flag) {\n    char *end = NULL;\n    long v = strtol(s, &end, 10);\n    if (!s[0] || *end || v <= 0 || v > INT_MAX) {\n        fprintf(stderr, \"ds4-worker: invalid value for %s: %s\\n\", flag, s);\n        exit(2);\n    }\n    return (int)v;\n}\n\nstatic ds4_backend default_backend(void) {\n#if defined(DS4_NO_GPU)\n    return DS4_BACKEND_CPU;\n#elif defined(__APPLE__)\n    return DS4_BACKEND_METAL;\n#else\n    return DS4_BACKEND_CUDA;\n#endif\n}\n\nint main(int argc, char **argv) {\n    signal(SIGPIPE, SIG_IGN);\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/cpp/ds4/worker_main.c#L17-L53","documentation":"CLI validation in the ds4 worker's parse_int_arg(): the value string for a numeric flag (-c/--ctx, -t/--threads, or a distributed numeric option) is rejected when it is empty, contains non-digit trailing characters, or parses to a value <= 0 or > INT_MAX. The worker exits with status 2 before touching the model.","triggerScenarios":"Passing 'ds4-worker -c 0', '-c -1', '-c 32k', '-t abc', or a value above 2147483647; strtol sets end and the check !s[0] || *end || v <= 0 || v > INT_MAX fires.","commonSituations":"Using KB/MB-style suffixes ('--ctx 8k') where a plain integer is required; environment variables expanding to empty strings; negative or zero values from miscomputed scripts; 64-bit counts overflowing INT_MAX.","solutions":["Supply a plain positive decimal integer within int range: '--ctx 32768', '--threads 8'.","Strip units in generating scripts: use $(( ... )) arithmetic or 'numfmt --from=iec' to precompute the raw number.","Echo the assembled command line in your launcher before exec so a bad substitution is visible."],"exampleFix":"# before\nds4-worker --role worker -m model.gguf --ctx 8k -t 0\n\n# after\nds4-worker --role worker -m model.gguf --ctx 8192 -t 8","handlingStrategy":"validation","validationCode":"# bash: pre-validate every numeric arg\nis_pos_int() { case \"$1\" in ''|*[!0-9]*) return 1;; esac; [ \"$1\" -gt 0 ] && [ \"$1\" -le 2147483647 ]; }\nfor v in \"$CTX\" \"$THREADS\"; do is_pos_int \"$v\" || { echo \"bad numeric value: $v\" >&2; exit 2; }; done","typeGuard":"bool valid_ds4_int(const char *s) {\n    char *end; long v = strtol(s, &end, 10);\n    return s[0] && !*end && v > 0 && v <= INT_MAX;\n}","tryCatchPattern":null,"preventionTips":["Never pass suffixed quantities ('8k', '1M') to ds4 numeric flags; precompute raw integers.","Fail fast in launchers on empty env vars instead of letting them reach argv.","Remember ctx must be > 0 and fit in int; extremely large values are rejected even if numerically valid."],"tags":["c","ds4","cli","validation","usage-error"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}