{"record":{"id":"58884bb46bd68db7","repo":"Mintplex-Labs/anything-llm","slug":"log-prefix-anythingllm-max-retries-envdefine","errorCode":null,"errorMessage":"${LOG_PREFIX} ANYTHINGLLM_MAX_RETRIES=\"${envDefinedMaxRetries}\" is not a valid non-negative integer — using default ${DEFAULT_MAX_RETRIES}.","messagePattern":"(.+?) ANYTHINGLLM_MAX_RETRIES=\"(.+?)\" is not a valid non-negative integer — using default (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/utils/boot/patchSdkTimeouts.js","lineNumber":36,"sourceCode":"  const envDefinedMaxRetries = process.env.ANYTHINGLLM_MAX_RETRIES;\n  let timeoutMs = DEFAULT_TIMEOUT_MS;\n  let maxRetries = DEFAULT_MAX_RETRIES;\n\n  if (envDefinedTimeout) {\n    const parsed = parseInt(envDefinedTimeout, 10);\n    if (!Number.isFinite(parsed) || parsed <= 0) {\n      console.warn(\n        `${LOG_PREFIX} ANYTHINGLLM_FETCH_TIMEOUT=\"${envDefinedTimeout}\" is not a valid positive integer — using default ${DEFAULT_TIMEOUT_MS}ms.`\n      );\n    } else {\n      timeoutMs = parsed;\n    }\n  }\n\n  if (envDefinedMaxRetries) {\n    const parsed = parseInt(envDefinedMaxRetries, 10);\n    if (!Number.isFinite(parsed) || parsed < 0) {\n      console.warn(\n        `${LOG_PREFIX} ANYTHINGLLM_MAX_RETRIES=\"${envDefinedMaxRetries}\" is not a valid non-negative integer — using default ${DEFAULT_MAX_RETRIES}.`\n      );\n    } else {\n      maxRetries = parsed;\n    }\n  }\n\n  const humanSecs = `${(timeoutMs / 1000).toFixed(0)}s`;\n  try {\n    const { Agent, setGlobalDispatcher } = require(\"undici\");\n    setGlobalDispatcher(\n      new Agent({ headersTimeout: timeoutMs, bodyTimeout: timeoutMs })\n    );\n    console.log(\n      `${LOG_PREFIX} undici global dispatcher — headersTimeout & bodyTimeout ${humanSecs}`\n    );\n  } catch {\n    console.warn(","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/boot/patchSdkTimeouts.js#L18-L54","documentation":"AnythingLLM prints this console.warn at boot when patchSdkTimeouts() (server/utils/boot/patchSdkTimeouts.js) cannot parse ANYTHINGLLM_MAX_RETRIES. The value is read from the environment, run through parseInt, and rejected when it is NaN or negative; the boot patch then keeps the built-in default of 0 retries for the undici global dispatcher (Agent with headersTimeout/bodyTimeout) that all LLM provider HTTP calls go through. It is purely advisory — the server keeps starting, just without your custom retry count. Note the check is lenient in other ways: parseInt('3x') and parseInt('3.9') both pass as 3, and an empty/unset value skips the branch entirely.","triggerScenarios":"Starting the server with ANYTHINGLLM_MAX_RETRIES=\"three\", \"-1\", \"x3\", \"3 retries\", or a value carrying quotes/whitespace/BOM from a .env file or docker-compose.yml environment block. Only non-numeric or negative parses reach the warning; the fetch-timeout sibling variable ANYTHINGLLM_FETCH_TIMEOUT has its own separate check.","commonSituations":"Typos in .env (ANYTHINGLLM_MAX_RETRIES=3x), copy-pasting quoted values (ANYTHINGLLM_MAX_RETRIES=\"3\") from documentation into compose files, Windows CRLF line endings in .env, or setting -1 intending \"unlimited retries\". The mistake is silent beyond this one startup line, so retries quietly stay at 0 and flaky provider calls fail where users expected retries.","solutions":["Set ANYTHINGLLM_MAX_RETRIES to a plain non-negative integer, e.g. ANYTHINGLLM_MAX_RETRIES=3 (no quotes, no units) in .env or the container environment, then restart the server — the patch runs once at boot before provider modules load.","If you did not intend to configure retries, unset/delete the variable to explicitly use the default of 0.","Inspect the raw .env entry for stray quotes, spaces, comments on the same line, or a BOM; retype the line if in doubt.","If you meant to raise the connection deadline instead of retries, use ANYTHINGLLM_FETCH_TIMEOUT (milliseconds, positive integer) — mixing the two up is a common cause of this warning."],"exampleFix":"# before (.env)\nANYTHINGLLM_MAX_RETRIES=\"3 times\"\nANYTHINGLLM_FETCH_TIMEOUT=2 min\n\n# after (.env)\nANYTHINGLLM_MAX_RETRIES=3\nANYTHINGLLM_FETCH_TIMEOUT=120000","handlingStrategy":"validation","validationCode":"const raw = process.env.ANYTHINGLLM_MAX_RETRIES;\nif (raw !== undefined && raw !== \"\" && !/^\\d+$/.test(raw.trim())) {\n  throw new Error(\n    `ANYTHINGLLM_MAX_RETRIES must be a non-negative integer, got \"${raw}\" — fix it before boot.`\n  );\n}","typeGuard":"const isNonNegativeIntString = (v) => {\n  const t = String(v ?? \"\").trim();\n  return /^\\d+$/.test(t) && Number.isSafeInteger(Number(t));\n};","tryCatchPattern":null,"preventionTips":["Keep numeric env values unquoted and unit-free in .env and compose files; never inline comments on the same line.","Add a strict env-lint step (regex ^\\d+$) to CI or a preboot script — the library's parseInt accepts junk like '3x' that your linter should reject.","Document sibling variables side by side (ANYTHINGLLM_FETCH_TIMEOUT in ms vs ANYTHINGLLM_MAX_RETRIES as a count) so they are not confused."],"tags":["env-var","configuration","undici","retries","boot"],"backgroundTag":"invalid-env-var-value","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}