AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(worker): AP_SKIP_PREWARM_CODES excludes code steps from the prewarm scope (#15836)
Chaker Atallahbd1f3532b1b5
diff --git a/docs/install/reference/environment-variables.mdx b/docs/install/reference/environment-variables.mdxindex 13151ae6e73..5351d4535d3 100644--- a/docs/install/reference/environment-variables.mdx+++ b/docs/install/reference/environment-variables.mdx@@ -217,6 +217,7 @@ run timeouts, and the network egress posture for user code. Read| `AP_CONTAINER_TYPE` | Which services run in the container: `APP` (API only), `WORKER` (worker only), or `WORKER_AND_APP` (both). | `WORKER_AND_APP` || `AP_WORKER_CONCURRENCY` | Concurrent jobs a worker processes at once. Each job uses one sandbox instance. | `5` || `AP_PREWARM_CACHE_ON_STARTUP` | Pre-fill the worker's local piece and code cache on startup by resolving every enabled flow on the platform, instead of filling it lazily on each flow's first run. Enabling it removes the one-time cold-start latency of the first run after a worker (re)starts, but the warm-up itself costs memory and CPU proportional to the number of enabled flows — on instances with many flows it can pin the worker at its CPU limit for the duration of the warm-up and spike memory enough to OOM-kill small workers, especially when all workers restart at once during an upgrade. Keep it disabled unless your instance has a modest number of enabled flows, your workers have memory headroom, and first-run latency after deploys matters to you. | `false` |+| `AP_SKIP_PREWARM_CODES` | Set on the app: exclude code steps from the platform-wide prewarm scope, so warming workers install pieces only. Use it when the instance has so many code steps that building them all at startup takes too long or exhausts worker memory or disk; code steps then compile lazily on each flow's first run. | `false` || `AP_SANDBOX_MEMORY_LIMIT` | Maximum memory (KB) a single sandboxed engine process can use. Each process runs at most one execution at a time. | `1048576` || `AP_SANDBOX_PROPAGATED_ENV_VARS` | Comma-separated environment variables propagated into sandboxed code. For pieces, keep everything in the authentication object so it works across instances. | `None` || `AP_FLOW_TIMEOUT_SECONDS` | Maximum runtime for a single flow run, in seconds. Also bounds a single action run — an agent's piece tool, a chat action, or MCP `ap_run_action` — so raising it lets those hold a worker slot for the same length of time. | `600` |diff --git a/packages/server/api/src/app/flows/pre-warm-workers.ts b/packages/server/api/src/app/flows/pre-warm-workers.tsindex 564085365fa..3eb3e340548 100644--- a/packages/server/api/src/app/flows/pre-warm-workers.ts+++ b/packages/server/api/src/app/flows/pre-warm-workers.ts@@ -8,6 +8,7 @@ import { workerGroupService } from '../ee/platform/platform-plan/worker-group.seimport { fileService } from '../file/file.service'import Paginator from '../helper/pagination/paginator'import { system } from '../helper/system/system'+import { AppSystemProp } from '../helper/system/system-props'import { pieceMetadataService } from '../pieces/metadata/piece-metadata-service'import { platformService } from '../platform/platform.service'import { projectService } from '../project/project-service'@@ -53,7 +54,7 @@ export const preWarmWorkersService = (log: FastifyBaseLogger) => ({async function resolveCachedScope(input: PrewarmDataRequest, log: FastifyBaseLogger): Promise<PrewarmScope | null> {const scopeId = input.workerGroupId ?? SHARED_CACHE_KEY- const cacheKey = `prewarm:scope:v3:${scopeId}`+ const cacheKey = `prewarm:scope:v3:${scopeId}:codes-${prewarmCodesSkipped() ? 'off' : 'on'}`const cached = await distributedStore.get<PrewarmScope>(cacheKey)if (!isNil(cached)) {return cached@@ -134,12 +135,16 @@ async function computeScope(input: PrewarmDataRequest, log: FastifyBaseLogger):// are computed here in one pass — the worker warms from the distinct set instead of resolving each// flow over RPC, which made prewarm scale with flow count instead of distinct piece count.const versions = activeFlows.data.map((flow) => flow.version)- const codes = versions.flatMap(extractCodeSteps)+ const codes = prewarmCodesSkipped() ? [] : versions.flatMap(extractCodeSteps)const pieces = await resolvePiecePackages({ versions, platformId, log })const tokenProjectId = projectIds?.[0] ?? (await projectService(log).getProjectIdsByPlatform(platformId))[0]return { pieces, codes, platformId, tokenProjectId }}+function prewarmCodesSkipped(): boolean {+ return system.getBoolean(AppSystemProp.SKIP_PREWARM_CODES) ?? false+}+function extractCodeSteps(flowVersion: FlowVersion): PrewarmCodeStep[] {return flowStructureUtil.getAllSteps(flowVersion.trigger).filter((step) => step.type === FlowActionType.CODE)diff --git a/packages/server/api/src/app/helper/system-validator.ts b/packages/server/api/src/app/helper/system-validator.tsindex 6ec9e31a8c7..aa086c766f5 100644--- a/packages/server/api/src/app/helper/system-validator.ts+++ b/packages/server/api/src/app/helper/system-validator.ts@@ -93,6 +93,7 @@ const systemPropValidators: {// AppSystemProp[AppSystemProp.ALLOW_OPEN_SIGN_UP]: booleanValidator,[AppSystemProp.EXECUTION_MODE]: enumValidator(Object.values(ExecutionMode)),+ [AppSystemProp.SKIP_PREWARM_CODES]: booleanValidator,[AppSystemProp.SKIP_PROJECT_LIMITS_CHECK]: booleanValidator,[AppSystemProp.LOG_LEVEL]: enumValidator(['error', 'warn', 'info', 'debug', 'trace']),[AppSystemProp.LOG_PRETTY]: booleanValidator,diff --git a/packages/server/api/src/app/helper/system/system-props.ts b/packages/server/api/src/app/helper/system/system-props.tsindex 38a8ec6eb90..abbcb7fd631 100644--- a/packages/server/api/src/app/helper/system/system-props.ts+++ b/packages/server/api/src/app/helper/system/system-props.ts@@ -114,6 +114,7 @@ export enum AppSystemProp {SCIM_DEFAULT_PROJECT_ROLE = 'SCIM_DEFAULT_PROJECT_ROLE',SENTRY_DSN = 'SENTRY_DSN',FRONTEND_SENTRY_DSN = 'FRONTEND_SENTRY_DSN',+ SKIP_PREWARM_CODES = 'SKIP_PREWARM_CODES',SKIP_PROJECT_LIMITS_CHECK = 'SKIP_PROJECT_LIMITS_CHECK',SMTP_HOST = 'SMTP_HOST',SMTP_PASSWORD = 'SMTP_PASSWORD',