{"record":{"id":"425f2a5e90a1b0c1","repo":"mastra-ai/mastra","slug":"operation-terminated-by-sigterm","errorCode":null,"errorMessage":"Operation terminated by SIGTERM","messagePattern":"Operation terminated by SIGTERM","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/create/create.ts","lineNumber":424,"sourceCode":"      await cleanupOwnedStagingDirectory(staging.rootPath);\n    } catch (cleanupError) {\n      console.error(\n        `Warning: Failed to clean up staging directory: ${cleanupError instanceof Error ? cleanupError.message : 'Unknown error'}`,\n      );\n    }\n  }\n\n  const platformSetup = await platformSetupPromise;\n  process.removeListener('SIGINT', handleSigint);\n  process.removeListener('SIGTERM', handleSigterm);\n\n  if (interruptionSignal === 'SIGINT') {\n    if (observabilityEnabled) {\n      analytics?.trackEvent('cli_observability_outcome', { command: 'create', outcome: 'cancelled' });\n    }\n    cancelCreate();\n  }\n  if (interruptionSignal === 'SIGTERM') throw new Error('Operation terminated by SIGTERM');\n  if (materializationError) throw materializationError;\n  if (platformSetup?.status === 'cancelled') {\n    analytics?.trackEvent('cli_observability_outcome', { command: 'create', outcome: 'skipped' });\n    p.log.info('Skipping Mastra platform setup.');\n  } else if (observabilityEnabled) {\n    p.log.success(\n      options.install\n        ? 'Default template cloned and dependencies installed.'\n        : 'Default template cloned. Dependency installation was skipped.',\n    );\n  }\n\n  const postSetup = await runPostCreateSetup({\n    projectPath: targetPath,\n    installSkills: options.skills,\n    initializeGit: options.git,\n    invocationIsGitWorktree,\n  });","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/create/create.ts#L406-L442","documentation":"During `create`, the CLI registers SIGINT/SIGTERM handlers and records the interruption signal; after materialization settles it re-checks them (create.ts:424). If SIGTERM was received while scaffolding, the run is aborted and a plain Error 'Operation terminated by SIGTERM' is thrown so the process exits non-zero instead of producing a half-written project.","triggerScenarios":"Something sends SIGTERM to `mastra create` mid-run: `kill <pid>`, container/CI timeout terminations, `pkill mastra`, orchestrators (Docker stop, Kubernetes) shutting down the job.","commonSituations":"CI jobs killed at a step timeout; IDE task runners stopping a dev command; Docker containers stopped before the scaffold finished; running the command under a supervisor that restarts it.","solutions":["Re-run `mastra create` after the terminating condition is gone","Raise CI/step timeouts so long installs aren't killed mid-scaffold","Run the command in a foreground terminal away from aggressive supervisors","If under Docker/K8s, increase grace period (docker stop -t, terminationGracePeriodSeconds) or run create outside the ephemeral environment"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await create(opts);\n} catch (error) {\n  if (error instanceof Error && error.message === 'Operation terminated by SIGTERM') {\n    console.error('Scaffold aborted by SIGTERM; target project may not exist — re-run create');\n    process.exitCode = 143; // conventional SIGTERM exit code\n    return;\n  }\n  throw error;\n}","preventionTips":["Increase CI step timeouts so long installs aren't killed","Avoid wrapping mastra create in supervisors that escalate to SIGTERM","Use --timeout with a generous value to finish installs before external kills","Check for stray partial directories after a SIGTERM before re-running"],"tags":["cli","sigterm","process-termination","interruption"],"backgroundTag":"process-killed-sigterm","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}