nanocoai/nanoclaw · error · StdinJsonInputError

--stdin-json input is not valid JSON

Error message

--stdin-json input is not valid JSON

What it means

parseMemoryMb throws when the CONTAINER_MEMORY_LIMIT env var does not match Docker's size-string grammar (number + optional b/k/m/g unit). It fails closed because returning undefined would silently remove the operator's memory cap — the one wrong direction for a resource limit to fail in.

Source

Thrown at container/agent-runner/src/cli/stdin-json.ts:72

      throw new StdinJsonInputError(`--stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes`);
    }
    chunks.push(buffer);
  }

  return Buffer.concat(chunks, byteLength).toString('utf8');
}

/** Parse the input, requiring exactly one JSON object — not an array, scalar, or null. */
function parseJsonObject(source: string): Record<string, unknown> {
  if (source.trim().length === 0) {
    throw new StdinJsonInputError('--stdin-json input is empty');
  }

  let parsed: unknown;
  try {
    parsed = JSON.parse(source);
  } catch (err) {
    throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err });
  }

  if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
    throw new StdinJsonInputError('--stdin-json input must be one JSON object');
  }

  return parsed as Record<string, unknown>;
}

/** Match the key normalization applied by command parsers in crud.ts. */
function canonicalArgKey(key: string): string {
  return key.replace(/-/g, '_');
}

/**
 * Reject any stdin key that could collide with another arg after the merge.
 *
 * Command parsers (crud.ts) normalize `-` to `_` in arg keys, so `group-id`

View on GitHub (pinned to 294ef2aee8)

Solutions

  1. Set CONTAINER_MEMORY_LIMIT to a plain docker size string like 8g, 512m, or 1073741824
  2. Set it to 0 to explicitly disable the cap
  3. Remove stray units/spaces: use '8g' not '8 gb' or '8GiB'

Example fix

# before
CONTAINER_MEMORY_LIMIT=8 GiB

# after
CONTAINER_MEMORY_LIMIT=8g
Defensive patterns

Strategy: validation

Validate before calling

if (process.env.CONTAINER_MEMORY_LIMIT && !/^\d+(?:\.\d+)?\s*[bkmg]?b?$/i.test(process.env.CONTAINER_MEMORY_LIMIT.trim())) {
  throw new Error('CONTAINER_MEMORY_LIMIT must be a docker size string like 8g or 512m');
}

Type guard

function isDockerSizeString(v: string): boolean {
  return /^\d+(?:\.\d+)?\s*[bkmg]?b?$/i.test(v.trim()) && Number.isFinite(Number(v));
}

Prevention

When it happens

Trigger: composeSessionSpec() reads CONTAINER_MEMORY_LIMIT and the value fails the regex /^(\d+(?:\.\d+)?)\s*([bkmg]?)b?$/i — e.g. '8 gb', 'limit=8g', '-512m', 'unlimited', or an empty-ish string.

Common situations: Typos in .env ('8GB' with a space, '8 g'), copy-paste from docs with units like '8GiB' or '512MB ' , or leftover placeholder values.

Related errors


AI-assisted analysis of nanocoai/nanoclaw@294ef2aee8 (2026-08-28). Data as JSON: /api/errors/cebb21b90a6d64a9. Report an issue: GitHub.