mastra-ai/mastra · error · Error

Storage not configured. Configure storage in Mastra…

Error message

Storage not configured. Configure storage in Mastra instance.

What it means

compareExperiments compares score data of two experiments, which requires a configured storage backend on the Mastra instance. If mastra.getStorage() returns undefined, no storage was configured and comparison cannot proceed.

Solutions

  1. Configure storage on the Mastra instance, e.g. new Mastra({ storage: new MastraStorage(...) })
  2. Check mastra.getStorage() before calling compareExperiments and surface a clear config error
  3. Verify the storage dependency/package is installed and imported correctly
  4. Ensure env vars controlling storage config are set in the runtime environment

Example fix

// before
const mastra = new Mastra({ agents: {...} }); // no storage
compareExperiments({ mastra, ... });
// after
const mastra = new Mastra({ agents: {...}, storage: new LibSQLStore({ url: process.env.DB_URL }) });
Defensive patterns

Strategy: validation

Validate before calling

const storage = mastra.getStorage();
if (!storage) throw new Error('Configure storage on the Mastra instance before comparing experiments');

Type guard

function hasStorage(mastra) { return typeof mastra.getStorage === 'function' && mastra.getStorage() != null; }

Try / catch

try {
  const report = await compareExperiments({ mastra, config });
} catch (e) {
  if (e instanceof Error && /Storage not configured/i.test(e.message)) {
    // reconfigure Mastra with a storage backend and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling compareExperiments(config) with a Mastra instance constructed without a storage option, or before storage is attached.

Common situations: Forgetting to pass storage in new Mastra({...}); running analytics in a test/dev environment with in-memory-only setup; storage config gated behind env vars that are unset in the deployment.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at packages/core/src/datasets/experiment/analytics/compare.ts:62

 *   thresholds: {
 *     'accuracy': { value: 0.05, direction: 'higher-is-better' },
 *     'latency': { value: 100, direction: 'lower-is-better' },
 *   },
 * });
 *
 * if (result.hasRegression) {
 *   console.log('Quality regression detected!');
 * }
 * ```
 */
export async function compareExperiments(mastra: Mastra, config: CompareExperimentsConfig): Promise<ComparisonResult> {
  const { experimentIdA, experimentIdB, thresholds = {} } = config;
  const warnings: string[] = [];

  // 1. Get storage
  const storage = mastra.getStorage();
  if (!storage) {
    throw new Error('Storage not configured. Configure storage in Mastra instance.');
  }

  const experimentsStore = await storage.getStore('experiments');
  const scoresStore = await storage.getStore('scores');

  if (!experimentsStore) {
    throw new Error('ExperimentsStorage not configured.');
  }
  if (!scoresStore) {
    throw new Error('ScoresStorage not configured.');
  }

  // 2. Load both experiments
  const [experimentA, experimentB] = await Promise.all([
    experimentsStore.getExperimentById({ id: experimentIdA }),
    experimentsStore.getExperimentById({ id: experimentIdB }),
  ]);

View on GitHub (pinned to 75dd419e61)