{"record":{"id":"1604f05543dbc88a","repo":"apify/crawlee","slug":"availablememoryratio-is-not-set-in-configuration","errorCode":null,"errorMessage":"availableMemoryRatio is not set in configuration.","messagePattern":"availableMemoryRatio is not set in configuration\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/autoscaling/memory_load_signal.ts","lineNumber":88,"sourceCode":"    async start(context: LoadSignalStartContext): Promise<void> {\n        this.#store.useSampleWindow(context.maxSampleWindowMillis);\n        // A new session starts from a clean slate, so it is not judged on measurements from before the downtime.\n        this.#store.clear();\n\n        // Resolved here rather than in the constructor: an instance built ahead of time (to be wrapped, or shared\n        // between systems) must not capture whichever services happened to be registered at that moment.\n        this.#config = serviceLocator.getConfiguration();\n        this.#events = serviceLocator.getEventManager();\n        this.#log = serviceLocator.getLogger().child({ prefix: 'MemoryLoadSignal' });\n\n        const memoryMbytes = this.#config.memoryMbytes ?? 0;\n\n        if (memoryMbytes > 0) {\n            this.#maxMemoryBytes = memoryMbytes * 1024 * 1024;\n        } else {\n            this.#maxMemoryRatio = this.#config.availableMemoryRatio;\n            if (!this.#maxMemoryRatio) {\n                throw new Error('availableMemoryRatio is not set in configuration.');\n            } else {\n                this.#log.debug(\n                    `Setting max memory of this run to ${this.#maxMemoryRatio * 100} % of available memory. ` +\n                        'Use the CRAWLEE_MEMORY_MBYTES or CRAWLEE_AVAILABLE_MEMORY_RATIO environment variable to override it.',\n                );\n            }\n            // Fallback memory measurement in case memTotalBytes is missing from SystemInfo.\n            this.#maxMemoryBytes = await this.getTotalMemoryBytes();\n        }\n\n        this.#events.on(EventType.SYSTEM_INFO, this.handle);\n    }\n\n    async stop(): Promise<void> {\n        this.#events?.off(EventType.SYSTEM_INFO, this.handle);\n        this.#events = undefined;\n    }\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/autoscaling/memory_load_signal.ts#L70-L106","documentation":"When starting the memory load signal and no absolute `memoryMbytes` limit is given, Crawlee falls back to `availableMemoryRatio` from configuration. If neither is set (ratio is 0/undefined) it cannot compute a memory ceiling and throws during `start()`.","triggerScenarios":"Constructing MemoryLoadSignal / starting autoscaling with no `memoryMbytes` and a Configuration whose `availableMemoryRatio` is unset (and env vars CRAWLEE_MEMORY_MBYTES / CRAWLEE_AVAILABLE_MEMORY_RATIO unset).","commonSituations":"Programmatic Configuration objects that drop defaults; tests constructing Configuration from scratch; environments where config was built without the default preset.","solutions":["Set `availableMemoryRatio` in the Configuration (e.g. 0.5) passed to the autoscaling setup.","Or set an absolute limit via `memoryMbytes` / the CRAWLEE_MEMORY_MBYTES env var.","Or set CRAWLEE_AVAILABLE_MEMORY_RATIO in the environment."],"exampleFix":"// before\nconst config = new Configuration();\nconst signal = new MemoryLoadSignal({ config });\nawait signal.start();\n// after\nconst config = new Configuration({ availableMemoryRatio: 0.5 });\nconst signal = new MemoryLoadSignal({ config });\nawait signal.start();","handlingStrategy":"validation","validationCode":"const ratio = config.get('availableMemoryRatio');\nconst mbytes = Number(process.env.CRAWLEE_MEMORY_MBYTES ?? 0);\nif (!ratio && mbytes <= 0) throw new Error('Set CRAWLEE_MEMORY_MBYTES or CRAWLEE_AVAILABLE_MEMORY_RATIO');","typeGuard":"function hasMemoryLimit(cfg: Configuration): boolean { return Boolean(cfg.get('availableMemoryRatio')) || Number(process.env.CRAWLEE_MEMORY_MBYTES) > 0; }","tryCatchPattern":"try { await signal.start(); } catch (err) { if (err.message.includes('availableMemoryRatio')) { /* reconfigure with a ratio and retry */ } else { throw err; } }","preventionTips":["Set CRAWLEE_MEMORY_MBYTES or CRAWLEE_AVAILABLE_MEMORY_RATIO in the environment","When building Configuration programmatically, include availableMemoryRatio explicitly","Smoke-test autoscaling startup in CI to catch config drift"],"tags":["autoscaling","memory","configuration","core"],"backgroundTag":"missing-config-option","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}