{"record":{"id":"302d85b78eb5899b","repo":"mastra-ai/mastra","slug":"one-or-more-process-memory-diagnostic-artifact-wri","errorCode":null,"errorMessage":"One or more process memory diagnostic artifact writes failed.","messagePattern":"One or more process memory diagnostic artifact writes failed\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/process-memory-diagnostics.ts","lineNumber":443,"sourceCode":"    this.clearTimersAndObserver();\n\n    if (startingPromise) {\n      this.stoppingPromise = startingPromise.then(() => this.getStatus());\n      return this.stoppingPromise;\n    }\n\n    this.stoppingPromise = (async () => {\n      let stopError: string | null = null;\n      try {\n        if (this.outputDirectory) await this.takeSample();\n        await this.enqueueCapture(async () => {\n          if (this.inspector && this.samplingActive) await this.captureEpoch('stop', true);\n        });\n        await this.writeQueue;\n        if (this.gcEventBufferOverflowed) {\n          throw new Error(`GC event buffer exceeded ${MAX_PENDING_GC_EVENTS} records before the next process sample.`);\n        }\n        if (this.artifactWriteFailed) throw new Error('One or more process memory diagnostic artifact writes failed.');\n        this.latestError = null;\n      } catch (error) {\n        stopError = `Unable to stop process memory diagnostics cleanly: ${errorMessage(error)}`;\n        this.latestError = stopError;\n      } finally {\n        this.disconnectInspector();\n        this.state = stopError ? 'error' : 'inactive';\n      }\n      return this.getStatus();\n    })();\n\n    return this.stoppingPromise;\n  }\n\n  private async createArtifacts(): Promise<void> {\n    await mkdir(this.config.parentDirectory, { recursive: true, mode: 0o700 });\n    await chmod(this.config.parentDirectory, 0o700);\n    const runName = `run-${safeTimestamp(this.startedAt!)}-${process.pid}-${this.randomId()","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/process-memory-diagnostics.ts#L425-L461","documentation":"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.","triggerScenarios":"An appendFile or writeFile in enqueueWriteBatch/captureEpoch threw (disk full, permissions, output directory removed mid-run) and stop() later runs while artifactWriteFailed is true.","commonSituations":"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.","solutions":["Check free disk space and write permissions on the profile parent directory (created with mode 0700, files 0600)","Set MASTRACODE_PROFILE_DIR to a writable location with sufficient space, then re-run the profiling session","Inspect earlier logs — recordError messages and 'Unable to persist allocation capture' identify which artifact failed"],"exampleFix":"// before\nMASTRACODE_PROFILE_DIR=/proc/readonly\n// after\nMASTRACODE_PROFILE_DIR=/var/tmp/mastracode-profiles","handlingStrategy":"try-catch","validationCode":"import { access, constants } from 'node:fs/promises';\nawait access(process.env.MASTRACODE_PROFILE_DIR ?? '/tmp', constants.W_OK); // verify writable before profiling","typeGuard":null,"tryCatchPattern":"try {\n  await diagnostics.stop();\n} catch (error) {\n  if (error.message.includes('artifact writes failed')) {\n    console.error(`Profile artifacts incomplete: ${diagnostics.getStatus().error}. Check disk space/permissions on the profile directory.`);\n  } else throw error;\n}","preventionTips":["Verify free disk space and write access on MASTRACODE_PROFILE_DIR before enabling profiling","Do not point the profile dir at ephemeral/read-only mounts (tmpfs, /proc, auto-cleaned paths)","Watch getStatus().error during runs — write failures are recorded incrementally","Watch for 'Unable to persist allocation capture' warnings, which also set artifactWriteFailed"],"tags":["filesystem","disk-full","permissions","diagnostics"],"backgroundTag":"artifact-write-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}