mastra-ai/mastra · error · Error

Operation terminated by SIGTERM

Error message

Operation terminated by SIGTERM

What it means

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.

Source

Thrown at packages/cli/src/commands/create/create.ts:424

      await cleanupOwnedStagingDirectory(staging.rootPath);
    } catch (cleanupError) {
      console.error(
        `Warning: Failed to clean up staging directory: ${cleanupError instanceof Error ? cleanupError.message : 'Unknown error'}`,
      );
    }
  }

  const platformSetup = await platformSetupPromise;
  process.removeListener('SIGINT', handleSigint);
  process.removeListener('SIGTERM', handleSigterm);

  if (interruptionSignal === 'SIGINT') {
    if (observabilityEnabled) {
      analytics?.trackEvent('cli_observability_outcome', { command: 'create', outcome: 'cancelled' });
    }
    cancelCreate();
  }
  if (interruptionSignal === 'SIGTERM') throw new Error('Operation terminated by SIGTERM');
  if (materializationError) throw materializationError;
  if (platformSetup?.status === 'cancelled') {
    analytics?.trackEvent('cli_observability_outcome', { command: 'create', outcome: 'skipped' });
    p.log.info('Skipping Mastra platform setup.');
  } else if (observabilityEnabled) {
    p.log.success(
      options.install
        ? 'Default template cloned and dependencies installed.'
        : 'Default template cloned. Dependency installation was skipped.',
    );
  }

  const postSetup = await runPostCreateSetup({
    projectPath: targetPath,
    installSkills: options.skills,
    initializeGit: options.git,
    invocationIsGitWorktree,
  });

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Re-run `mastra create` after the terminating condition is gone
  2. Raise CI/step timeouts so long installs aren't killed mid-scaffold
  3. Run the command in a foreground terminal away from aggressive supervisors
  4. If under Docker/K8s, increase grace period (docker stop -t, terminationGracePeriodSeconds) or run create outside the ephemeral environment
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await create(opts);
} catch (error) {
  if (error instanceof Error && error.message === 'Operation terminated by SIGTERM') {
    console.error('Scaffold aborted by SIGTERM; target project may not exist — re-run create');
    process.exitCode = 143; // conventional SIGTERM exit code
    return;
  }
  throw error;
}

Prevention

When it happens

Trigger: Something sends SIGTERM to `mastra create` mid-run: `kill <pid>`, container/CI timeout terminations, `pkill mastra`, orchestrators (Docker stop, Kubernetes) shutting down the job.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/425f2a5e90a1b0c1. Report an issue: GitHub.