TencentCloud/TencentDB-Agent-Memory · error · Error

cos.generationLogRetentionDays must be a non-negative intege

Error message

cos.generationLogRetentionDays must be a non-negative integer

What it means

During loadGatewayConfig, the COS (object storage) section's generationLogRetentionDays is resolved from env COS_GENERATION_LOG_RETENTION_DAYS, yaml cos.generationLogRetentionDays, or defaults to 30. The gateway validates the final value must be an integer >= 0 and throws at startup otherwise. This is fail-fast config validation for generation-log retention.

Source

Thrown at MemoryCore/src/gateway/config.ts:612

  };

  // Worker config
  const workerConfig = obj(fileConfig, "worker");
  const worker: WorkerConfig = {
    pollMs: envInt("WORKER_POLL_MS") ?? num(workerConfig, "pollMs") ?? 200,
    concurrency: envInt("WORKER_CONCURRENCY") ?? num(workerConfig, "concurrency") ?? 60,
  };

  // COS extra config
  const cosConfig = obj(fileConfig, "cos");
  const cos: CosExtraConfig = {
    domain: env("COS_DOMAIN") ?? str(cosConfig, "domain"),
    generationLogRetentionDays: envInt("COS_GENERATION_LOG_RETENTION_DAYS")
      ?? num(cosConfig, "generationLogRetentionDays")
      ?? 30,
  };
  if (!Number.isInteger(cos.generationLogRetentionDays) || cos.generationLogRetentionDays < 0) {
    throw new Error("cos.generationLogRetentionDays must be a non-negative integer");
  }

  // Observability config (yaml: observability.{otel,clickhouse,kafka}, env 兜底)
  const observabilityConfig = obj(fileConfig, "observability");

  // OTel config
  const otelConfig = obj(observabilityConfig, "otel");
  const otel: OTelConfig = {
    enabled: otelConfig.enabled !== undefined
      ? Boolean(otelConfig.enabled)
      : env("TDAI_OTEL_ENABLED") === "true",
    endpoint: str(otelConfig, "endpoint") ?? env("OTEL_EXPORTER_OTLP_ENDPOINT") ?? "http://localhost:4317",
    protocol: (str(otelConfig, "protocol") ?? env("OTEL_EXPORTER_OTLP_PROTOCOL") ?? "grpc") as "grpc" | "http/protobuf",
    serviceName: str(otelConfig, "serviceName") ?? env("OTEL_SERVICE_NAME") ?? "core",
    serviceVersion: str(otelConfig, "serviceVersion") ?? "1.0.0",
    tenantId: str(otelConfig, "tenantId") ?? env("OTEL_TENANT_ID") ?? "",
    logExportInterval: num(otelConfig, "logExportInterval") ?? envInt("OTEL_LOG_EXPORT_INTERVAL") ?? 5,
  };

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Fix COS_GENERATION_LOG_RETENTION_DAYS to a non-negative integer string, e.g. 30, or unset it to fall back to yaml/default.
  2. Fix cos.generationLogRetentionDays in the gateway yaml to an integer >= 0.
  3. To disable retention clearing, set 0 (valid) rather than a negative number.
  4. Check which layer wins (env beats yaml): echo "$COS_GENERATION_LOG_RETENTION_DAYS" and remove the stale override.

Example fix

// before (env)
COS_GENERATION_LOG_RETENTION_DAYS=-1
// after
COS_GENERATION_LOG_RETENTION_DAYS=30
// or yaml: cos:
//   generationLogRetentionDays: 30
Defensive patterns

Strategy: validation

Validate before calling

const raw = process.env.COS_GENERATION_LOG_RETENTION_DAYS;
if (raw !== undefined && (!Number.isInteger(Number(raw)) || Number(raw) < 0)) {
  throw new Error(`COS_GENERATION_LOG_RETENTION_DAYS must be a non-negative integer, got: ${raw}`);
}

Type guard

function isValidRetentionDays(v: unknown): v is number {
  return typeof v === 'number' && Number.isInteger(v) && v >= 0;
}

Try / catch

try {
  const cfg = loadGatewayConfig();
} catch (err) {
  if (err.message.includes('generationLogRetentionDays')) {
    console.error('Fix COS_GENERATION_LOG_RETENTION_DAYS or cos.generationLogRetentionDays in yaml: must be an integer >= 0');
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Setting COS_GENERATION_LOG_RETENTION_DAYS to a non-integer (e.g. "7.5", "30d", "") or a negative number; putting generationLogRetentionDays: -1 or a decimal/string in the cos: block of the gateway yaml.

Common situations: Typo or unit suffix in env value ("30d", "3 weeks"); operator intended "disable retention" by setting -1 (must use 0, which retains nothing/forever per semantics); YAML type coercion producing a float; stale env var from an old deployment overriding a fixed yaml value.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/10c3c8b164dc582a. Report an issue: GitHub.