mastra-ai/mastra · error

One or more process memory diagnostic artifact writes failed

Error message

One or more process memory diagnostic artifact writes failed.

What it means

Thrown during stop() when any artifact write (process-samples.jsonl, gc-events.jsonl, or an allocation .heapprofile file) failed at some point during the run, flagged via artifactWriteFailed. stop() surfaces this so the user knows the on-disk diagnostic artifacts are incomplete or truncated.

Source

Thrown at mastracode/sdk/src/process-memory-diagnostics.ts:443

    this.clearTimersAndObserver();

    if (startingPromise) {
      this.stoppingPromise = startingPromise.then(() => this.getStatus());
      return this.stoppingPromise;
    }

    this.stoppingPromise = (async () => {
      let stopError: string | null = null;
      try {
        if (this.outputDirectory) await this.takeSample();
        await this.enqueueCapture(async () => {
          if (this.inspector && this.samplingActive) await this.captureEpoch('stop', true);
        });
        await this.writeQueue;
        if (this.gcEventBufferOverflowed) {
          throw new Error(`GC event buffer exceeded ${MAX_PENDING_GC_EVENTS} records before the next process sample.`);
        }
        if (this.artifactWriteFailed) throw new Error('One or more process memory diagnostic artifact writes failed.');
        this.latestError = null;
      } catch (error) {
        stopError = `Unable to stop process memory diagnostics cleanly: ${errorMessage(error)}`;
        this.latestError = stopError;
      } finally {
        this.disconnectInspector();
        this.state = stopError ? 'error' : 'inactive';
      }
      return this.getStatus();
    })();

    return this.stoppingPromise;
  }

  private async createArtifacts(): Promise<void> {
    await mkdir(this.config.parentDirectory, { recursive: true, mode: 0o700 });
    await chmod(this.config.parentDirectory, 0o700);
    const runName = `run-${safeTimestamp(this.startedAt!)}-${process.pid}-${this.randomId()

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Check free disk space and write permissions on the profile parent directory (created with mode 0700, files 0600)
  2. Set MASTRACODE_PROFILE_DIR to a writable location with sufficient space, then re-run the profiling session
  3. Inspect earlier logs — recordError messages and 'Unable to persist allocation capture' identify which artifact failed

Example fix

// before
MASTRACODE_PROFILE_DIR=/proc/readonly
// after
MASTRACODE_PROFILE_DIR=/var/tmp/mastracode-profiles
Defensive patterns

Strategy: try-catch

Validate before calling

import { access, constants } from 'node:fs/promises';
await access(process.env.MASTRACODE_PROFILE_DIR ?? '/tmp', constants.W_OK); // verify writable before profiling

Try / catch

try {
  await diagnostics.stop();
} catch (error) {
  if (error.message.includes('artifact writes failed')) {
    console.error(`Profile artifacts incomplete: ${diagnostics.getStatus().error}. Check disk space/permissions on the profile directory.`);
  } else throw error;
}

Prevention

When it happens

Trigger: An appendFile or writeFile in enqueueWriteBatch/captureEpoch threw (disk full, permissions, output directory removed mid-run) and stop() later runs while artifactWriteFailed is true.

Common situations: Disk quota exceeded in the profile directory, MASTRACODE_PROFILE_DIR pointing to a read-only or auto-cleaned path, tmpfs full, or the run directory deleted by an external cleanup process.

Related errors


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