tobi/qmd · error · Error

Invalid expandContextSize: ${configValue}. Must be a positiv

Error message

Invalid expandContextSize: ${configValue}. Must be a positive integer.

What it means

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.

Source

Thrown at src/llm.ts:777

    setTimeout(() => resolve("timeout"), timeoutMs).unref();
  });

  try {
    const result = await Promise.race([dispose(), timeoutPromise]);
    if (result === "timeout") {
      process.stderr.write(`QMD Warning: timed out disposing ${resourceName}; continuing shutdown.\n`);
    }
  } catch (error) {
    process.stderr.write(
      `QMD Warning: failed to dispose ${resourceName} (${error instanceof Error ? error.message : String(error)}); continuing shutdown.\n`
    );
  }
}

function resolveExpandContextSize(configValue?: number): number {
  if (configValue !== undefined) {
    if (!Number.isInteger(configValue) || configValue <= 0) {
      throw new Error(`Invalid expandContextSize: ${configValue}. Must be a positive integer.`);
    }
    return configValue;
  }

  const envValue = process.env.QMD_EXPAND_CONTEXT_SIZE?.trim();
  if (!envValue) return DEFAULT_EXPAND_CONTEXT_SIZE;

  const parsed = Number.parseInt(envValue, 10);
  if (!Number.isInteger(parsed) || parsed <= 0) {
    process.stderr.write(
      `QMD Warning: invalid QMD_EXPAND_CONTEXT_SIZE="${envValue}", using default ${DEFAULT_EXPAND_CONTEXT_SIZE}.\n`
    );
    return DEFAULT_EXPAND_CONTEXT_SIZE;
  }
  return parsed;
}

const failedGpuInitModes = new Set<LlamaGpuMode>();

View on GitHub (pinned to dbfd0b4736)

Solutions

  1. Set expandContextSize to a positive integer such as 2048 in the config
  2. If using the env var, export a plain integer: QMD_EXPAND_CONTEXT_SIZE=2048
  3. Remove the setting entirely to use the built-in default

Example fix

# before
expandContextSize: 512.5
# after
expandContextSize: 2048
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(process.env.QMD_EXPAND_CONTEXT_SIZE ?? config.expandContextSize);
const valid = Number.isInteger(n) && n > 0;

Type guard

const isValidExpandContextSize = (v: unknown): v is number =>
  typeof v === 'number' && Number.isInteger(v) && v > 0;

Prevention

When it happens

Trigger: 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'.

Common situations: 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.

Related errors


AI-assisted analysis of tobi/qmd@dbfd0b4736 (2026-08-28). Data as JSON: /api/errors/90b18eab66bc8722. Report an issue: GitHub.