{"record":{"id":"90b18eab66bc8722","repo":"tobi/qmd","slug":"invalid-expandcontextsize-configvalue-must-be","errorCode":null,"errorMessage":"Invalid expandContextSize: ${configValue}. Must be a positive integer.","messagePattern":"Invalid expandContextSize: (.+?)\\. Must be a positive integer\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/llm.ts","lineNumber":777,"sourceCode":"    setTimeout(() => resolve(\"timeout\"), timeoutMs).unref();\n  });\n\n  try {\n    const result = await Promise.race([dispose(), timeoutPromise]);\n    if (result === \"timeout\") {\n      process.stderr.write(`QMD Warning: timed out disposing ${resourceName}; continuing shutdown.\\n`);\n    }\n  } catch (error) {\n    process.stderr.write(\n      `QMD Warning: failed to dispose ${resourceName} (${error instanceof Error ? error.message : String(error)}); continuing shutdown.\\n`\n    );\n  }\n}\n\nfunction resolveExpandContextSize(configValue?: number): number {\n  if (configValue !== undefined) {\n    if (!Number.isInteger(configValue) || configValue <= 0) {\n      throw new Error(`Invalid expandContextSize: ${configValue}. Must be a positive integer.`);\n    }\n    return configValue;\n  }\n\n  const envValue = process.env.QMD_EXPAND_CONTEXT_SIZE?.trim();\n  if (!envValue) return DEFAULT_EXPAND_CONTEXT_SIZE;\n\n  const parsed = Number.parseInt(envValue, 10);\n  if (!Number.isInteger(parsed) || parsed <= 0) {\n    process.stderr.write(\n      `QMD Warning: invalid QMD_EXPAND_CONTEXT_SIZE=\"${envValue}\", using default ${DEFAULT_EXPAND_CONTEXT_SIZE}.\\n`\n    );\n    return DEFAULT_EXPAND_CONTEXT_SIZE;\n  }\n  return parsed;\n}\n\nconst failedGpuInitModes = new Set<LlamaGpuMode>();","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/tobi/qmd/blob/dbfd0b4736aeaf761d1a16ca8e424f071df8feb9/src/llm.ts#L759-L795","documentation":"The expandContextSize setting (used by query expansion to bound context size) must be a positive integer, and the configured value failed that check. It reads from config first, then the QMD_EXPAND_CONTEXT_SIZE env var; the error names the offending value so it's easy to spot.","triggerScenarios":"Setting expandContextSize: 0, a negative number, or a non-integer like 512.5 in the YAML config; exporting QMD_EXPAND_CONTEXT_SIZE='1e3' or '10px'.","commonSituations":"Copying a config snippet with wrong units; treating the setting as a boolean/enabled flag; env var set to an empty-ish or formatted number string.","solutions":["Set expandContextSize to a positive integer such as 2048 in the config","If using the env var, export a plain integer: QMD_EXPAND_CONTEXT_SIZE=2048","Remove the setting entirely to use the built-in default"],"exampleFix":"# before\nexpandContextSize: 512.5\n# after\nexpandContextSize: 2048\n","handlingStrategy":"validation","validationCode":"const n = Number(process.env.QMD_EXPAND_CONTEXT_SIZE ?? config.expandContextSize);\nconst valid = Number.isInteger(n) && n > 0;","typeGuard":"const isValidExpandContextSize = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":null,"preventionTips":["Document expandContextSize as a positive integer in project READMEs","Validate numeric config values at app startup, not at first use","Avoid string env values with units or formatting; use plain integers"],"tags":["config","validation","query-expansion"],"backgroundTag":"config-value-validation","analyzedSha":"dbfd0b4736aeaf761d1a16ca8e424f071df8feb9","analyzedAt":"2026-08-28T18:07:46.628Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}